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

Tests/Service/ExportServiceTest.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\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'));
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));
45
        $obj->setTranslator($this->createMock(TranslatorInterface::class));
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());
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
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
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
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