Completed
Push — master ( f7d484...5c67d5 )
by Vincent
18s queued 12s
created

testLoadWithoutTagWithoutCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Doctrine\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\NewsBundle\Tests\Fixtures\UserMock;
25
26
class SonataNewsExtensionTest extends AbstractExtensionTestCase
27
{
28
    protected function setUp(): void
29
    {
30
        parent::setUp();
31
        $this->container->setParameter('kernel.bundles', ['SonataDoctrineBundle' => true]);
32
    }
33
34
    public function testLoadWithTagWithCollection(): void
35
    {
36
        $this->load($this->getConfigurationWithTagWithCollection());
37
        $collector = DoctrineCollector::getInstance();
38
        $this->assertCount(2, $collector->getAssociations(), 'Our models should have 2 associations (post, comment)');
39
        $postManyToOneAssociation = $collector->getAssociations()[Post::class]['mapManyToOne'];
40
        $this->assertCount(3, $postManyToOneAssociation, 'The post model should have 3 many to one associations (user, media, collection)');
41
        $postManyToManyAssociation = $collector->getAssociations()[Post::class]['mapManyToMany'];
42
        $this->assertCount(1, $postManyToManyAssociation, 'The post model should have 1 many to many association (tag)');
43
        $postOneToManyAssociation = $collector->getAssociations()[Post::class]['mapOneToMany'];
44
        $this->assertCount(1, $postOneToManyAssociation, 'The post model should have 1 one to many association (comment)');
45
    }
46
47
    protected function getConfigurationWithTagWithCollection(): array
48
    {
49
        return [
50
            'title' => 'Foo title',
51
            'link' => '/foo/bar',
52
            'description' => 'Foo description',
53
            'salt' => 'pepper',
54
            'comment' => [
55
                'notification' => [
56
                    'emails' => ['[email protected]', '[email protected]'],
57
                    'from' => '[email protected]',
58
                    'template' => '@SonataNews/Mail/comment_notification.txt.twig',
59
                ],
60
            ],
61
            'class' => [
62
                'post' => Post::class,
63
                'comment' => Comment::class,
64
                'media' => Media::class,
65
                'user' => UserMock::class,
66
                'collection' => Collection::class,
67
                'tag' => Tag::class,
68
            ],
69
        ];
70
    }
71
72
    protected function getContainerExtensions(): array
73
    {
74
        return [
75
            new SonataNewsExtension(),
76
        ];
77
    }
78
}
79