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\MockObject\MockObject; |
||
1 ignored issue
–
show
|
|||
23 | use PHPUnit\Framework\TestCase; |
||
24 | |||
25 | final class EntityManagerMockFactory |
||
26 | { |
||
27 | /** |
||
28 | * @param TestCase $test |
||
29 | * @param \Closure $qbCallback |
||
30 | * @param mixed $fields |
||
31 | * |
||
32 | * @return MockObject|EntityManagerInterface |
||
33 | */ |
||
34 | public static function create(TestCase $test, \Closure $qbCallback, $fields) |
||
35 | { |
||
36 | $query = $test->getMockBuilder(AbstractQuery::class) |
||
37 | ->disableOriginalConstructor()->getMock(); |
||
38 | $query->expects($test->any())->method('execute')->will($test->returnValue(true)); |
||
39 | |||
40 | if (Version::compare('2.5.0') < 1) { |
||
41 | $entityManager = $test->getMockBuilder(EntityManagerInterface::class)->getMock(); |
||
42 | $qb = $test->getMockBuilder(QueryBuilder::class)->setConstructorArgs([$entityManager])->getMock(); |
||
43 | } else { |
||
44 | $qb = $test->getMockBuilder(QueryBuilder::class)->disableOriginalConstructor()->getMock(); |
||
45 | } |
||
46 | |||
47 | $qb->expects($test->any())->method('select')->will($test->returnValue($qb)); |
||
48 | $qb->expects($test->any())->method('getQuery')->will($test->returnValue($query)); |
||
49 | $qb->expects($test->any())->method('where')->will($test->returnValue($qb)); |
||
50 | $qb->expects($test->any())->method('orderBy')->will($test->returnValue($qb)); |
||
51 | $qb->expects($test->any())->method('andWhere')->will($test->returnValue($qb)); |
||
52 | $qb->expects($test->any())->method('leftJoin')->will($test->returnValue($qb)); |
||
53 | |||
54 | $qbCallback($qb); |
||
55 | |||
56 | $repository = $test->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->getMock(); |
||
57 | $repository->expects($test->any())->method('createQueryBuilder')->will($test->returnValue($qb)); |
||
58 | |||
59 | $metadata = $test->getMockBuilder(ClassMetadataInfo::class)->disableOriginalConstructor()->getMock(); |
||
60 | $metadata->expects($test->any())->method('getFieldNames')->will($test->returnValue($fields)); |
||
61 | $metadata->expects($test->any())->method('getName')->will($test->returnValue('className')); |
||
62 | $metadata->expects($test->any())->method('getIdentifier')->will($test->returnValue('id')); |
||
63 | $metadata->expects($test->any())->method('getTableName')->will($test->returnValue('dummy')); |
||
64 | |||
65 | $connection = $test->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); |
||
66 | |||
67 | $em = $test->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock(); |
||
68 | $em->expects($test->any())->method('getRepository')->will($test->returnValue($repository)); |
||
69 | $em->expects($test->any())->method('getClassMetadata')->will($test->returnValue($metadata)); |
||
70 | $em->expects($test->any())->method('getConnection')->will($test->returnValue($connection)); |
||
71 | |||
72 | return $em; |
||
73 | } |
||
74 | } |
||
75 |
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