mardi 24 mai 2016

How to include file in phpunit test?

I'm having some trouble including a file in a phpunit test. For example: when I execute the following code in PhpStorm I get the expected output.

Code:

class NifvalidationTest extends PHPUnit_Framework_TestCase
{
    public function test_apiRequest()
    {
        $result = 1+1;
        $this->assertEquals(2, $result);
    }
}

Output:

Testing started at 16:58 ...
PHPUnit 5.2.12 by Sebastian Bergmann and contributors.



Time: 120 ms, Memory: 11.50Mb

OK (1 test, 1 assertion)

Process finished with exit code 0

But when I need to access a method from another class using the include, I dont get the expected output. Just as an example, when I execute the following code:

class NifvalidationTest extends PHPUnit_Framework_TestCase
{
    public function test_apiRequest()
    {
        include('/../nifvalidation.php');
        $result = 1+1;
        $this->assertEquals(2, $result);
    }
}

I get this instead of the expected output:

Testing started at 17:05 ...
PHPUnit 5.2.12 by Sebastian Bergmann and contributors.


Process finished with exit code 0

Any ideas on why the include is breaking the test?

Note 1: In the above example I dont need to include the file, but I need in another tests.

Note 2: The path to the file 'nifvalidation.php' is correct.

Aucun commentaire:

Enregistrer un commentaire