Completed
Push — master ( f093c4...60435d )
by Richard van
02:59 queued 46s
created

ProfiledNameFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 103
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testProfiledNamesFactory() 0 7 1
A getProfiledNames() 0 49 1
A testInvalidObjectProfiledName() 0 6 1
A testInvalidArrayProfiledName() 0 6 1
A testInvalidStringProfiledName() 0 6 1
1
<?php
2
3
/**
4
 * micrometa
5
 *
6
 * @category   Jkphl
7
 * @package    Jkphl\Micrometa
8
 * @subpackage Jkphl\Micrometa\Tests\Domain
9
 * @author     Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright  Copyright © 2018 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 © 2018 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 files (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 Jkphl\Micrometa\Tests\Infrastructure;
38
39
use Jkphl\Micrometa\Infrastructure\Factory\MicroformatsFactory;
40
use Jkphl\Micrometa\Infrastructure\Factory\ProfiledNamesFactory;
41
use Jkphl\Micrometa\Infrastructure\Parser\ProfiledNamesList;
42
use Jkphl\Micrometa\Tests\AbstractTestBase;
43
44
/**
45
 * Profiled name factory tests
46
 *
47
 * @package    Jkphl\Micrometa
48
 * @subpackage Jkphl\Micrometa\Tests
49
 */
50
class ProfiledNameFactoryTest extends AbstractTestBase
51
{
52
    /**
53
     * Test the profiled name factory
54
     *
55
     * @param array $args     Arguments
56
     * @param array $expected Expected profiled names
57
     *
58
     * @dataProvider getProfiledNames
59
     */
60
    public function testProfiledNamesFactory(array $args, array $expected)
61
    {
62
        /** @var ProfiledNamesList $profiledNamesList */
63
        $profiledNamesList = ProfiledNamesFactory::createFromArguments($args);
64
        $this->assertInstanceOf(ProfiledNamesList::class, $profiledNamesList);
65
        $this->assertEquals($expected, $profiledNamesList->getArrayCopy());
66
    }
67
68
    /**
69
     * Get profiled name test data
70
     *
71
     * @return array[]
72
     */
73
    public function getProfiledNames()
74
    {
75
        $schemaOrgProfile = 'http://schema.org/';
76
        $feedObject       = (object)['name' => 'h-feed', 'profile' => MicroformatsFactory::MF2_PROFILE_URI];
77
        $eventObject      = (object)['name' => 'Event', 'profile' => $schemaOrgProfile];
78
79
        return [
80
            [
81
                ['h-feed'],
82
                [(object)['name' => 'h-feed', 'profile' => null]],
83
            ],
84
            [
85
                ['h-feed', MicroformatsFactory::MF2_PROFILE_URI],
86
                [$feedObject],
87
            ],
88
            [
89
                [['h-feed', MicroformatsFactory::MF2_PROFILE_URI]],
90
                [$feedObject],
91
            ],
92
            [
93
                [['name' => 'h-feed', 'profile' => MicroformatsFactory::MF2_PROFILE_URI]],
94
                [$feedObject],
95
            ],
96
            [
97
                [$feedObject],
98
                [$feedObject],
99
            ],
100
            [
101
                [$feedObject, 'h-feed'],
102
                [$feedObject, $feedObject],
103
            ],
104
            [
105
                [$feedObject, $eventObject],
106
                [$feedObject, $eventObject],
107
            ],
108
            [
109
                [$feedObject, $eventObject, 'Person'],
110
                [$feedObject, $eventObject, (object)['name' => 'Person', 'profile' => $schemaOrgProfile]],
111
            ],
112
            [
113
                ['h-feed', MicroformatsFactory::MF2_PROFILE_URI, $eventObject],
114
                [$feedObject, $eventObject],
115
            ],
116
            [
117
                ['h-feed', $eventObject],
118
                [(object)['name' => 'h-feed', 'profile' => null], $eventObject],
119
            ],
120
        ];
121
    }
122
123
    /**
124
     * Test an invalid profiled name object
125
     */
126
    public function testInvalidObjectProfiledName()
127
    {
128
        $this->expectException('Jkphl\Micrometa\Ports\Exceptions\InvalidArgumentException');
129
        $this->expectExceptionCode('1489528854');
130
        ProfiledNamesFactory::createFromArguments([(object)['missing' => 'name']]);
131
    }
132
133
    /**
134
     * Test an invalid profiled name array
135
     */
136
    public function testInvalidArrayProfiledName()
137
    {
138
        $this->expectException('Jkphl\Micrometa\Ports\Exceptions\InvalidArgumentException');
139
        $this->expectExceptionCode('1491063221');
140
        ProfiledNamesFactory::createFromArguments([['invalid' => 'array']]);
141
    }
142
143
    /**
144
     * Test an invalid profiled name sting
145
     */
146
    public function testInvalidStringProfiledName()
147
    {
148
        $this->expectException('Jkphl\Micrometa\Ports\Exceptions\InvalidArgumentException');
149
        $this->expectExceptionCode('1489528854');
150
        ProfiledNamesFactory::createFromArguments(['']);
151
    }
152
}
153