Completed
Push — master ( 3cd231...d48ef1 )
by
unknown
153:58 queued 132:33
created

FormSubmissionAdminListConfiguratorTest.php (3 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\QueryBuilder;
6
use Kunstmaan\AdminListBundle\AdminList\ItemAction\SimpleItemAction;
7
use Kunstmaan\FormBundle\AdminList\FormSubmissionAdminListConfigurator;
8
use Kunstmaan\NodeBundle\Entity\Node;
9
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
10
use Kunstmaan\NodeBundle\Tests\Stubs\TestRepository;
11
use Kunstmaan\FormBundle\Tests\Stubs\TestConfiguration;
12
use Kunstmaan\FormBundle\Tests\Entity\FakePage;
13
14
/**
15
 * This test tests the FormPageAdminListConfigurator
16
 */
17
class FormSubmissionAdminListConfiguratorTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var FormSubmissionAdminListConfigurator
21
     */
22
    protected $object;
23
24
    /**
25
     * Sets up the fixture, for example, opens a network connection.
26
     * This method is called before a test is executed.
27
     */
28 View Code Duplication
    protected function setUp()
29
    {
30
        $em = $this->getMockedEntityManager();
31
        $node = new Node();
32
        $node->setId(666);
33
        $nt = new NodeTranslation();
34
        $nt->setNode($node);
35
        $this->object = new FormSubmissionAdminListConfigurator($em, $nt);
36
    }
37
38
    /**
39
     * https://gist.github.com/1331789
40
     *
41
     * @return \Doctrine\ORM\EntityManager
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
        $emMock  = $this->createMock('\Doctrine\ORM\EntityManager', array('getRepository', 'getConfiguration', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
46
        $emMock->expects($this->any())
47
            ->method('getRepository')
48
            ->will($this->returnValue(new TestRepository()));
49
        $emMock->expects($this->any())
50
            ->method('getConfiguration')
51
            ->will($this->returnValue(new TestConfiguration()));
52
        $emMock->expects($this->any())
53
            ->method('getClassMetadata')
54
            ->will($this->returnValue((object) array('name' => 'aClass')));
55
        $emMock->expects($this->any())
56
            ->method('persist')
57
            ->will($this->returnValue(null));
58
        $emMock->expects($this->any())
59
            ->method('flush')
60
            ->will($this->returnValue(null));
61
62
        return $emMock;  // it tooks 13 lines to achieve mock!
63
    }
64
65
    public function testAdaptQueryBuilder()
66
    {
67
        $queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder')
68
            ->disableOriginalConstructor()
69
            ->getMock();
70
71
        $queryBuilder->expects($this->any())
72
            ->method('innerJoin')
73
            ->will($this->returnSelf());
74
75
        $queryBuilder->expects($this->any())
76
            ->method('andWhere')
77
            ->will($this->returnSelf());
78
79
        $queryBuilder->expects($this->any())
80
            ->method('setParameter')
81
            ->will($this->returnSelf());
82
83
        /* @var $queryBuilder QueryBuilder */
84
        $this->object->adaptQueryBuilder($queryBuilder);
85
    }
86
87
88
89 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...
90
    {
91
        $item = new FakePage();
92
        $item->setId(123);
93
        $this->assertEquals('', $this->object->getAddUrlFor([]));
94
        $this->assertEquals('KunstmaanFormBundle', $this->object->getBundleName());
95
        $this->assertEquals('FormSubmission', $this->object->getEntityName());
96
        $this->assertCount(0, $this->object->getDeleteUrlFor($item));
97
        $this->assertCount(2, $this->object->getIndexUrl());
98
        $this->assertCount(2, $this->object->getEditUrlFor($item));
99
        $this->assertCount(2, $this->object->getExportUrl());
100
        $this->assertFalse($this->object->canAdd());
101
        $this->assertFalse($this->object->canEdit($item));
102
        $this->assertFalse($this->object->canDelete($item));
103
        $this->assertTrue($this->object->canExport());
104
    }
105
106
107
108
    public function testBuildFilters()
109
    {
110
        $this->object->buildFilters();
111
        $filters = $this->object->getFilterBuilder()->getFilterDefinitions();
112
        $this->assertCount(3, $filters);
113
    }
114
115
    public function testBuildFields()
116
    {
117
        $this->object->buildFields();
118
        $fields = $this->object->getFields();
119
        $this->assertCount(3, $fields);
120
    }
121
122 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...
123
    {
124
        $item = new FakePage();
125
        $item->setId(1);
126
        $this->object->buildItemActions();
127
        $actions = $this->object->getItemActions();
128
        $this->assertCount(1, $actions);
129
        $this->assertInstanceOf(SimpleItemAction::class, $actions[0]);
130
        /** @var SimpleItemAction $action */
131
        $action = $actions[0];
132
        $this->assertCount(2, $action->getUrlFor($item));
133
    }
134
}
135