Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

ExportServiceTest::testGetSupportedExtensions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\AdminListBundle\Tests\Service;
4
5
use Box\Spout\Common\Type;
6
use Kunstmaan\AdminListBundle\AdminList\ExportableInterface;
7
use Kunstmaan\AdminListBundle\Service\ExportService;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
10
use Symfony\Component\Translation\Translator;
11
use Symfony\Component\Translation\TranslatorInterface;
12
use Twig\Environment;
13
14
class ExportServiceTest extends TestCase
15
{
16
    /**
17
     * @var ExportService
18
     */
19
    protected $object;
20
21
    protected function setUp()
22
    {
23
        $this->object = new ExportService($this->createMock(Environment::class), new Translator('nl'));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Twig\Environment::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Twig\Environment>.

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...
24
    }
25
26
    /**
27
     * @group legacy
28
     * @expectedDeprecation Not passing the Twig service as the first argument of "Kunstmaan\AdminListBundle\Service\ExportService::__construct" is deprecated since KunstmaanAdminListBundle 5.4 and will be required in KunstmaanAdminListBundle 6.0. Injected the required services in the constructor instead.
29
     */
30
    public function testWithoutConstructorInjection()
31
    {
32
        new ExportService();
33
    }
34
35
    /**
36
     * @group legacy
37
     * @expectedDeprecation Not passing the Twig service as the first argument of "Kunstmaan\AdminListBundle\Service\ExportService::__construct" is deprecated since KunstmaanAdminListBundle 5.4 and will be required in KunstmaanAdminListBundle 6.0. Injected the required services in the constructor instead.
38
     * @expectedDeprecation Injecting the template renderer with "Kunstmaan\AdminListBundle\Service\ExportService::setRenderer" is deprecated since KunstmaanAdminListBundle 5.4 and will be removed in KunstmaanAdminListBundle 6.0. Inject Twig with constructor injection instead.
39
     * @expectedDeprecation Injecting the translator with "Kunstmaan\AdminListBundle\Service\ExportService::setTranslator" is deprecated since KunstmaanAdminListBundle 5.4 and will be removed in KunstmaanAdminListBundle 6.0. Inject the Translator with constructor injection instead.
40
     */
41
    public function testDeprecatedSetters()
42
    {
43
        $obj = new ExportService();
44
        $obj->setRenderer($this->createMock(EngineInterface::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Symfo...EngineInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Bundle\Fr...lating\EngineInterface>.

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...
Deprecated Code introduced by
The method Kunstmaan\AdminListBundl...tService::setRenderer() has been deprecated with message: Setter injection is deprecation since KunstmaanAdminListBundle 5.4 and will be removed in KunstmaanAdminListBundle 6.0. Use constructor injection instead.

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...
45
        $obj->setTranslator($this->createMock(TranslatorInterface::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Symfo...slatorInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Translation\Translator>.

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...
Deprecated Code introduced by
The method Kunstmaan\AdminListBundl...ervice::setTranslator() has been deprecated with message: Setter injection is deprecation since KunstmaanAdminListBundle 5.4 and will be removed in KunstmaanAdminListBundle 6.0. Use constructor injection instead.

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...
46
    }
47
48
    public function testConstructorInvalidTranslatorlass()
49
    {
50
        $this->expectException(\InvalidArgumentException::class);
51
        $this->expectExceptionMessage('Argument 2 passed to "Kunstmaan\AdminListBundle\Service\ExportService::__construct" must be of the type "Symfony\Component\Translation\TranslatorInterface" or "Symfony\Contracts\Translation\TranslatorInterface", "stdClass" given');
52
53
        new ExportService($this->createMock(Environment::class), new \stdClass());
0 ignored issues
show
Documentation introduced by
$this->createMock(\Twig\Environment::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Twig\Environment>.

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...
54
    }
55
56
    public function testGetSupportedExtensions()
57
    {
58
        $extensions = ExportService::getSupportedExtensions();
59
        $this->assertEquals(['Csv' => 'csv', 'Ods' => 'ods', 'Excel' => 'xlsx'], $extensions);
60
    }
61
62 View Code Duplication
    public function testGetDownloadableResponseReturnsStreamedResponseWithExcel()
0 ignored issues
show
Duplication introduced by
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...
63
    {
64
        /** @var ExportableInterface $adminList */
65
        $adminList = $this->createMock('Kunstmaan\AdminListBundle\AdminList\ExportableInterface');
66
67
        $response = $this->object->getDownloadableResponse($adminList, Type::XLSX);
68
69
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
70
    }
71
72 View Code Duplication
    public function testGetDownloadableResponseReturnsStreamedResponseWithOds()
0 ignored issues
show
Duplication introduced by
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...
73
    {
74
        /** @var ExportableInterface $adminList */
75
        $adminList = $this->createMock('Kunstmaan\AdminListBundle\AdminList\ExportableInterface');
76
77
        $response = $this->object->getDownloadableResponse($adminList, Type::ODS);
78
79
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
80
    }
81
82 View Code Duplication
    public function testGetDownloadableResponseReturnsStreamedResponseWithCsv()
0 ignored issues
show
Duplication introduced by
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...
83
    {
84
        /** @var ExportableInterface $adminList */
85
        $adminList = $this->createMock('Kunstmaan\AdminListBundle\AdminList\ExportableInterface');
86
87
        $response = $this->object->getDownloadableResponse($adminList, Type::CSV);
88
89
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\StreamedResponse', $response);
90
    }
91
}
92