Completed
Pull Request — master (#725)
by
unknown
01:55
created

StubRepository::getEntityManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Doctrine Bundle
4
 *
5
 * The code was originally distributed inside the Symfony framework.
6
 *
7
 * (c) Fabien Potencier <[email protected]>
8
 * (c) Doctrine Project, Benjamin Eberlei <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
*/
13
14
namespace Doctrine\Bundle\DoctrineBundle\Tests\Twig;
15
16
use Doctrine\Bundle\DoctrineBundle\Repository\RepositoryTrait;
17
use Doctrine\ORM\EntityManagerInterface;
18
use Doctrine\ORM\EntityRepository;
19
use Doctrine\ORM\QueryBuilder;
20
use PHPUnit\Framework\TestCase;
21
22
class RepositoryTraitTest extends TestCase
23
{
24
    public function testBasicTraitFunctionality()
25
    {
26
        $em = $this->getMockBuilder(EntityManagerInterface::class)->getMock();
27
        $repo = $this->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->getMock();
28
29
        $em->expects($this->once())
30
            ->method('getRepository')
31
            ->with('App\Entity\CoolStuff')
32
            ->will($this->returnValue($repo));
33
34
        $qb = new QueryBuilder($em);
35
        $repo->expects($this->once())
36
            ->method('createQueryBuilder')
37
            ->with('cs')
38
            ->willReturn($qb);
39
40
        $stubRepo = new StubRepository($em);
41
        $this->assertSame($qb, $stubRepo->createQueryBuilder('cs'));
42
    }
43
}
44
45
class StubRepository
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
46
{
47
    use RepositoryTrait;
48
49
    private $em;
50
51
    public function __construct(EntityManagerInterface $em)
52
    {
53
        $this->em = $em;
54
    }
55
56
    protected function getEntityManager()
57
    {
58
        return $this->em;
59
    }
60
61
    protected function getClassName()
62
    {
63
        return 'App\Entity\CoolStuff';
64
    }
65
}