Completed
Push — 3.x ( ba2f7c...5aa95f )
by Grégoire
02:57
created

tests/Export/ExporterTest.php (2 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
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('/attachment; filename="?'.$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