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