Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

Configurator/AbstractAdminListConfiguratorTest.php (2 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\AdminListBundle\Tests\AdminList\Configurator;
4
5
use DateTime;
6
use Exception;
7
use Kunstmaan\AdminBundle\Form\ColorType;
8
use Kunstmaan\AdminListBundle\AdminList\BulkAction\SimpleBulkAction;
9
use Kunstmaan\AdminListBundle\AdminList\ListAction\SimpleListAction;
10
use Kunstmaan\LeadGenerationBundle\Entity\Rule\LocaleBlacklistRule;
11
use Kunstmaan\LeadGenerationBundle\Form\Rule\LocaleBlackListAdminType;
12
use PHPUnit_Framework_TestCase;
13
use stdClass;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Session\Session;
16
use Kunstmaan\AdminListBundle\Tests\unit\Model\ConcreteConfigurator;
17
18
/**
19
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-13 at 16:18:47.
20
 */
21
class AbstractAdminListConfiguratorTest extends PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var ConcreteConfigurator
25
     */
26
    protected $object;
27
28
    /**
29
     * Sets up the fixture, for example, opens a network connection.
30
     * This method is called before a test is executed.
31
     */
32
    protected function setUp()
33
    {
34
35
        $session = $this->createMock(Session::class);
36
        $session->expects($this->any())->method('has')->willReturn(true);
37
        $session->expects($this->any())->method('get')->willReturn([
38
            'page' => 1,
39
            'orderBy' => 'id',
40
            'orderDirection' => 'ASC',
41
        ]);
42
        $request = new Request();
43
        $request->setSession($session);
44
        $request->query->add([
45
            '_route' => 'some-route',
46
        ]);
47
        $config = new ConcreteConfigurator();
48
        $config->bindRequest($request);
49
        $config->buildIterator();
50
        $this->object = $config;
51
    }
52
53
    public function testGetSet()
54
    {
55
        $config = $this->object;
56
57
        $config->setAdminTypeOptions(['test' => 123]);
58
        $config->setDeleteTemplate('delete.twig');
59
        $config->setEditTemplate('edit.twig');
60
        $config->setViewTemplate('view.twig');
61
        $config->setAddTemplate('add.twig');
62
        $config->setListTemplate('list.twig');
63
64
        $this->assertEquals('id', $config->getOrderBy());
65
        $this->assertEquals('ASC', $config->getOrderDirection());
66
        $this->assertEquals(1, $config->getPage());
67
        $this->assertEquals(10, $config->getLimit());
68
        $this->assertCount(1, $config->getAdminTypeOptions());
69
        $this->assertArrayHasKey('test', $config->getAdminTypeOptions());
70
        $viewUrl = $config->getViewUrlFor(['id' => 5]);
71
        $this->assertCount(2, $viewUrl);
72
        $this->assertArrayHasKey('path', $viewUrl);
73
        $this->assertArrayHasKey('params', $viewUrl);
74
        $this->assertArrayHasKey('id', $viewUrl['params']);
75
        $this->assertEquals('xyz:Xyz', $config->getControllerPath());
76
        $this->assertEquals(5, $viewUrl['params']['id']);
77
        $this->assertEquals('xyz_admin_xyz_view', $viewUrl['path']);
78
        $this->assertEquals('delete.twig', $config->getDeleteTemplate());
79
        $this->assertEquals('edit.twig', $config->getEditTemplate());
80
        $this->assertEquals('view.twig', $config->getViewTemplate());
81
        $this->assertEquals('add.twig', $config->getAddTemplate());
82
        $this->assertEquals('list.twig', $config->getListTemplate());
83
        $this->assertInstanceOf(DateTime::class, $config->decorateNewEntity(new DateTime()));
84
    }
85
86
    public function testGetAdminType()
87
    {
88
        $config = $this->object;
89
        $blackList = new LocaleBlacklistRule();
90
91
        $this->assertEquals(LocaleBlackListAdminType::class, $config->getAdminType($blackList));
92
93
        $this->setUp();
94
        $config = $this->object;
95
        $config->setAdminType(new ColorType());
0 ignored issues
show
new \Kunstmaan\AdminBundle\Form\ColorType() is of type object<Kunstmaan\AdminBundle\Form\ColorType>, but the function expects a string.

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->assertInstanceOf(ColorType::class, $config->getAdminType($blackList));
97
98
        $this->setUp();
99
        $this->expectException(Exception::class);
100
        $this->object->getAdminType(new stdClass());
101
    }
102
103 View Code Duplication
    public function testGetSetHasBulkAction()
104
    {
105
        $config = $this->object;
106
        $this->assertFalse($config->hasBulkActions());
107
        $config->addBulkAction(new SimpleBulkAction(['/url'], 'label'));
108
        $this->assertTrue($config->hasBulkActions());
109
        $this->assertCount(1, $config->getBulkActions());
110
        $this->assertInstanceOf(SimpleBulkAction::class, $config->getBulkActions()[0]);
111
    }
112
113 View Code Duplication
    public function testGetSetHasListAction()
114
    {
115
        $config = $this->object;
116
        $this->assertFalse($config->hasListActions());
117
        $config->addListAction(new SimpleListAction(['/url'], 'label'));
118
        $this->assertTrue($config->hasListActions());
119
        $this->assertCount(1, $config->getListActions());
120
        $this->assertInstanceOf(SimpleListAction::class, $config->getListActions()[0]);
121
    }
122
123
    public function testGetSetHasItemAction()
124
    {
125
        $config = $this->object;
126
        $this->assertFalse($config->hasItemActions());
127
        $config->addSimpleItemAction('x', 'y', 'z');
128
        $this->assertTrue($config->hasItemActions());
129
    }
130
131
    public function testSortFields()
132
    {
133
        $config = $this->object;
134
        $this->assertCount(0, $config->getSortFields());
135
        $config->addField('sort', 'blah', true);
0 ignored issues
show
true is of type boolean, but the function expects a string.

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...
136
        $this->assertCount(1, $config->getSortFields());
137
    }
138
139
    public function testExportFields()
140
    {
141
        $config = $this->object;
142
        $config->buildExportFields();
143
        $this->assertCount(0, $config->getExportFields());
144
        $config->addExportField('sort', 'blah', 'blah.twig');
145
        $this->assertCount(1, $config->getExportFields());
146
        $config->resetBuilds();
147
        $this->assertCount(0, $config->getExportFields());
148
    }
149
}
150