|
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\Doctrine\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; |
|
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|EntityManager |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function create(TestCase $test, \Closure $qbCallback, $fields): MockObject |
|
35
|
|
|
{ |
|
36
|
|
|
$query = $test->getMockBuilder(AbstractQuery::class) |
|
37
|
|
|
->disableOriginalConstructor()->getMock(); |
|
38
|
|
|
$query->method('execute')->willReturn(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->method('select')->willReturn($qb); |
|
48
|
|
|
$qb->method('getQuery')->willReturn($query); |
|
49
|
|
|
$qb->method('where')->willReturn($qb); |
|
50
|
|
|
$qb->method('orderBy')->willReturn($qb); |
|
51
|
|
|
$qb->method('andWhere')->willReturn($qb); |
|
52
|
|
|
$qb->method('leftJoin')->willReturn($qb); |
|
53
|
|
|
|
|
54
|
|
|
$qbCallback($qb); |
|
55
|
|
|
|
|
56
|
|
|
$repository = $test->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->getMock(); |
|
57
|
|
|
$repository->method('createQueryBuilder')->willReturn($qb); |
|
58
|
|
|
|
|
59
|
|
|
$metadata = $test->getMockBuilder(ClassMetadataInfo::class)->disableOriginalConstructor()->getMock(); |
|
60
|
|
|
$metadata->method('getFieldNames')->willReturn($fields); |
|
61
|
|
|
$metadata->method('getName')->willReturn('className'); |
|
62
|
|
|
$metadata->method('getIdentifier')->willReturn(['id']); |
|
63
|
|
|
$metadata->method('getTableName')->willReturn('dummy'); |
|
64
|
|
|
|
|
65
|
|
|
$connection = $test->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); |
|
66
|
|
|
|
|
67
|
|
|
$em = $test->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock(); |
|
68
|
|
|
$em->method('getRepository')->willReturn($repository); |
|
69
|
|
|
$em->method('getClassMetadata')->willReturn($metadata); |
|
70
|
|
|
$em->method('getConnection')->willReturn($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