Completed
Pull Request — master (#19)
by
unknown
01:09
created

AbstractTaggableTest::testAddTag()   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
namespace Beelab\TagBundle\Tests\Entity;
4
5
use Beelab\TagBundle\Test\Entity;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * @group unit
10
 */
11
final class AbstractTaggableTest extends TestCase
12
{
13
    public function testAddTag(): void
14
    {
15
        $tag = $this->getMockBuilder('Beelab\TagBundle\Tag\TagInterface')->getMock();
16
        $entity = new Entity();
17
        $entity->addTag($tag);
0 ignored issues
show
Documentation introduced by
$tag is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Beelab\TagBundle\Tag\TagInterface>.

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...
18
        $this->assertTrue(in_array($tag, $entity->getTags()));
19
    }
20
21
    public function testRemoveTag(): void
22
    {
23
        $tag = $this->getMockBuilder('Beelab\TagBundle\Tag\TagInterface')->getMock();
24
        $entity = new Entity();
25
        $entity->addTag($tag);
0 ignored issues
show
Documentation introduced by
$tag is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Beelab\TagBundle\Tag\TagInterface>.

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...
26
        $entity->removeTag($tag);
0 ignored issues
show
Documentation introduced by
$tag is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Beelab\TagBundle\Tag\TagInterface>.

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...
27
        $this->assertFalse(in_array($tag, $entity->getTags()));
28
    }
29
30
    public function testGetTags(): void
31
    {
32
        $tag = $this->getMockBuilder('Beelab\TagBundle\Tag\TagInterface')->getMock();
33
        $entity = new Entity();
34
        $entity->addTag($tag);
0 ignored issues
show
Documentation introduced by
$tag is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Beelab\TagBundle\Tag\TagInterface>.

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...
35
        $this->assertCount(1, $entity->getTags());
36
    }
37
38
    public function testGetTagsText(): void
39
    {
40
        $tag = $this->getMockBuilder('Beelab\TagBundle\Tag\TagInterface')->getMock();
41
        $entity = new Entity();
42
        $entity->setTagsText('foo, bar, baz');
43
        $this->assertEquals('', $entity->getTagsText());
44
    }
45
46
    public function testGetTagNames(): void
47
    {
48
        $tag = $this->getMockBuilder('Beelab\TagBundle\Tag\TagInterface')->getMock();
49
        $entity = new Entity();
50
        $this->assertEquals([], $entity->getTagNames());
51
    }
52
}
53