Answer the question
In order to leave comments, you need to log in
Problem with phpunit. How to inherit a class?
I want to move the code to a separate class and inherit it by other classes... When I run tests, I get a fatality:
PHP Fatal error: Class 'App\Bundle\CoreBundle\Tests\Repository\DoctrineTestCase' not found in /home/user/desktop/app/tests/AppCoreBundle/Repository/CategoryRepositoryTest.php on line 8
namespace App\Bundle\CoreBundle\Tests\Repository;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class DoctrineTestCase extends KernelTestCase
{
/**
* @var EntityManager
*/
protected $em;
protected function setUp()
{
self::bootKernel();
$this->em = static::$kernel->getContainer()
->get('doctrine')
->getManager();
}
protected function tearDown()
{
parent::tearDown();
$this->em->close();
$this->em = null;
}
...
}
namespace App\Bundle\CoreBundle\Tests\Repository;
use App\Bundle\CoreBundle\Entity\Category;
class CategoryRepositoryTest extends DoctrineTestCase
{
...
}
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/** @var ClassLoader $loader */
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
return $loader;
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="app/autoload.php"
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_DIR" value="app/" />
</php>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/*Bundle/Resources</directory>
<directory>src/*/*Bundle/Resources</directory>
<directory>src/*/Bundle/*Bundle/Resources</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
Answer the question
In order to leave comments, you need to log in
Good afternoon.
You have a problem with Namespace.
You specified App\Bundle\CoreBundle\Tests\Repository;
And the files are in app/tests/AppCoreBundle/Repository;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question