Completed
Push — master ( 1dc6e5...73a7e8 )
by Jeroen
07:06 queued 20s
created

ExportListTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testConstructor() 0 10 1
A testGetExportColumns() 0 4 1
A testGetIterator() 0 4 1
A testGetStringValue() 0 5 1
1
<?php
2
3
namespace Kunstmaan\AdminListBundle\Tests\AdminList;
4
5
use Kunstmaan\AdminListBundle\AdminList\Configurator\AdminListConfiguratorInterface;
6
use Kunstmaan\AdminListBundle\AdminList\Configurator\ExportListConfiguratorInterface;
7
use Kunstmaan\AdminListBundle\AdminList\ExportList;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Class ExportListTest
12
 */
13
class ExportListTest extends TestCase
14
{
15
    /** @var ExportList */
16
    protected $exportList;
17
18
    public function setUp()
19
    {
20
        /** @var AdminListConfiguratorInterface */
21
        $configurator = $this->createMock(ExportListConfiguratorInterface::class);
22
        $configurator->method('getExportFields')->willReturn(['c', 'd']);
23
        $configurator->method('getIterator')->willReturn($this->createMock(\Iterator::class));
24
        $configurator->method('getStringValue')->willReturn('stringtest');
25
26
        $this->exportList = new ExportList($configurator);
0 ignored issues
show
Documentation introduced by
$configurator is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminLi...tConfiguratorInterface>.

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...
27
    }
28
29
    public function testConstructor()
30
    {
31
        $configurator = $this->createMock(ExportListConfiguratorInterface::class);
32
33
        $configurator->expects($this->once())->method('buildFilters');
34
        $configurator->expects($this->once())->method('buildExportFields');
35
        $configurator->expects($this->once())->method('buildIterator');
36
37
        new ExportList($configurator);
0 ignored issues
show
Documentation introduced by
$configurator is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminLi...tConfiguratorInterface>.

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...
38
    }
39
40
    public function testGetExportColumns()
41
    {
42
        $this->assertContains('c', $this->exportList->getExportColumns());
43
    }
44
45
    public function testGetIterator()
46
    {
47
        $this->assertInstanceOf(\Iterator::class, $this->exportList->getIterator());
48
    }
49
50
    public function testGetStringValue()
51
    {
52
        $object = new \stdClass();
53
        $this->assertEquals('stringtest', $this->exportList->getStringValue($object, 'test'));
54
    }
55
}
56