SatisfiesCopyInterfaceTest::testCanSetCopy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Axstrad library.
5
 *
6
 * (c) Dan Kempster <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @copyright 2014-2015 Dan Kempster <[email protected]>
12
 */
13
14
namespace Axstrad\Component\Content\Tests\Functional;
15
16
use Axstrad\Component\Content\Copy;
17
use Axstrad\Component\Content\Entity;
18
use Axstrad\Component\Content\Exception\InvalidArgumentException;
19
use Axstrad\Component\Content\Model;
20
use Axstrad\Component\Content\Tests\Stubs\Traits\CopyBasedIntroductionTraitStub;
21
use Axstrad\Component\Content\Tests\Stubs\Traits\CopyTraitStub;
22
23
/**
24
 * Axstrad\Component\Content\Tests\Functional\SatisfiesCopyInterfaceTest
25
 *
26
 * @author Dan Kempster <[email protected]>
27
 * @license MIT
28
 * @package Axstrad/Content
29
 * @subpackage Tests
30
 * @group functional
31
 */
32
class SatisfiesCopyInterfaceTest extends \PHPUnit_Framework_TestCase
33
{
34
    public function fixtureProvider()
35
    {
36
        return array(
37
38
            // Traits
39
            [new CopyTraitStub()],
40
            [new CopyBasedIntroductionTraitStub()],
41
42
            // Model
43
            [new Model\Article],
44
            [new Model\ArticleIntroduction],
45
            [new Model\Copy],
46
47
            // Doctrine/ORM
48
            [new Entity\Copy],
49
            [new Entity\ArticleIntroduction()],
50
            [new Entity\Article()],
51
        );
52
    }
53
54
    public function classNameProvider()
55
    {
56
        return array(
57
            // Model
58
            ['Axstrad\Component\Content\Model\Copy'],
59
            ['Axstrad\Component\Content\Model\Article'],
60
61
            // Doctrine/ORM
62
            ['Axstrad\Component\Content\Entity\Copy'],
63
            ['Axstrad\Component\Content\Entity\Article'],
64
            ['Axstrad\Component\Content\Entity\ArticleIntroduction'],
65
        );
66
    }
67
68
    /**
69
     * @dataProvider classNameProvider
70
     * @param Copy $fixture
71
     */
72
    public function testImplementsCopyInterface($fixture)
73
    {
74
        $this->assertTrue(
75
            is_a($fixture, 'Axstrad\Component\Content\Copy', true),
76
            sprintf(
77
                '%s doesn\'t implement the %s interface',
78
                $fixture,
79
                'Axstrad\Component\Content\Copy'
80
            )
81
        );
82
    }
83
84
    /**
85
     * @dataProvider fixtureProvider
86
     * @param Copy $fixture
87
     */
88
    public function testCopyIsNullToStart($fixture)
89
    {
90
        $this->assertNull(
91
            $fixture->getCopy()
92
        );
93
    }
94
    /**
95
     * @dataProvider fixtureProvider
96
     * @param Copy $fixture
97
     */
98
    public function testCanSetCopy($fixture)
99
    {
100
        $fixture->setCopy('Some more copy.');
101
        $this->assertEquals(
102
            'Some more copy.',
103
            $fixture->getCopy()
104
        );
105
    }
106
107
    /**
108
     * @dataProvider fixtureProvider
109
     * @param Copy $fixture
110
     */
111
    public function testSetCopyReturnsSelf($fixture)
112
    {
113
        $this->assertSame(
114
            $fixture,
115
            $fixture->setCopy('foo')
116
        );
117
    }
118
119
    /**
120
     * @dataProvider fixtureProvider
121
     * @param Copy $fixture
122
     */
123
    public function testCopyIsTypeCastToString($fixture)
124
    {
125
        $fixture->setCopy(1.1);
126
        $this->assertSame(
127
            '1.1',
128
            $fixture->getCopy()
129
        );
130
    }
131
132
    /**
133
     * @dataProvider fixtureProvider
134
     * @param Copy $fixture
135
     */
136
    public function testCopyCanBeSetToNull($fixture)
137
    {
138
        $fixture->setCopy('My Copy');
139
        $fixture->setCopy(null);
140
        $this->assertNull(
141
            $fixture->getCopy()
142
        );
143
    }
144
145
    /**
146
     * @expectedException InvalidArgumentException
147
     * @dataProvider fixtureProvider
148
     * @param Copy $fixture
149
     */
150
    public function testSetCopyThrowsExceptionIfArgumentIsNotScalar($fixture)
151
    {
152
        $fixture->setCopy($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Axstrad\Component\C...sfiesCopyInterfaceTest>, but the function expects a null|string.

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...
153
    }
154
}
155