Re: PHPUnit to test Fat Free PHP routing

132 views
Skip to first unread message
Message has been deleted

Rayne

unread,
Oct 8, 2016, 5:45:37 AM10/8/16
to Fat-Free Framework
Did you setup the class loader for your controller?

Am Freitag, 7. Oktober 2016 21:38:02 UTC+2 schrieb Drew:
I posted a summary of my issue on StackOverflow but figured I'd get more tailored advice here:

My (relevant) project structure is:

web/
  fatfree
/
    index
.php
    app
/
     
*.ini
      controllers
/
       
DeviceController.php
      models
/
      views
/
    lib
/
    tests
/
      app
/
        bootstrap
.php
        phpunit
.xml
        controllers
/
         
DeviceControllerTests.php

In my DeviceController.php class I have the action method that I am trying to test:

function devices($f3) {
    $currentUser
= $this->currentUser($f3);
    $devicesForCurrentUser
= $this->userDevicesViewModel->devicesForUser($currentUser->ID);
    $f3
->set("name", $currentUser->Name);
    $f3
->set("devices", $devicesForCurrentUser);
    $template
= new Template;
    echo $template
->render("devices.html");
}

In my DeviceControllerTests.php test class I have:

<?php


class DeviceControllerTests extends PHPUnit\Framework\TestCase {
   
protected $f3;


   
protected function setUp() {
        $this
->f3 = require(__DIR__ . "/../../../lib/base.php");
   
}


   
function testRoute() {
        $this
->f3->route("GET /devices", "DeviceController->devices");
        $this
->f3->mock("GET /devices");
        $name
= $this->f3->get("Test Name");
        $test
->expect($name == "Test Name", "Uri param 'name' equals 'Test Name'");
   
}
}

When I run PHPUnit by doing
 
./vendor/bin/phpunit --configuration web/fatfree/tests/phpunit.xml

I get the following output that I don't understand:

PHPUnit 5.5.7 by Sebastian Bergmann and contributors.

HTTP
404 (GET --configuration)
If I remove $this->f3->route("GET /devices", "DeviceController->devices"); from the test, it says No routes specified when I try to run the tests again.

My website works as expected otherwise, just not this test.

I'm not sure why I'm getting a 404. I'm new to PHPUnit. I assume it could be related to not including Fat Free properly, but I can't figure out what else to do. If I could get help with an example how to test my controller method, I'd appreciate it.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages