HydratorTest::testInvalidSubhydratorName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * apparat-resource
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Resource
8
 * @subpackage  Apparat\Resource\Tests
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation Fixture (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Resource\Tests;
38
39
use Apparat\Dev\Tests\AbstractTest;
40
use Apparat\Resource\Domain\Factory\HydratorFactory;
41
use Apparat\Resource\Domain\Model\Hydrator\HydratorInterface;
42
use Apparat\Resource\Domain\Model\Hydrator\InvalidArgumentException;
43
use Apparat\Resource\Infrastructure\Model\Hydrator\TextHydrator;
44
45
/**
46
 * Hydrator tests
47
 *
48
 * @package     Apparat\Resource
49
 * @subpackage  Apparat\Resource\Tests
50
 */
51
class HydratorTest extends AbstractTest
52
{
53
    /**
54
     * Test an invalid hydrator configuraton
55
     *
56
     * @expectedException InvalidArgumentException
57
     * @expectedExceptionCode 1447019565
58
     */
59
    public function testInvalidHydratorConfig()
60
    {
61
        HydratorFactory::build([]);
62
    }
63
64
    /**
65
     * Test an invalid hydrator content model configuraton
66
     *
67
     * @expectedException InvalidArgumentException
68
     * @expectedExceptionCode 1447020287
69
     */
70
    public function testInvalidHydratorContentModel()
71
    {
72
        HydratorFactory::build([[]]);
73
    }
74
75
    /**
76
     * Test an invalid subhydrator name
77
     *
78
     * @expectedException InvalidArgumentException
79
     * @expectedExceptionCode 1447364401
80
     */
81
    public function testInvalidSubhydratorName()
82
    {
83
        HydratorFactory::build([['~' => true]]);
84
    }
85
86
    /**
87
     * Test an invalid singlepart hydrator class
88
     *
89
     * @expectedException InvalidArgumentException
90
     * @expectedExceptionCode 1447110065
91
     */
92
    public function testInvalidSinglepartHydratorClass()
93
    {
94
        HydratorFactory::build([[HydratorInterface::STANDARD => \stdClass::class]]);
95
    }
96
97
    /**
98
     * Test the text hydrator (short form)
99
     */
100
    public function testTextHydratorShort()
101
    {
102
        $textHydrator = HydratorFactory::build([TextHydrator::class]);
103
        $this->assertInstanceOf(TextHydrator::class, $textHydrator);
104
    }
105
106
    /**
107
     * Test the text hydrator (verbose form)
108
     */
109
    public function testTextHydratorVerbose()
110
    {
111
        $textHydrator = HydratorFactory::build([[HydratorInterface::STANDARD => TextHydrator::class]]);
112
        $this->assertInstanceOf(TextHydrator::class, $textHydrator);
113
    }
114
115
    /**
116
     * Test the text hydrator name
117
     */
118
    public function testTextHydratorName()
119
    {
120
        $textHydrator = HydratorFactory::build([[HydratorInterface::STANDARD => TextHydrator::class]]);
121
        $this->assertEquals(HydratorInterface::STANDARD, $textHydrator->getName());
122
    }
123
}
124