Completed
Push — master ( 7e6070...203e38 )
by Gerrit
02:38
created

FailedRDMAssertionExceptionTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\Exception\FailedRDMAssertionException;
15
use ReflectionClass;
16
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
17
use Addiks\RDMBundle\Tests\Hydration\ServiceExample;
18
19
final class FailedRDMAssertionExceptionTest extends TestCase
20
{
21
22
    /**
23
     * @var FailedRDMAssertionException
24
     */
25
    private $exception;
26
27
    public function setUp()
28
    {
29
        $this->exception = new FailedRDMAssertionException("Some Message!", "some_type", [
30
            'lorem' => 'ipsum',
31
            'dolor' => 'sit'
32
        ]);
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function shouldStoreType()
39
    {
40
        $this->assertEquals("some_type", $this->exception->getType());
41
    }
42
43
    /**
44
     * @test
45
     */
46
    public function shouldStoreParameters()
47
    {
48
        $this->assertEquals([
49
            'lorem' => 'ipsum',
50
            'dolor' => 'sit'
51
        ], $this->exception->getParameters());
52
    }
53
54
    /**
55
     * @test
56
     */
57
    public function shouldCreateExpectedDifferentServiceException()
58
    {
59
        $reflectionClass = new ReflectionClass(EntityExample::class);
60
61
        $serviceA = new ServiceExample("lorem", 123);
62
        $serviceB = new ServiceExample("ipsum", 456);
63
64
        /** @var FailedRDMAssertionException $actualException */
65
        $actualException = FailedRDMAssertionException::expectedDifferentService(
66
            "some_service",
67
            $reflectionClass,
68
            $serviceA,
69
            $serviceB
70
        );
71
72
        $this->assertEquals(
73
            sprintf(
74
                "Expected service 'some_service' (%s#%s) on entity %s, was %s#%s instead!",
75
                ServiceExample::class,
76
                spl_object_hash($serviceA),
77
                EntityExample::class,
78
                ServiceExample::class,
79
                spl_object_hash($serviceB)
80
            ),
81
            $actualException->getMessage()
82
        );
83
    }
84
}
85