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); |
||
0 ignored issues
–
show
|
|||
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')); |
||
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 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: