Completed
Push — 3.x ( f37b5a...b37d45 )
by Christian
26:43
created

ExporterTest::testGetResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 3
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\Exporter\Source\ArraySourceIterator;
19
use Sonata\Exporter\Source\SourceIteratorInterface;
20
use Symfony\Component\HttpFoundation\Response;
21
22
/**
23
 * NEXT_MAJOR: remove this class.
24
 *
25
 * @group legacy
26
 */
27
class ExporterTest extends TestCase
28
{
29
    public function testFilter(): void
30
    {
31
        $this->expectException(\RuntimeException::class);
32
33
        $source = $this->createMock(SourceIteratorInterface::class);
34
35
        $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...
36
        $exporter->getResponse('foo', 'foo', $source);
37
    }
38
39
    /**
40
     * @dataProvider getGetResponseTests
41
     */
42
    public function testGetResponse($format, $filename, $contentType): void
43
    {
44
        $source = new ArraySourceIterator([
45
            ['foo' => 'bar'],
46
        ]);
47
48
        $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...
49
        $response = $exporter->getResponse($format, $filename, $source);
50
51
        $this->assertInstanceOf(Response::class, $response);
52
        $this->assertSame($contentType, $response->headers->get('Content-Type'));
53
        // Quotes does not appear on some sonata versions.
54
        $this->assertRegExp('/attachment; filename="?'.$filename.'"?/', $response->headers->get('Content-Disposition'));
55
    }
56
57
    public function getGetResponseTests()
58
    {
59
        return [
60
            ['json', 'foo.json', 'application/json'],
61
            ['xml', 'foo.xml', 'text/xml'],
62
            ['xls', 'foo.xls', 'application/vnd.ms-excel'],
63
            ['csv', 'foo.csv', 'text/csv'],
64
        ];
65
    }
66
}
67