1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * (c) Christian Gripp <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Core23\DoctrineExtensions\Test\ORM; |
||
13 | |||
14 | use Doctrine\DBAL\Connection; |
||
15 | use Doctrine\ORM\AbstractQuery; |
||
16 | use Doctrine\ORM\EntityManager; |
||
17 | use Doctrine\ORM\EntityManagerInterface; |
||
18 | use Doctrine\ORM\EntityRepository; |
||
19 | use Doctrine\ORM\Mapping\ClassMetadataInfo; |
||
20 | use Doctrine\ORM\QueryBuilder; |
||
21 | use Doctrine\ORM\Version; |
||
22 | use PHPUnit\Framework\TestCase; |
||
23 | |||
24 | final class EntityManagerMockFactory |
||
25 | { |
||
26 | /** |
||
27 | * @param TestCase $test |
||
28 | * @param \Closure $qbCallback |
||
29 | * @param mixed $fields |
||
30 | * |
||
31 | * @return \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface |
||
32 | */ |
||
33 | public static function create(TestCase $test, \Closure $qbCallback, $fields): \PHPUnit_Framework_MockObject_MockObject |
||
0 ignored issues
–
show
|
|||
34 | { |
||
35 | $query = $test->getMockBuilder(AbstractQuery::class) |
||
36 | ->disableOriginalConstructor()->getMock(); |
||
37 | $query->expects($test->any())->method('execute')->will($test->returnValue(true)); |
||
38 | |||
39 | if (Version::compare('2.5.0') < 1) { |
||
40 | $entityManager = $test->getMockBuilder(EntityManagerInterface::class)->getMock(); |
||
41 | $qb = $test->getMockBuilder(QueryBuilder::class)->setConstructorArgs([$entityManager])->getMock(); |
||
42 | } else { |
||
43 | $qb = $test->getMockBuilder(QueryBuilder::class)->disableOriginalConstructor()->getMock(); |
||
44 | } |
||
45 | |||
46 | $qb->expects($test->any())->method('select')->will($test->returnValue($qb)); |
||
47 | $qb->expects($test->any())->method('getQuery')->will($test->returnValue($query)); |
||
48 | $qb->expects($test->any())->method('where')->will($test->returnValue($qb)); |
||
49 | $qb->expects($test->any())->method('orderBy')->will($test->returnValue($qb)); |
||
50 | $qb->expects($test->any())->method('andWhere')->will($test->returnValue($qb)); |
||
51 | $qb->expects($test->any())->method('leftJoin')->will($test->returnValue($qb)); |
||
52 | |||
53 | $qbCallback($qb); |
||
54 | |||
55 | $repository = $test->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->getMock(); |
||
56 | $repository->expects($test->any())->method('createQueryBuilder')->will($test->returnValue($qb)); |
||
57 | |||
58 | $metadata = $test->getMockBuilder(ClassMetadataInfo::class)->disableOriginalConstructor()->getMock(); |
||
59 | $metadata->expects($test->any())->method('getFieldNames')->will($test->returnValue($fields)); |
||
60 | $metadata->expects($test->any())->method('getName')->will($test->returnValue('className')); |
||
61 | $metadata->expects($test->any())->method('getIdentifier')->will($test->returnValue('id')); |
||
62 | $metadata->expects($test->any())->method('getTableName')->will($test->returnValue('dummy')); |
||
63 | |||
64 | $connection = $test->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); |
||
65 | |||
66 | $em = $test->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock(); |
||
67 | $em->expects($test->any())->method('getRepository')->will($test->returnValue($repository)); |
||
68 | $em->expects($test->any())->method('getClassMetadata')->will($test->returnValue($metadata)); |
||
69 | $em->expects($test->any())->method('getConnection')->will($test->returnValue($connection)); |
||
70 | |||
71 | return $em; |
||
72 | } |
||
73 | } |
||
74 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths