Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

AbstractArticlePageAdminListConfiguratorTest.php (11 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\ArticleBundle\Tests\AdminList;
4
5
use Doctrine\ORM\EntityManager;
6
use Doctrine\ORM\EntityRepository;
7
use Doctrine\ORM\QueryBuilder;
8
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
9
use Kunstmaan\ArticleBundle\AdminList\AbstractArticlePageAdminListConfigurator;
10
use Kunstmaan\NodeBundle\Entity\Node;
11
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
12
use Kunstmaan\NodeBundle\Helper\NodeMenu;
13
use Kunstmaan\NodeBundle\Helper\NodeMenuItem;
14
use PHPUnit\Framework\TestCase;
15
use ReflectionClass;
16
17
class Configurator extends AbstractArticlePageAdminListConfigurator
18
{
19
    /** @var EntityRepository */
20
    private $repo;
21
22
    public function __construct(EntityManager $em, AclHelper $aclHelper, $locale, $permission, $repo)
23
    {
24
        parent::__construct($em, $aclHelper, $locale, $permission);
25
        $this->repo = $repo;
26
    }
27
28
    /**
29
     * @return bool
0 ignored issues
show
Should the return type not be EntityRepository?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
30
     */
31
    public function getOverviewPageRepository()
32
    {
33
        return $this->repo;
34
    }
35
}
36
37
/**
38
 * Class AbstractArticlePageAdminListConfiguratorTest
39
 */
40
class AbstractArticlePageAdminListConfiguratorTest extends TestCase
41
{
42
    /**
43
     * @var AbstractArticlePageAdminListConfigurator
44
     */
45
    protected $object;
46
47
    /**
48
     * @var EntityManager
49
     */
50
    protected $em;
51
52
    /**
53
     * Sets up the fixture, for example, opens a network connection.
54
     * This method is called before a test is executed.
55
     */
56
    protected function setUp()
57
    {
58
        $em = $this->createMock(EntityManager::class);
59
        $em->expects($this->any())
60
            ->method($this->anything())
61
            ->willReturn($em);
62
63
        $acl = $this->createMock(AclHelper::class);
64
65
        $repo = $this->createMock(EntityRepository::class);
66
        $repo->expects($this->any())
67
            ->method($this->anything())
68
            ->willReturn([['fake' => 'array']]);
69
70
        $this->em = $em;
0 ignored issues
show
Documentation Bug introduced by
It seems like $em of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\ORM\EntityManager> of property $em.

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...
71
72
        /* @var EntityManager $em */
73
        /* @var AclHelper $acl */
74
        $this->object = new Configurator($em, $acl, 'nl', 'admin', $repo);
0 ignored issues
show
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
    }
76
77
    public function testGetters()
78
    {
79
        $this->assertEquals('KunstmaanArticleBundle', $this->object->getBundleName());
80
        $this->assertEquals('AbstractArticlePage', $this->object->getEntityName());
81
        $this->assertEquals('@KunstmaanArticle/AbstractArticlePageAdminList/list.html.twig', $this->object->getListTemplate());
82
        $this->assertEquals('KunstmaanArticleBundle:AbstractArticlePage', $this->object->getRepositoryName());
83
    }
84
85
    public function testBuildFields()
86
    {
87
        $this->object->buildFields();
88
        $this->object->buildFilters();
89
        $fields = $this->object->getFields();
90
        $this->assertCount(4, $fields);
0 ignored issues
show
$fields is of type array<integer,object<Kun...undle\AdminList\Field>>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
91
    }
92
93
    public function testGetUrls()
94
    {
95
        $node = new Node();
96
        $node->setId(1314);
97
        $nodeTranslation = new NodeTranslation();
98
        /** @var NodeMenu $menu */
99
        $menu = $this->createMock(NodeMenu::class);
100
        $item = new NodeMenuItem($node, $nodeTranslation, false, $menu);
101
102
        $url = $this->object->getEditUrlFor($item);
103
104
        $this->assertCount(2, $url);
0 ignored issues
show
$url is of type array<string,string|arra...\"id\":\"integer\"}>"}>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
105
        $this->assertArrayHasKey('path', $url);
106
        $this->assertArrayHasKey('params', $url);
107
        $this->assertEquals('KunstmaanNodeBundle_nodes_edit', $url['path']);
108
        $this->assertCount(1, $url['params']);
0 ignored issues
show
$url['params'] is of type array<string,integer,{"id":"integer"}>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
109
        $this->assertEquals(1314, $url['params']['id']);
110
111
        $url = $this->object->getDeleteUrlFor($item);
112
113
        $this->assertCount(2, $url);
0 ignored issues
show
$url is of type array<string,string|arra...\"id\":\"integer\"}>"}>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
114
        $this->assertArrayHasKey('path', $url);
115
        $this->assertArrayHasKey('params', $url);
116
        $this->assertEquals('KunstmaanNodeBundle_nodes_delete', $url['path']);
117
        $this->assertCount(1, $url['params']);
0 ignored issues
show
$url['params'] is of type array<string,integer,{"id":"integer"}>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
118
        $this->assertEquals(1314, $url['params']['id']);
119
    }
120
121
    /**
122
     * @throws \ReflectionException
123
     */
124
    public function testGetQueryBuilder()
125
    {
126
        $em = $this->createMock(EntityManager::class);
127
        $qb = $this->createMock(QueryBuilder::class);
128
        $em->expects($this->any())
129
            ->method('createQueryBuilder')
130
            ->willReturn($qb);
131
132
        $em->expects($this->any())
133
            ->method('getRepository')
134
            ->willReturn($em);
135
136
        $this->em = $em;
0 ignored issues
show
Documentation Bug introduced by
It seems like $em of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\ORM\EntityManager> of property $em.

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...
137
138
        $mirror = new ReflectionClass(Configurator::class);
139
        $method = $mirror->getMethod('getQueryBuilder');
140
        $method->setAccessible(true);
141
142
        $mirror = new ReflectionClass(Configurator::class);
143
        $prop = $mirror->getProperty('em');
144
        $prop->setAccessible(true);
145
        $prop->setValue($this->object, $em);
146
147
        /* @var QueryBuilder $qb */
148
        $this->object->adaptQueryBuilder($qb);
149
        $qb = $method->invoke($this->object);
150
        $this->assertInstanceOf(QueryBuilder::class, $qb);
151
    }
152
153
    /**
154
     * @throws \ReflectionException
155
     */
156
    public function testEntityClassName()
157
    {
158
        $em = $this->createMock(EntityManager::class);
159
        $repo = $this->createMock(EntityRepository::class);
160
161
        $em->expects($this->any())
162
            ->method('getRepository')
163
            ->willReturn($repo);
164
165
        $repo->expects($this->any())
166
            ->method('getClassName')
167
            ->willReturn(Configurator::class);
168
169
        $this->em = $em;
0 ignored issues
show
Documentation Bug introduced by
It seems like $em of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\ORM\EntityManager> of property $em.

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...
170
171
        $mirror = new ReflectionClass(Configurator::class);
172
        $method = $mirror->getMethod('getQueryBuilder');
173
        $method->setAccessible(true);
174
175
        $mirror = new ReflectionClass(Configurator::class);
176
        $prop = $mirror->getProperty('em');
177
        $prop->setAccessible(true);
178
        $prop->setValue($this->object, $em);
179
        $this->assertEquals(Configurator::class, $this->object->getEntityClassName());
180
    }
181
182
    /**
183
     * @throws \ReflectionException
184
     */
185
    public function testGetOverViewPages()
186
    {
187
        $this->assertCount(1, $this->object->getOverviewPages());
188
        $this->assertCount(1, $this->object->getOverviewPage());
0 ignored issues
show
$this->object->getOverviewPage() is of type object<Kunstmaan\Article...actArticleOverviewPage>, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
189
190
        $mirror = new ReflectionClass(Configurator::class);
191
        $prop = $mirror->getProperty('repo');
192
        $prop->setAccessible(true);
193
194
        $repo = $this->createMock(EntityRepository::class);
195
        $repo->expects($this->any())
196
            ->method($this->anything())
197
            ->willReturn([]);
198
199
        $prop->setValue($this->object, $repo);
200
201
        $this->assertNull($this->object->getOverviewPage());
202
    }
203
}
204