GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( e9c651...e1baf6 )
by Christian
02:19
created

EntityManagerMockFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 39
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 39
rs 9.472
c 0
b 0
f 0
cc 2
nc 2
nop 3
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;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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