Completed
Push — 3.x ( e95e95...638cd1 )
by Oskar
05:54
created

tests/Export/ExporterTest.php (1 issue)

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\Filter;
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();
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();
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'));
0 ignored issues
show
It seems like $response->headers->get('Content-Disposition') targeting Symfony\Component\HttpFoundation\HeaderBag::get() can also be of type array<integer,string> or null; however, PHPUnit\Framework\Assert::assertRegExp() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
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