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.