Completed
Push — v2 ( 88b419...d5d6a3 )
by Joschi
05:06
created

ItemTest::getFeedItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 70
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 42
nc 1
nop 0
dl 0
loc 70
rs 9.1724
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * micrometa
5
 *
6
 * @category Jkphl
7
 * @package Jkphl\Micrometa
8
 * @subpackage Infrastructure
9
 * @author Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright Copyright © 2017 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 © 2017 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\Ports;
38
39
use Jkphl\Micrometa\Application\Item\Item as ApplicationItem;
40
use Jkphl\Micrometa\Application\Value\StringValue;
41
use Jkphl\Micrometa\Infrastructure\Factory\MicroformatsFactory;
42
use Jkphl\Micrometa\Infrastructure\Parser\Microformats;
43
use Jkphl\Micrometa\Ports\Item\Item;
44
45
/**
46
 * Parser factory tests
47
 *
48
 * @package Jkphl\Micrometa
49
 * @subpackage Jkphl\Micrometa\Tests
50
 */
51
class ItemTest extends \PHPUnit_Framework_TestCase
52
{
53
    /**
54
     * Test an item
55
     */
56
    public function testItem()
57
    {
58
        $feedItem = $this->getFeedItem();
59
        $this->assertInstanceOf(Item::class, $feedItem);
60
61
        // Test the item type
62
        $this->assertTrue($feedItem->isOfType('h-feed'));
63
        $this->assertTrue($feedItem->isOfType('h-feed', MicroformatsFactory::MF2_PROFILE_URI));
64
    }
65
66
    /**
67
     * Create and return an h-feed Microformats item
68
     *
69
     * @return Item h-feed item
70
     */
71
    protected function getFeedItem()
72
    {
73
        $authorItem = new ApplicationItem(
74
            Microformats::FORMAT,
75
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-card'],
76
            [
77
                (object)[
78
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
79
                    'name' => 'p-name',
80
                    'values' => [
81
                        new StringValue('John Doe')
82
                    ]
83
                ],
84
                (object)[
85
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
86
                    'name' => 'u-email',
87
                    'values' => [
88
                        new StringValue('[email protected]')
89
                    ]
90
                ]
91
            ]
92
        );
93
94
95
        $entryItem = new ApplicationItem(
96
            Microformats::FORMAT,
97
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-entry'],
98
            [
99
                (object)[
100
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
101
                    'name' => 'p-name',
102
                    'values' => [
103
                        new StringValue('Famous blog post')
104
                    ]
105
                ],
106
                (object)[
107
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
108
                    'name' => 'p-author',
109
                    'values' => [
110
                        $authorItem
111
                    ]
112
                ]
113
            ]
114
        );
115
116
117
        $feedItem = new ApplicationItem(
118
            Microformats::FORMAT,
119
            (object)['profile' => MicroformatsFactory::MF2_PROFILE_URI, 'name' => 'h-feed'],
120
            [
121
                (object)[
122
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
123
                    'name' => 'p-name',
124
                    'values' => [
125
                        new StringValue('John Doe\'s Blog')
126
                    ]
127
                ],
128
                (object)[
129
                    'profile' => MicroformatsFactory::MF2_PROFILE_URI,
130
                    'name' => 'p-author',
131
                    'values' => [
132
                        $authorItem
133
                    ]
134
                ]
135
            ],
136
            [$entryItem, $entryItem]
137
        );
138
139
        return new Item($feedItem);
140
    }
141
}
142