I’m trying to write a simple unit test for a single function in my Slim PHP application. The function creates a directory using mkdir() and I want the test to assert that the directory is created successfully. When tested using the front end application, the folder is created successfully, however when running the test, the directory is not found
1) TestController::testCreate mkdir(): No such file or directory
We are autoloading classes using the follow:
//composer.json
"autoload": {
"psr-4": {
"App\\": "app",
"tests\\": "tests/"
}
}
This is the function that creates the directory:
//Controllor.php
public function create($request, $response){
mkdir("../public/folder");
}
Using the application, this creates a directory in the following location as expected
-app
-public/folder
This is an example of the test function:
//TestController.php
public function testCreate(){
$controller = new Controller($this->container);
$request = $this->requestFactory();
$response = new \Slim\Http\Response();
$response = $controller>create($request, $response, []);
//Assertions below..
}
I am using a phpunit.xml to bootstrap the autoload.php file by inserting bootstrap="vendor/autoload.php" into the config file.
I have also tried to require the vendor/autoload.php from the TestController.php and have tried to manually set $_SERVER['DOCUMENT_ROOT']
in TestController.php
How can I autoload the namespaces while running TestController.php so that the create() function is invoking mkdir() from the correct location?
Aucun commentaire:
Enregistrer un commentaire