Completed
Pull Request — master (#6194)
by Vincent
05:04
created

ExporterTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFilter() 0 9 1
A testGetResponse() 0 19 2
A getGetResponseTests() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Export;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Export\Exporter;
18
use Sonata\CoreBundle\Exporter\Exporter as CoreExporter;
19
use Sonata\Exporter\Source\ArraySourceIterator;
20
use Sonata\Exporter\Source\SourceIteratorInterface;
21
use Symfony\Component\HttpFoundation\Response;
22
23
/**
24
 * NEXT_MAJOR: remove this class.
25
 *
26
 * @group legacy
27
 */
28
class ExporterTest extends TestCase
29
{
30
    public function testFilter(): void
31
    {
32
        $this->expectException(\RuntimeException::class);
33
34
        $source = $this->createMock(SourceIteratorInterface::class);
35
36
        $exporter = new Exporter();
0 ignored issues
show
Deprecated Code introduced by
The class Sonata\AdminBundle\Export\Exporter has been deprecated with message: since sonata-project/admin-bundle 3.14, to be removed in 4.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
37
        $exporter->getResponse('foo', 'foo', $source);
38
    }
39
40
    /**
41
     * @dataProvider getGetResponseTests
42
     */
43
    public function testGetResponse(string $format, string $filename, string $contentType): void
44
    {
45
        if (!class_exists(CoreExporter::class)) {
46
            $this->markTestSkipped('Not test Exporter from removed SonataCoreBundle.');
47
        }
48
49
        $this->markTestSkipped();
50
        $source = new ArraySourceIterator([
51
            ['foo' => 'bar'],
52
        ]);
53
54
        $exporter = new Exporter();
0 ignored issues
show
Deprecated Code introduced by
The class Sonata\AdminBundle\Export\Exporter has been deprecated with message: since sonata-project/admin-bundle 3.14, to be removed in 4.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
55
        $response = $exporter->getResponse($format, $filename, $source);
56
57
        $this->assertInstanceOf(Response::class, $response);
58
        $this->assertSame($contentType, $response->headers->get('Content-Type'));
59
        // Quotes does not appear on some sonata versions.
60
        $this->assertRegExp(sprintf('/attachment; filename="?%s"?/', $filename), $response->headers->get('Content-Disposition'));
61
    }
62
63
    public function getGetResponseTests()
64
    {
65
        return [
66
            ['json', 'foo.json', 'application/json'],
67
            ['xml', 'foo.xml', 'text/xml'],
68
            ['xls', 'foo.xls', 'application/vnd.ms-excel'],
69
            ['csv', 'foo.csv', 'text/csv'],
70
        ];
71
    }
72
}
73