-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
TagManagerTest.php
69 lines (52 loc) · 1.8 KB
/
TagManagerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\ClassificationBundle\Tests\Entity;
use Doctrine\ORM\EntityManagerInterface;
use Sonata\ClassificationBundle\Model\TagManagerInterface;
use Sonata\ClassificationBundle\Tests\App\Entity\Context;
use Sonata\ClassificationBundle\Tests\App\Entity\Tag;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
final class TagManagerTest extends KernelTestCase
{
public function testGetBySlug(): void
{
$this->prepareData();
$tag = $this->getTagManager()->getBySlug('tag', '1', false);
static::assertNotNull($tag);
}
public function testGetByContext(): void
{
$this->prepareData();
$tag = $this->getTagManager()->getByContext('1', false);
static::assertCount(1, $tag);
}
private function prepareData(): void
{
$manager = self::getContainer()->get('doctrine.orm.entity_manager');
\assert($manager instanceof EntityManagerInterface);
$context = new Context();
$context->setId('1');
$context->setName('contextA');
$collection = new Tag();
$collection->setName('tag');
$collection->setEnabled(false);
$collection->setContext($context);
$manager->persist($context);
$manager->persist($collection);
$manager->flush();
}
private function getTagManager(): TagManagerInterface
{
$tagManager = self::getContainer()->get('sonata.classification.manager.tag');
\assert($tagManager instanceof TagManagerInterface);
return $tagManager;
}
}