Completed
Push — master ( fcb59d...326ddf )
by Ruud
299:19 queued 288:03
created

testBuildFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\FormPageAdminListConfigurator;
11
use Kunstmaan\NodeBundle\Entity\AbstractPage;
12
use PHPUnit\Framework\TestCase;
13
14
/**
15
 * This test tests the FormPageAdminListConfigurator
16
 */
17
class FormPageAdminListConfiguratorTest extends TestCase
18
{
19
    const PERMISSION_VIEW = 'view';
20
21
    /**
22
     * @var FormPageAdminListConfigurator
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
    protected function setUp()
31
    {
32
        $em = $this->getMockedEntityManager();
33
        $tokenStorage = $this->createMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
0 ignored issues
show
Unused Code introduced by
$tokenStorage is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
        $roleHierarchy = $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface')
0 ignored issues
show
Unused Code introduced by
$roleHierarchy is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
          ->getMock();
36
        $aclHelper = $this->createMock('Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper');
37
38
        $this->object = new FormPageAdminListConfigurator($em, $aclHelper, self::PERMISSION_VIEW);
0 ignored issues
show
Documentation introduced by
$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...
Documentation introduced by
$aclHelper is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...Security\Acl\AclHelper>.

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...
39
    }
40
41
    /**
42
     * @return \Doctrine\ORM\EntityManager
0 ignored issues
show
Documentation introduced by
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...
43
     */
44 View Code Duplication
    protected function getMockedEntityManager()
0 ignored issues
show
Duplication introduced by
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...
45
    {
46
        $configuration = $this->createMock(Configuration::class);
47
        $configuration->method('getQuoteStrategy')->willReturn(null);
48
49
        $repository = $this->createMock(EntityRepository::class);
50
        $repository->method('find')->willReturn(null);
51
        $repository->method('findBy')->willReturn(null);
52
        $repository->method('findOneBy')->willReturn(null);
53
54
        $emMock = $this->createMock(EntityManager::class);
55
        $emMock->method('getRepository')->willReturn($repository);
56
        $emMock->method('getClassMetaData')->willReturn((object) ['name' => 'aClass']);
57
        $emMock->method('getConfiguration')->willReturn($configuration);
58
        $emMock->method('persist')->willReturn(null);
59
        $emMock->method('flush')->willReturn(null);
60
61
        return $emMock;
62
    }
63
64
    public function testAdaptQueryBuilder()
65
    {
66
        $queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
67
            ->disableOriginalConstructor()
68
            ->getMock();
69
70
        $queryBuilder->expects($this->once())
71
            ->method('innerJoin')
72
            ->will($this->returnSelf());
73
74
        $queryBuilder->expects($this->once())
75
            ->method('andWhere')
76
            ->will($this->returnSelf());
77
78
        /* @var QueryBuilder $queryBuilder */
79
        $this->object->adaptQueryBuilder($queryBuilder);
80
    }
81
82 View Code Duplication
    public function testFixedGetters()
0 ignored issues
show
Duplication introduced by
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...
83
    {
84
        $item = $this->createMock(AbstractPage::class);
85
        $item->method('getId')->willReturn(123);
86
87
        $this->assertEquals('', $this->object->getAddUrlFor([]));
88
        $this->assertEquals('KunstmaanNodeBundle', $this->object->getBundleName());
89
        $this->assertEquals('NodeTranslation', $this->object->getEntityName());
90
        $this->assertEquals('KunstmaanFormBundle:FormSubmissions', $this->object->getControllerPath());
91
        $this->assertCount(0, $this->object->getDeleteUrlFor($item));
0 ignored issues
show
Documentation introduced by
$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...
92
        $this->assertCount(1, $this->object->getIndexUrl());
0 ignored issues
show
Documentation introduced by
$this->object->getIndexUrl() is of type array<string,string,{"path":"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...
93
        $this->assertCount(2, $this->object->getEditUrlFor($item));
0 ignored issues
show
Documentation introduced by
$this->object->getEditUrlFor($item) is of type array<string,string|arra...nslationId\":\"?\"}>"}>, 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->assertFalse($this->object->canAdd());
95
        $this->assertFalse($this->object->canEdit($item));
96
        $this->assertFalse($this->object->canDelete($item));
97
    }
98
99
    public function testBuildFilters()
100
    {
101
        $this->object->buildFilters();
102
        $filters = $this->object->getFilterBuilder()->getFilterDefinitions();
103
        $this->assertCount(2, $filters);
0 ignored issues
show
Documentation introduced by
$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...
104
    }
105
106
    public function testBuildFields()
107
    {
108
        $this->object->buildFields();
109
        $fields = $this->object->getFields();
110
        $this->assertCount(3, $fields);
0 ignored issues
show
Documentation introduced by
$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...
111
    }
112
113 View Code Duplication
    public function testBuildItemActions()
0 ignored issues
show
Duplication introduced by
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...
114
    {
115
        $item = $this->createMock(AbstractPage::class);
116
        $item->method('getId')->willReturn(123);
117
118
        $this->object->buildItemActions();
119
        $actions = $this->object->getItemActions();
120
        $this->assertCount(1, $actions);
0 ignored issues
show
Documentation introduced by
$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...
121
        $this->assertInstanceOf(SimpleItemAction::class, $actions[0]);
122
        /** @var SimpleItemAction $action */
123
        $action = $actions[0];
124
        $this->assertCount(2, $action->getUrlFor($item));
0 ignored issues
show
Documentation introduced by
$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...
125
    }
126
}
127