In my symfony 4 application I try to run the first unit test from the symfony doc. But it returns the follwing message.
// tests/Util/CalculatorTest.php
namespace App\Tests\Util;
use App\Util\Calculator;
use PHPUnit\Framework\TestCase;
public class CalculatorTest extends TestCase
{
public function testAdd()
{
$calculator = new Calculator();
$result = $calculator->add(30, 12);
// assert that your calculator added the numbers correctly!
$this->assertEquals(4, $result);
}
}
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
Time: 17 ms, Memory: 2.00MB
No tests executed!
And when I try to run that test directly using following command it also gives following error.
$ ./bin/phpunit tests/Util/CalculatorTest.php
#!/usr/bin/env php
// tests/Util/CalculatorTest.php
namespace App\Tests\Util;
use App\Util\Calculator;
use PHPUnit\Framework\TestCase;
public class CalculatorTest extends TestCase
{
public function testAdd()
{
$calculator = new Calculator();
$result = $calculator->add(30, 12);
// assert that your calculator added the numbers correctly!
$this->assertEquals(4, $result);
}
}
PHP Fatal error: Uncaught PHPUnit\Runner\Exception: Class 'tests/Util/CalculatorTest' could not be found in '/home/username/server/tests/Util/CalculatorTest.php'. in /home/username/server/bin/.phpunit/phpunit-6.5/src/Runner/StandardTestSuiteLoader.php:102
Any kind of help would be appreciated.
App\Tests\Util
and the classname isCalculatorTest
, why does it try to find the class:tests/Util/CalculatorTest
? You have an autoloading problem. – Dragos