Issues (3627)

StageBundle/Tests/Entity/StageRepositoryTest.php (2 issues)

1
<?php
2
3
/*
4
 * @copyright   2019 Mautic, Inc. All rights reserved
5
 * @author      Mautic, Inc.
6
 *
7
 * @link        https://mautic.com
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\StageBundle\Tests\Entity;
13
14
use Doctrine\ORM\AbstractQuery;
15
use Doctrine\ORM\EntityManager;
16
use Doctrine\ORM\Mapping\ClassMetadata;
17
use Doctrine\ORM\QueryBuilder;
18
use Mautic\StageBundle\Entity\Stage;
19
use Mautic\StageBundle\Entity\StageRepository;
20
21
class StageRepositoryTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var EntityManager|\PHPUnit_Framework_MockObject_MockObject
25
     */
26
    private $entityManager;
27
28
    /**
29
     * @var ClassMetadata|\PHPUnit_Framework_MockObject_MockObject
30
     */
31
    private $classMetadata;
32
33
    /**
34
     * @var StageRepository
35
     */
36
    private $stageRepository;
37
38
    protected function setUp(): void
39
    {
40
        parent::setUp();
41
42
        $this->entityManager = $this->createMock(EntityManager::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Doctri...M\EntityManager::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Doctrine\ORM\EntityManag...k_MockObject_MockObject of property $entityManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
43
        $this->classMetadata = $this->createMock(ClassMetadata::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Doctri...g\ClassMetadata::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Doctrine\ORM\Mapping\Cla...k_MockObject_MockObject of property $classMetadata.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
44
45
        $this->stageRepository = new StageRepository($this->entityManager, $this->classMetadata);
46
    }
47
48
    public function testFindByIdOrNameUseInt()
49
    {
50
        $value ='1';
51
52
        $queryBuilder = $this->createMock(QueryBuilder::class);
53
54
        $this->entityManager->expects($this->once())
55
            ->method('createQueryBuilder')
56
            ->willReturn($queryBuilder);
57
58
        $queryBuilder->expects($this->once())
59
            ->method('select')
60
            ->with('s')
61
            ->willReturn($queryBuilder);
62
63
        $queryBuilder->expects($this->once())
64
            ->method('from')
65
            ->with(Stage::class, 's')
66
            ->willReturn($queryBuilder);
67
68
        $queryBuilder->expects($this->once())
69
            ->method('where')
70
            ->with('s.id = :value')
71
            ->willReturn($queryBuilder);
72
73
        $queryBuilder->expects($this->once())
74
            ->method('orWhere')
75
            ->with('s.name = :value')
76
            ->willReturn($queryBuilder);
77
78
        $queryBuilder->expects($this->once())
79
            ->method('setParameter')
80
            ->with('value', $value)
81
            ->willReturn($queryBuilder);
82
83
        $query = $this->getMockBuilder(AbstractQuery::class)
84
            ->disableOriginalConstructor()
85
            ->setMethods(['getOneOrNullResult'])
86
            ->getMockForAbstractClass();
87
88
        $queryBuilder->expects($this->once())
89
            ->method('getQuery')
90
            ->willReturn($query);
91
92
        $query->expects($this->once())
93
            ->method('getOneOrNullResult')
94
            ->willReturn(new Stage());
95
96
        $this->stageRepository->findByIdOrName($value);
97
    }
98
99
    public function testFindByIdOrNameUseString()
100
    {
101
        $value ='string';
102
103
        $queryBuilder = $this->createMock(QueryBuilder::class);
104
105
        $this->entityManager->expects($this->once())
106
            ->method('createQueryBuilder')
107
            ->willReturn($queryBuilder);
108
109
        $queryBuilder->expects($this->once())
110
            ->method('select')
111
            ->with('s')
112
            ->willReturn($queryBuilder);
113
114
        $queryBuilder->expects($this->once())
115
            ->method('from')
116
            ->with(Stage::class, 's')
117
            ->willReturn($queryBuilder);
118
119
        $queryBuilder->expects($this->once())
120
            ->method('where')
121
            ->with('s.name = :value')
122
            ->willReturn($queryBuilder);
123
124
        $queryBuilder->expects($this->once())
125
            ->method('setParameter')
126
            ->with('value', $value)
127
            ->willReturn($queryBuilder);
128
129
        $query = $this->getMockBuilder(AbstractQuery::class)
130
            ->disableOriginalConstructor()
131
            ->setMethods(['getOneOrNullResult'])
132
            ->getMockForAbstractClass();
133
134
        $queryBuilder->expects($this->once())
135
            ->method('getQuery')
136
            ->willReturn($query);
137
138
        $query->expects($this->once())
139
            ->method('getOneOrNullResult')
140
            ->willReturn(new Stage());
141
142
        $this->stageRepository->findByIdOrName($value);
143
    }
144
}
145