Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

FormSubmissionAdminListConfiguratorTest.php (14 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\FormBundle\Tests\AdminList;
4
5
use Doctrine\ORM\Configuration;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\EntityRepository;
8
use Doctrine\ORM\QueryBuilder;
9
use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction;
10
use Kunstmaan\FormBundle\AdminList\FormSubmissionAdminListConfigurator;
11
use Kunstmaan\NodeBundle\Entity\AbstractPage;
12
use Kunstmaan\NodeBundle\Entity\Node;
13
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
14
use PHPUnit\Framework\TestCase;
15
16
/**
17
 * This test tests the FormPageAdminListConfigurator
18
 */
19
class FormSubmissionAdminListConfiguratorTest extends TestCase
20
{
21
    /**
22
     * @var FormSubmissionAdminListConfigurator
23
     */
24
    protected $object;
25
26
    /**
27
     * Sets up the fixture, for example, opens a network connection.
28
     * This method is called before a test is executed.
29
     */
30 View Code Duplication
    protected function setUp()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        $em = $this->getMockedEntityManager();
33
        $node = new Node();
34
        $node->setId(666);
35
        $nt = new NodeTranslation();
36
        $nt->setNode($node);
37
        $this->object = new FormSubmissionAdminListConfigurator($em, $nt);
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...
38
    }
39
40
    /**
41
     * @return \Doctrine\ORM\EntityManager
0 ignored issues
show
Should the return type not be \PHPUnit\Framework\MockObject\MockObject?

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...
42
     */
43 View Code Duplication
    protected function getMockedEntityManager()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $configuration = $this->createMock(Configuration::class);
46
        $configuration->method('getQuoteStrategy')->willReturn(null);
47
48
        $repository = $this->createMock(EntityRepository::class);
49
        $repository->method('find')->willReturn(null);
50
        $repository->method('findBy')->willReturn(null);
51
        $repository->method('findOneBy')->willReturn(null);
52
53
        $emMock = $this->createMock(EntityManager::class);
54
        $emMock->method('getRepository')->willReturn($repository);
55
        $emMock->method('getClassMetaData')->willReturn((object) ['name' => 'aClass']);
56
        $emMock->method('getConfiguration')->willReturn($configuration);
57
        $emMock->method('persist')->willReturn(null);
58
        $emMock->method('flush')->willReturn(null);
59
60
        return $emMock;
61
    }
62
63
    public function testAdaptQueryBuilder()
64
    {
65
        $queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
69
        $queryBuilder->expects($this->once())
70
            ->method('innerJoin')
71
            ->will($this->returnSelf());
72
73
        $queryBuilder->expects($this->atLeastOnce())
74
            ->method('andWhere')
75
            ->will($this->returnSelf());
76
77
        $queryBuilder->expects($this->atLeastOnce())
78
            ->method('setParameter')
79
            ->will($this->returnSelf());
80
81
        /* @var QueryBuilder $queryBuilder */
82
        $this->object->adaptQueryBuilder($queryBuilder);
83
    }
84
85 View Code Duplication
    public function testFixedGetters()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        $item = $this->createMock(AbstractPage::class);
88
        $item->method('getId')->willReturn(123);
89
90
        $this->assertEquals('', $this->object->getAddUrlFor([]));
91
        $this->assertEquals('KunstmaanFormBundle', $this->object->getBundleName());
92
        $this->assertEquals('FormSubmission', $this->object->getEntityName());
93
        $this->assertCount(0, $this->object->getDeleteUrlFor($item));
0 ignored issues
show
$this->object->getDeleteUrlFor($item) is of type array, 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...
94
        $this->assertCount(2, $this->object->getIndexUrl());
0 ignored issues
show
$this->object->getIndexUrl() is of type array<string,string|arra...onId\":\"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...
95
        $this->assertCount(2, $this->object->getEditUrlFor($item));
0 ignored issues
show
$this->object->getEditUrlFor($item) is of type array<string,string|arra...bmissionId\":\"?\"}>"}>, 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...
96
        $this->assertCount(2, $this->object->getExportUrl());
0 ignored issues
show
$this->object->getExportUrl() is of type array|string, 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...
97
        $this->assertFalse($this->object->canAdd());
98
        $this->assertFalse($this->object->canEdit($item));
99
        $this->assertFalse($this->object->canDelete($item));
100
        $this->assertTrue($this->object->canExport());
101
    }
102
103
    public function testBuildFilters()
104
    {
105
        $this->object->buildFilters();
106
        $filters = $this->object->getFilterBuilder()->getFilterDefinitions();
107
        $this->assertCount(3, $filters);
0 ignored issues
show
$filters is of type array, 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...
108
    }
109
110
    public function testBuildFields()
111
    {
112
        $this->object->buildFields();
113
        $fields = $this->object->getFields();
114
        $this->assertCount(3, $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...
115
    }
116
117 View Code Duplication
    public function testBuildItemActions()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
    {
119
        $item = $this->createMock(AbstractPage::class);
120
        $item->method('getId')->willReturn(123);
121
122
        $this->object->buildItemActions();
123
        $actions = $this->object->getItemActions();
124
        $this->assertCount(1, $actions);
0 ignored issues
show
$actions is of type array<integer,object<Kun...n\ItemActionInterface>>, 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...
125
        $this->assertInstanceOf(SimpleItemAction::class, $actions[0]);
126
        /** @var SimpleItemAction $action */
127
        $action = $actions[0];
128
        $this->assertCount(2, $action->getUrlFor($item));
0 ignored issues
show
$action->getUrlFor($item) is of type string, 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...
129
    }
130
}
131