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\DoctrinePHPCRAdminBundle\Tests\Unit\Guesser; |
||
15 | |||
16 | use Doctrine\Bundle\PHPCRBundle\ManagerRegistry; |
||
17 | use Doctrine\Common\Persistence\Mapping\ClassMetadata; |
||
18 | use Doctrine\ODM\PHPCR\DocumentRepository; |
||
19 | use PHPUnit\Framework\TestCase; |
||
20 | use Sonata\DoctrinePHPCRAdminBundle\Filter\StringFilter; |
||
21 | use Sonata\DoctrinePHPCRAdminBundle\Guesser\FilterTypeGuesser; |
||
22 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
||
23 | use Symfony\Component\Form\Guess\Guess; |
||
24 | use Symfony\Component\Form\Guess\TypeGuess; |
||
25 | |||
26 | class FilterTypeGuesserTest extends TestCase |
||
27 | { |
||
28 | public function testGuessType(): void |
||
29 | { |
||
30 | $managerRegistry = $this->createMock(ManagerRegistry::class); |
||
31 | |||
32 | $documentRepository = $this->createMock(DocumentRepository::class); |
||
33 | |||
34 | $documentRepository->expects($this->once()) |
||
35 | ->method('getClassMetadata') |
||
36 | ->with($this->equalTo($class = 'Whatever')) |
||
37 | ->willReturn($this->createMock( |
||
38 | ClassMetadata::class |
||
39 | )); |
||
40 | |||
41 | $managerRegistry->expects($this->once()) |
||
42 | ->method('getManagers') |
||
43 | ->willReturn([$documentRepository]); |
||
44 | |||
45 | $guesser = new FilterTypeGuesser( |
||
46 | $managerRegistry |
||
0 ignored issues
–
show
|
|||
47 | ); |
||
48 | |||
49 | $typeGuess = $guesser->guessType($class, $fieldname = 'whatever', $this->createMock( |
||
0 ignored issues
–
show
$this->createMock('Sonat...ModelManagerInterface') is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Sonata\AdminBundl...\ModelManagerInterface> .
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...
|
|||
50 | 'Sonata\AdminBundle\Model\ModelManagerInterface' |
||
51 | )); |
||
52 | |||
53 | $this->assertInstanceOf( |
||
54 | TypeGuess::class, |
||
55 | $typeGuess |
||
56 | ); |
||
57 | $this->assertSame( |
||
58 | StringFilter::class, |
||
59 | $typeGuess->getType() |
||
60 | ); |
||
61 | $this->assertSame( |
||
62 | [ |
||
63 | 'field_type' => TextType::class, |
||
64 | 'field_options' => [], |
||
65 | 'options' => [], |
||
66 | 'field_name' => $fieldname, |
||
67 | ], |
||
68 | $typeGuess->getOptions() |
||
69 | ); |
||
70 | |||
71 | $this->assertSame( |
||
72 | Guess::LOW_CONFIDENCE, |
||
73 | $typeGuess->getConfidence() |
||
74 | ); |
||
75 | } |
||
76 | } |
||
77 |
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: