The class under test is in app \ web:
<?php declare(strict_types = 1); namespace app\web; class Application { private $config = []; public function __construct(array $config = null) { if ($config !== null) { $this->checkConfig($config); $this->config = $config; } } public function configure(array $config) { $this->checkConfig($config); $this->config = $config; } public function checkConfigure() { return !empty($this->config); } public function run() { if (empty($this->config)) { return false; } else { return true; } } public function notFound() { throw new \InvalidArgumentException(); } public function sayHello() { echo 'Hello World!'; } private function checkConfig($config) { if (!is_array($config)) { throw new \Exception("Config must be an array!"); } } } Class with tests in tests \ web:
<?php namespace tests\web; use app\web\Application; class ApplicationTest extends \PHPUnit_Framework_TestCase { public function testRunApplication(){ $app = new Application(['param'=>'value']); $this->assertTrue($app->run()); $wrongApp = new Application([]); $this->assertFalse($wrongApp->run()); $this->assertEquals(true, $app->run()); $this->markTestIncomplete('Incomplete'); } } Actually the problem is that when you run phpunit an error occurs:
Fatal error: Class 'app \ web \ Application' not found in C: \ wamp64 \ www \ unit_test_learning \ tests \ web \ ApplicationTest.php on line 11
I did not find a solution on the network. Please tell me what I'm doing wrong.
* used composer if important
$loader->setPsr4('app\\', __DIR__ . '/path/to/app');- Goncharov Alexander