| Q |
A |
| PHPUnit version |
12.1.5 |
| PHP version |
8.3.21 |
| Installation Method |
PHAR |
Summary
When trying to create a stub via createStubForIntersectionOfInterfaces() a UnknownTypeException is thrown.
But creating a stub for the seemingly unknown class via createStub() does work.
Current behavior
In my test I want to create a stub for a class and an interface:
$userRepositoryStub = $this->createStubForIntersectionOfInterfaces([
UserRepositoryInterface::class,
\Doctrine\ORM\EntityRepository::class
]);
When running the test I get this error:
1) [REDACTED]\MyTest::fooBarBaz
PHPUnit\Framework\MockObject\Generator\UnknownTypeException: Class or interface "Doctrine\ORM\EntityRepository" does not exist
But doing it the following way works and the assertions pass:
$userRepository = $this->createStub(\Doctrine\ORM\EntityRepository::class)
$this->assertInstanceOf(\Doctrine\ORM\EntityRepository::class, $userRepository);
$this->assertTrue(class_exists(\Doctrine\ORM\EntityRepository::class));
How to reproduce
I'am currently unable to provide a minimal reproducible example - I'll try doing so tommorrow.
But here is my (minimalized) UserRepositoryInterface interface:
interface UserRepositoryInterface extends Doctrine\Persistence\ObjectRepository
{
// [...]
}
The \Doctrine\ORM\EntityRepository class is from doctrine/orm:3.3.3: https://github.com/doctrine/orm/blob/3.3.3/src/EntityRepository.php
I should also mention that I'm not using the standard composer autoloader but a custom boostrapping script for PHPUnit.
Maybe the issue is caused by UserRepositoryInterface and \Doctrine\ORM\EntityRepository extending the same \Doctrine\Persistence\ObjectRepository interface?
I also noticed that the error message Class or interface "Doctrine\ORM\EntityRepository" does not exist is missing the backslash (\) in front of Doctrine\ which may also cause a problem when trying to find the class?
Expected behavior
Calling createStubForIntersectionOfInterfaces() should not throw an exception since the class exists.
Summary
When trying to create a stub via
createStubForIntersectionOfInterfaces()aUnknownTypeExceptionis thrown.But creating a stub for the seemingly unknown class via
createStub()does work.Current behavior
In my test I want to create a stub for a class and an interface:
When running the test I get this error:
But doing it the following way works and the assertions pass:
How to reproduce
I'am currently unable to provide a minimal reproducible example - I'll try doing so tommorrow.
But here is my (minimalized)
UserRepositoryInterfaceinterface:The
\Doctrine\ORM\EntityRepositoryclass is fromdoctrine/orm:3.3.3: https://github.com/doctrine/orm/blob/3.3.3/src/EntityRepository.phpI should also mention that I'm not using the standard composer autoloader but a custom boostrapping script for PHPUnit.
Maybe the issue is caused by
UserRepositoryInterfaceand\Doctrine\ORM\EntityRepositoryextending the same\Doctrine\Persistence\ObjectRepositoryinterface?I also noticed that the error message
Class or interface "Doctrine\ORM\EntityRepository" does not existis missing the backslash (\) in front ofDoctrine\which may also cause a problem when trying to find the class?Expected behavior
Calling
createStubForIntersectionOfInterfaces()should not throw an exception since the class exists.