Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Tests/unit/AdminList/ExportListTest.php (1 issue)

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;
4
5
use ArrayIterator;
6
use Doctrine\ORM\AbstractQuery;
7
use Doctrine\ORM\EntityManager;
8
use Doctrine\ORM\QueryBuilder;
9
use Iterator;
10
use Kunstmaan\AdminListBundle\AdminList\Configurator\AbstractAdminListConfigurator;
11
use Kunstmaan\AdminListBundle\AdminList\ExportList;
12
use Kunstmaan\AdminListBundle\AdminList\Field;
13
use Kunstmaan\FormBundle\AdminList\FormSubmissionExportListConfigurator;
14
use Kunstmaan\FormBundle\Entity\FormSubmission;
15
use Kunstmaan\NodeBundle\Entity\Node;
16
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
17
use Kunstmaan\TranslatorBundle\Service\Translator\Translator;
18
use PHPUnit\Framework\TestCase;
19
use ReflectionClass;
20
use Symfony\Component\HttpFoundation\Request;
21
22
class ExportListTest extends TestCase
23
{
24
    /**
25
     * @var ExportList
26
     */
27
    protected $object;
28
29
    /**
30
     * @var \PHPUnit_Framework_MockObject_MockObject
31
     */
32
    protected $configurator;
33
34
    /**
35
     * Sets up the fixture, for example, opens a network connection.
36
     * This method is called before a test is executed.
37
     */
38
    protected function setUp()
39
    {
40
        $query = $this->createMock(AbstractQuery::class);
41
        $query->expects($this->once())->method('iterate')->willReturn(new ArrayIterator([[new FormSubmission()]]));
42
43
        $qb = $this->createMock(QueryBuilder::class);
44
        $qb->expects($this->any())->method('select')->willReturn($qb);
45
        $qb->expects($this->any())->method('from')->willReturn($qb);
46
        $qb->expects($this->any())->method('innerJoin')->willReturn($qb);
47
        $qb->expects($this->any())->method('andWhere')->willReturn($qb);
48
        $qb->expects($this->any())->method('setParameter')->willReturn($qb);
49
        $qb->expects($this->any())->method('addOrderBy')->willReturn($qb);
50
        $qb->expects($this->any())->method('getQuery')->willReturn($query);
51
52
        $em = $this->createMock(EntityManager::class);
53
        $em->expects($this->once())->method('createQueryBuilder')->willReturn($qb);
54
55
        $node = new Node();
56
        $node->setId(666);
57
        $nodeTranslation = $this->createMock(NodeTranslation::class);
58
        $nodeTranslation->expects($this->any())->method('getNode')->willReturn($node);
59
        $nodeTranslation->expects($this->any())->method('getLang')->willReturn('nl');
60
        $translator = $this->createMock(Translator::class);
61
62
        $this->configurator = new FormSubmissionExportListConfigurator($em, $nodeTranslation, $translator); //$this->createMock('Kunstmaan\AdminListBundle\AdminList\Configurator\ExportListConfiguratorInterface');
63
64
        $this->object = new ExportList($this->configurator);
65
    }
66
67
    public function testGetExportColumns()
68
    {
69
        $columns = $this->object->getExportColumns();
70
        $this->assertCount(3, $columns);
71
        $this->assertInstanceOf(Field::class, $columns[0]);
72
        $this->assertInstanceOf(Field::class, $columns[1]);
73
        $this->assertInstanceOf(Field::class, $columns[2]);
74
    }
75
76
    public function testGetIterator()
77
    {
78
        $this->assertInstanceOf(Iterator::class, $this->object->getIterator());
79
    }
80
81
    public function testGetStringValue()
82
    {
83
        $item = array('id' => 1);
84
85
        $this->assertEquals(1, $this->object->getStringValue($item, 'id'));
86
    }
87
88
    /**
89
     * @throws \ReflectionException
90
     */
91
    public function testBindRequest()
92
    {
93
        $configurator = $this->createMock(AbstractAdminListConfigurator::class);
94
        $configurator->expects($this->once())->method('bindRequest')->willReturn(true);
95
        $mirror = new ReflectionClass(ExportList::class);
96
        $property = $mirror->getProperty('configurator');
97
        $property->setAccessible(true);
98
        $property->setValue($this->object, $configurator);
99
        $this->object->bindRequest(new Request());
0 ignored issues
show
Deprecated Code introduced by
The method Kunstmaan\AdminListBundl...portList::bindRequest() has been deprecated with message: ? This method is not configured in the configurator interface

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
100
    }
101
}
102