|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Beelab\TagBundle\Tests\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Beelab\TagBundle\Tag\TagInterface; |
|
6
|
|
|
use Beelab\TagBundle\Tests\Entity; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @group unit |
|
11
|
|
|
*/ |
|
12
|
|
|
final class AbstractTaggableTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testHasTag(): void |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var TagInterface&\PHPUnit\Framework\MockObject\MockObject $tag */ |
|
17
|
|
|
$tag = $this->createMock(TagInterface::class); |
|
18
|
|
|
$entity = new Entity(); |
|
19
|
|
|
$entity->addTag($tag); |
|
20
|
|
|
$this->assertTrue($entity->hasTag($tag)); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testRemoveTag(): void |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var TagInterface&\PHPUnit\Framework\MockObject\MockObject $tag */ |
|
26
|
|
|
$tag = $this->createMock(TagInterface::class); |
|
27
|
|
|
$entity = new Entity(); |
|
28
|
|
|
$entity->addTag($tag); |
|
29
|
|
|
$entity->removeTag($tag); |
|
30
|
|
|
$this->assertFalse($entity->hasTag($tag)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testGetTags(): void |
|
34
|
|
|
{ |
|
35
|
|
|
/** @var TagInterface&\PHPUnit\Framework\MockObject\MockObject $tag */ |
|
36
|
|
|
$tag = $this->createMock(TagInterface::class); |
|
37
|
|
|
$entity = new Entity(); |
|
38
|
|
|
$entity->addTag($tag); |
|
39
|
|
|
$this->assertCount(1, $entity->getTags()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testGetTagsText(): void |
|
43
|
|
|
{ |
|
44
|
|
|
/** @var TagInterface&\PHPUnit\Framework\MockObject\MockObject $tag */ |
|
45
|
|
|
$tag = $this->createMock(TagInterface::class); |
|
|
|
|
|
|
46
|
|
|
$entity = new Entity(); |
|
47
|
|
|
$entity->setTagsText('foo, bar, baz'); |
|
48
|
|
|
$this->assertEquals('', $entity->getTagsText()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testGetTagNames(): void |
|
52
|
|
|
{ |
|
53
|
|
|
/** @var TagInterface&\PHPUnit\Framework\MockObject\MockObject $tag */ |
|
54
|
|
|
$tag = $this->createMock(TagInterface::class); |
|
|
|
|
|
|
55
|
|
|
$entity = new Entity(); |
|
56
|
|
|
$this->assertEquals([], $entity->getTagNames()); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|