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\Form\ChoiceList; |
||
15 | |||
16 | use PHPUnit\Framework\TestCase; |
||
17 | use Sonata\AdminBundle\Form\ChoiceList\ModelChoiceLoader; |
||
18 | use Sonata\AdminBundle\Model\ModelManagerInterface; |
||
19 | use Sonata\AdminBundle\Tests\Fixtures\Bundle\Entity\Foo; |
||
20 | |||
21 | class ModelChoiceLoaderTest extends TestCase |
||
22 | { |
||
23 | private $modelManager = null; |
||
24 | |||
25 | public function setUp(): void |
||
26 | { |
||
27 | $this->modelManager = $this->getMockForAbstractClass(ModelManagerInterface::class); |
||
28 | } |
||
29 | |||
30 | public function testLoadFromEntityWithSamePropertyValues(): void |
||
31 | { |
||
32 | $fooA = new Foo(); |
||
33 | $fooA->setBar(1); |
||
34 | $fooA->setBaz('baz'); |
||
35 | |||
36 | $fooB = new Foo(); |
||
37 | $fooB->setBar(2); |
||
38 | $fooB->setBaz('baz'); |
||
39 | |||
40 | $this->modelManager->expects($this->once()) |
||
41 | ->method('findBy') |
||
42 | ->will($this->returnValue([$fooA, $fooB])); |
||
43 | |||
44 | $this->modelManager->expects($this->any()) |
||
45 | ->method('getIdentifierValues') |
||
46 | ->will($this->returnCallback(function (Foo $foo) { |
||
47 | return [$foo->getBar()]; |
||
48 | })); |
||
49 | |||
50 | $modelChoiceLoader = new ModelChoiceLoader( |
||
51 | $this->modelManager, |
||
0 ignored issues
–
show
|
|||
52 | \Sonata\AdminBundle\Tests\Fixtures\Entity\Foo::class, |
||
53 | 'baz' |
||
54 | ); |
||
55 | |||
56 | $expectedChoices = [ |
||
57 | 1 => 'baz (id: 1)', |
||
58 | 2 => 'baz (id: 2)', |
||
59 | ]; |
||
60 | |||
61 | $this->assertSame($expectedChoices, $modelChoiceLoader->loadChoiceList()->getOriginalKeys()); |
||
62 | } |
||
63 | } |
||
64 |
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: