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 ( 46e57d...ec86a4 )
by Christian
01:49
created

EntityManagerMockFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B create() 0 39 2
1
<?php
2
3
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\DoctrineExtensions\Test\ORM;
11
12
use Doctrine\DBAL\Connection;
13
use Doctrine\ORM\AbstractQuery;
14
use Doctrine\ORM\EntityManager;
15
use Doctrine\ORM\EntityManagerInterface;
16
use Doctrine\ORM\EntityRepository;
17
use Doctrine\ORM\Mapping\ClassMetadataInfo;
18
use Doctrine\ORM\QueryBuilder;
19
use Doctrine\ORM\Version;
20
21
final class EntityManagerMockFactory
22
{
23
    /**
24
     * @param \PHPUnit_Framework_TestCase $test
25
     * @param \Closure                    $qbCallback
26
     * @param mixed                       $fields
27
     *
28
     * @return \PHPUnit_Framework_MockObject_MockObject|EntityManagerInterface
29
     */
30
    public static function create(\PHPUnit_Framework_TestCase $test, \Closure $qbCallback, $fields): \PHPUnit_Framework_MockObject_MockObject
31
    {
32
        $query = $test->getMockBuilder(AbstractQuery::class)
33
            ->disableOriginalConstructor()->getMock();
34
        $query->expects($test->any())->method('execute')->will($test->returnValue(true));
35
36
        if (Version::compare('2.5.0') < 1) {
37
            $entityManager = $test->getMockBuilder(EntityManagerInterface::class)->getMock();
38
            $qb            = $test->getMockBuilder(QueryBuilder::class)->setConstructorArgs(array($entityManager))->getMock();
39
        } else {
40
            $qb = $test->getMockBuilder(QueryBuilder::class)->disableOriginalConstructor()->getMock();
41
        }
42
43
        $qb->expects($test->any())->method('select')->will($test->returnValue($qb));
44
        $qb->expects($test->any())->method('getQuery')->will($test->returnValue($query));
45
        $qb->expects($test->any())->method('where')->will($test->returnValue($qb));
46
        $qb->expects($test->any())->method('orderBy')->will($test->returnValue($qb));
47
        $qb->expects($test->any())->method('andWhere')->will($test->returnValue($qb));
48
        $qb->expects($test->any())->method('leftJoin')->will($test->returnValue($qb));
49
50
        $qbCallback($qb);
51
52
        $repository = $test->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->getMock();
53
        $repository->expects($test->any())->method('createQueryBuilder')->will($test->returnValue($qb));
54
55
        $metadata = $test->getMockBuilder(ClassMetadataInfo::class)->disableOriginalConstructor()->getMock();
56
        $metadata->expects($test->any())->method('getFieldNames')->will($test->returnValue($fields));
57
        $metadata->expects($test->any())->method('getName')->will($test->returnValue('className'));
58
        $metadata->expects($test->any())->method('getIdentifier')->will($test->returnValue('id'));
59
        $metadata->expects($test->any())->method('getTableName')->will($test->returnValue('dummy'));
60
61
        $connection = $test->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
62
63
        $em = $test->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock();
64
        $em->expects($test->any())->method('getRepository')->will($test->returnValue($repository));
65
        $em->expects($test->any())->method('getClassMetadata')->will($test->returnValue($metadata));
66
        $em->expects($test->any())->method('getConnection')->will($test->returnValue($connection));
67
68
        return $em;
69
    }
70
}
71