I just installed PHPUnit Testing and for some reason it won't read my file. I'm sure it's in the correct path, but why PHPUnit can't find it?
Here is my sample code:
functions.php
<?php
function my_addition($arg1, $arg2){
return $arg1 + $arg2;
?>
Here is the code and the file to test:
functions_test.php
<?php
use PHPUnit\Framework\TestCase;
class functions_test extends TestCase {
public function testmy_addition() {
include("./data/functions.php");
$result = my_addition(1,1);
$this->assertEquals(2, $result);
}
}
?>
What can I do to get it to work and make it pass?
You should be able to use __DIR__ . "/data/functions.php"
in your include statement
(that's two underscores before and after).
I did a quick test in my test environment and had no problems.
The __DIR__
magic constant gives you the full path to the test file you are running. From the PHP website:
The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to
dirname(__FILE__)
. This directory name does not have a trailing slash unless it is the root directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With