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\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
|
|||
34 | $roleHierarchy = $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface') |
||
35 | ->getMock(); |
||
36 | $aclHelper = $this->createMock('Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper'); |
||
37 | |||
38 | $this->object = new FormPageAdminListConfigurator($em, $aclHelper, self::PERMISSION_VIEW); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @return \Doctrine\ORM\EntityManager |
||
43 | */ |
||
44 | View Code Duplication | protected function getMockedEntityManager() |
|
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() |
|
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)); |
||
92 | $this->assertCount(1, $this->object->getIndexUrl()); |
||
93 | $this->assertCount(2, $this->object->getEditUrlFor($item)); |
||
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); |
||
104 | } |
||
105 | |||
106 | public function testBuildFields() |
||
107 | { |
||
108 | $this->object->buildFields(); |
||
109 | $fields = $this->object->getFields(); |
||
110 | $this->assertCount(3, $fields); |
||
111 | } |
||
112 | |||
113 | View Code Duplication | public function testBuildItemActions() |
|
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); |
||
121 | $this->assertInstanceOf(SimpleItemAction::class, $actions[0]); |
||
122 | /** @var SimpleItemAction $action */ |
||
123 | $action = $actions[0]; |
||
124 | $this->assertCount(2, $action->getUrlFor($item)); |
||
125 | } |
||
126 | } |
||
127 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.