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\NewsBundle\Tests\DependencyInjection; |
||
15 | |||
16 | use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
||
17 | use Sonata\ClassificationBundle\Model\Collection; |
||
18 | use Sonata\ClassificationBundle\Model\Tag; |
||
19 | use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector; |
||
20 | use Sonata\MediaBundle\Model\Media; |
||
21 | use Sonata\NewsBundle\DependencyInjection\SonataNewsExtension; |
||
22 | use Sonata\NewsBundle\Model\Comment; |
||
23 | use Sonata\NewsBundle\Model\Post; |
||
24 | use Sonata\UserBundle\Model\User; |
||
25 | |||
26 | class SonataNewsExtensionTest extends AbstractExtensionTestCase |
||
27 | { |
||
28 | protected function setUp(): void |
||
29 | { |
||
30 | parent::setUp(); |
||
31 | $this->container->setParameter('kernel.bundles', []); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Test if the deprecation notice is triggered when the tag (or collection) class declaration is missing. |
||
36 | * It should trigger a deprecation notice but doesn't break anything |
||
37 | * You should have 0 association. |
||
38 | * |
||
39 | * @group legacy |
||
40 | * @expectedDeprecation The %s class is not defined or does not exist. This is tolerated now but will be forbidden in 4.0 |
||
41 | */ |
||
42 | public function testLoadWithoutTagWithoutCollection(): void |
||
43 | { |
||
44 | $this->load($this->getMinimalConfiguration()); |
||
45 | $collector = DoctrineCollector::getInstance(); |
||
46 | |||
47 | $this->assertEmpty($collector->getAssociations(), 'Our models should have 0 association'); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Test if the deprecation notice is triggered when the tag (or collection) class declaration is present. |
||
52 | * It shouldn't trigger a deprecation notice but doesn't break anything |
||
53 | * You should have 2 associations (Post, Comment). |
||
54 | * The Post model should have an association with (Media, User, Collection, Tag). |
||
55 | */ |
||
56 | public function testLoadWithTagWithCollection(): void |
||
57 | { |
||
58 | $this->load($this->getConfigurationWithTagWithCollection()); |
||
59 | $collector = DoctrineCollector::getInstance(); |
||
60 | $this->assertCount(2, $collector->getAssociations(), 'Our models should have 2 associations (post, comment)'); |
||
0 ignored issues
–
show
|
|||
61 | $postManyToOneAssociation = $collector->getAssociations()[Post::class]['mapManyToOne']; |
||
62 | $this->assertCount(3, $postManyToOneAssociation, 'The post model should have 3 many to one associations (user, media, collection)'); |
||
63 | $postManyToManyAssociation = $collector->getAssociations()[Post::class]['mapManyToMany']; |
||
64 | $this->assertCount(1, $postManyToManyAssociation, 'The post model should have 1 many to many association (tag)'); |
||
65 | $postOneToManyAssociation = $collector->getAssociations()[Post::class]['mapOneToMany']; |
||
66 | $this->assertCount(1, $postOneToManyAssociation, 'The post model should have 1 one to many association (comment)'); |
||
67 | } |
||
68 | |||
69 | protected function getMinimalConfiguration(): array |
||
70 | { |
||
71 | return [ |
||
72 | 'title' => 'Foo title', |
||
73 | 'link' => '/foo/bar', |
||
74 | 'description' => 'Foo description', |
||
75 | 'salt' => 'pepper', |
||
76 | 'comment' => [ |
||
77 | 'notification' => [ |
||
78 | 'emails' => ['[email protected]', '[email protected]'], |
||
79 | 'from' => '[email protected]', |
||
80 | 'template' => '@SonataNews/Mail/comment_notification.txt.twig', |
||
81 | ], |
||
82 | ], |
||
83 | 'class' => [ |
||
84 | 'post' => Post::class, |
||
85 | 'comment' => Comment::class, |
||
86 | 'media' => Media::class, |
||
87 | 'user' => User::class, |
||
88 | ], |
||
89 | ]; |
||
90 | } |
||
91 | |||
92 | protected function getConfigurationWithTagWithCollection(): array |
||
93 | { |
||
94 | $minimalConfiguration = $this->getMinimalConfiguration(); |
||
95 | $tagAndCollectionDeclaration = [ |
||
96 | 'class' => [ |
||
97 | 'collection' => Collection::class, |
||
98 | 'tag' => Tag::class, |
||
99 | ], |
||
100 | ]; |
||
101 | |||
102 | return array_merge($minimalConfiguration, $tagAndCollectionDeclaration); |
||
103 | } |
||
104 | |||
105 | protected function getContainerExtensions() |
||
106 | { |
||
107 | return [ |
||
108 | new SonataNewsExtension(), |
||
109 | ]; |
||
110 | } |
||
111 | } |
||
112 |
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: