Test Setup Failed
Pull Request — develop (#1)
by Andreas
04:24
created

ContentMapperTest::getValidContentData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 6

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
use Wambo\Catalog\Mapper\ContentMapper;
3
4
/**
5
 * Class ContentMapperTest tests the Wambo\Catalog\Mapper\ContentMapper class.
6
 */
7
class ContentMapperTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
{
9
    /**
10
     * If the given summary and description is valid a Content model with the given summary and description should be
11
     * returned
12
     *
13
     * @test
14
     * @dataProvider getValidContentData
15
     *
16
     * @param array $contentData Product content data
17
     */
18
    public function getContent_ValidSummaryAndDescriptionGiven_ContentWithSummaryAndDescriptionIsReturned($contentData)
19
    {
20
        // arrange
21
        $productMapper = new ContentMapper();
22
23
        // act
24
        $content = $productMapper->getContent($contentData);
25
26
        // assert
27
        $this->assertNotEmpty($content->getSummaryText(), "The summary of the content model should not be empty");
28
        $this->assertNotEmpty($content->getProductDescription(), "The description of the content model should not be empty");
29
    }
30
31
    /**
32
     * If the given summary and description is valid a Content model with the given summary and description should be
33
     * returned
34
     *
35
     * @test
36
     * @dataProvider getContentDataWithMissingAttributes
37
     * @expectedException Wambo\Catalog\Error\ContentException
38
     * @expectedExceptionMessageRegExp /The field '.+' is missing in the given content data/
39
     *
40
     * @param array $contentData Product content data
41
     */
42
    public function getContent_FieldsMissing_ContentExceptionIsThrown($contentData)
43
    {
44
        // arrange
45
        $productMapper = new ContentMapper();
46
47
        // act
48
        $productMapper->getContent($contentData);
49
    }
50
51
    /**
52
     * If the given summary is invalid a ContentException should be thrown
53
     *
54
     * @test
55
     * @dataProvider getContentWithInvalidSummary
56
     * @expectedException Wambo\Catalog\Error\ContentException
57
     * @expectedExceptionMessageRegExp /The summary text should not be (shorter|longer) than \d+ characters/
58
     *
59
     * @param array $contentData Product content data
60
     */
61
    public function getContent_InvalidSummary_ContentExceptionIsThrown($contentData)
62
    {
63
        // arrange
64
        $productMapper = new ContentMapper();
65
66
        // act
67
        $productMapper->getContent($contentData);
68
    }
69
70
    /**
71
     * Get a list of valid content data for testing
72
     * @return array
73
     */
74 View Code Duplication
    public static function getValidContentData() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
        return array(
76
            [
77
                [
78
                    "summary" => "A product summary",
79
                    "description" => "A detailed product description",
80
                ],
81
82
                [
83
                    "summary" => "ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.",
84
                    "description" => "A detailed product description ...",
85
                ]
86
            ]
87
        );
88
    }
89
90
    /**
91
     * Get a list of valid content data for testing
92
     * @return array
93
     */
94
    public static function getContentWithInvalidSummary() {
95
        return array(
96
            [
97
                // empty
98
                [
99
                    "summary" => "",
100
                ],
101
102
                // too short
103
                [
104
                    "summary" => "A",
105
                ],
106
107
                // too long
108
                [
109
                    "summary" => "ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.ABCdefghijklmnopqrstuvwxyzöüä.",
110
                ]
111
            ]
112
        );
113
    }
114
115
    /**
116
     * Get a list of content data object with missing attribtues for testing
117
     * @return array
118
     */
119 View Code Duplication
    public static function getContentDataWithMissingAttributes() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
        return array(
121
            [
122
                // wrong casing
123
                [
124
                    "SUMMARY" => "A product summary",
125
                    "description" => "A detailed product description",
126
                ],
127
128
                // summary missing
129
                [
130
                    "description" => "A detailed product description",
131
                ]
132
            ]
133
        );
134
    }
135
}
136