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\Bridge\Exporter; |
||
15 | |||
16 | use PHPUnit\Framework\TestCase; |
||
17 | use Sonata\AdminBundle\Admin\AdminInterface; |
||
18 | use Sonata\AdminBundle\Bridge\Exporter\AdminExporter; |
||
19 | use Sonata\Exporter\Exporter; |
||
20 | use Sonata\Exporter\Writer\TypedWriterInterface; |
||
21 | |||
22 | class AdminExporterTest extends TestCase |
||
23 | { |
||
24 | public function provideExportFormats() |
||
25 | { |
||
26 | return [ |
||
27 | 'no override' => [['xls'], ['json', 'xml', 'csv', 'xls'], ['xls']], |
||
28 | 'override in admin' => [['csv'], ['csv'], ['xls']], |
||
29 | ]; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @dataProvider provideExportFormats |
||
34 | */ |
||
35 | public function testAdminHasPriorityOverGlobalSettings(array $expectedFormats, array $adminFormats, array $globalFormats): void |
||
36 | { |
||
37 | $writers = []; |
||
38 | foreach ($globalFormats as $exportFormat) { |
||
39 | $writer = $this->createMock(TypedWriterInterface::class); |
||
40 | $writer->expects($this->once()) |
||
41 | ->method('getFormat') |
||
42 | ->will($this->returnValue($exportFormat)); |
||
43 | $writers[] = $writer; |
||
44 | } |
||
45 | |||
46 | $exporter = new Exporter($writers); |
||
47 | $admin = $this->createMock(AdminInterface::class); |
||
48 | $admin->expects($this->once()) |
||
49 | ->method('getExportFormats') |
||
50 | ->will($this->returnValue($adminFormats)); |
||
51 | $adminExporter = new AdminExporter($exporter); |
||
52 | $this->assertSame($expectedFormats, $adminExporter->getAvailableFormats($admin)); |
||
0 ignored issues
–
show
|
|||
53 | } |
||
54 | |||
55 | public function testGetExportFilename(): void |
||
56 | { |
||
57 | $admin = $this->createMock(AdminInterface::class); |
||
58 | $admin->expects($this->once()) |
||
59 | ->method('getClass') |
||
60 | ->will($this->returnValue('MyProject\AppBundle\Model\MyClass')); |
||
61 | $adminExporter = new AdminExporter(new Exporter()); |
||
62 | $this->assertRegexp( |
||
63 | '#export_myclass_\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2}.csv#', |
||
64 | $adminExporter->getExportFilename($admin, 'csv') |
||
0 ignored issues
–
show
$admin is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Sonata\AdminBundle\Admin\AdminInterface> .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
65 | ); |
||
66 | } |
||
67 | } |
||
68 |
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: