Completed
Push — ezp-31039-allow-empty-sort-par... ( c6037d...71d919 )
by
unknown
21:21
created

testParseWithMissingSortOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 25
loc 25
rs 9.52
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\REST\Server\Tests\Input\Parser;
8
9
use eZ\Publish\Core\Repository\LocationService;
10
use eZ\Publish\Core\REST\Server\Input\Parser\LocationUpdate;
11
use eZ\Publish\API\Repository\Values\Content\LocationUpdateStruct;
12
use eZ\Publish\API\Repository\Values\Content\Location;
13
use eZ\Publish\Core\REST\Server\Values\RestLocationUpdateStruct;
14
15
class LocationUpdateTest extends BaseTest
16
{
17
    /**
18
     * Tests the LocationUpdate parser.
19
     */
20
    public function testParse()
21
    {
22
        $inputArray = [
23
            'priority' => 0,
24
            'remoteId' => 'remote-id',
25
            'hidden' => 'true',
26
            'sortField' => 'PATH',
27
            'sortOrder' => 'ASC',
28
        ];
29
30
        $locationUpdate = $this->getParser();
31
        $result = $locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
32
33
        $this->assertInstanceOf(
34
            RestLocationUpdateStruct::class,
35
            $result,
36
            'LocationUpdateStruct not created correctly.'
37
        );
38
39
        $this->assertInstanceOf(
40
            LocationUpdateStruct::class,
41
            $result->locationUpdateStruct,
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
42
            'LocationUpdateStruct not created correctly.'
43
        );
44
45
        $this->assertEquals(
46
            0,
47
            $result->locationUpdateStruct->priority,
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
            'LocationUpdateStruct priority property not created correctly.'
49
        );
50
51
        $this->assertEquals(
52
            'remote-id',
53
            $result->locationUpdateStruct->remoteId,
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
54
            'LocationUpdateStruct remoteId property not created correctly.'
55
        );
56
57
        $this->assertTrue(
58
            $result->hidden,
0 ignored issues
show
Documentation introduced by
The property hidden does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
59
            'hidden property not created correctly.'
60
        );
61
62
        $this->assertEquals(
63
            Location::SORT_FIELD_PATH,
64
            $result->locationUpdateStruct->sortField,
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
65
            'LocationUpdateStruct sortField property not created correctly.'
66
        );
67
68
        $this->assertEquals(
69
            Location::SORT_ORDER_ASC,
70
            $result->locationUpdateStruct->sortOrder,
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
71
            'LocationUpdateStruct sortOrder property not created correctly.'
72
        );
73
    }
74
75
    /**
76
     * Test LocationUpdate parser with missing sort field.
77
     */
78 View Code Duplication
    public function testParseWithMissingSortField()
79
    {
80
        $inputArray = [
81
            'priority' => 0,
82
            'remoteId' => 'remote-id',
83
            'sortOrder' => 'ASC',
84
        ];
85
86
        $locationUpdate = $this->getParser();
87
        $result = $locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
88
89
        $this->assertInstanceOf(
90
            RestLocationUpdateStruct::class,
91
            $result
92
        );
93
94
        $this->assertInstanceOf(
95
            LocationUpdateStruct::class,
96
            $result->locationUpdateStruct
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
97
        );
98
99
        $this->assertNull(
100
            $result->locationUpdateStruct->sortField
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
101
        );
102
    }
103
104
    /**
105
     * Test LocationUpdate parser with missing sort order.
106
     */
107 View Code Duplication
    public function testParseWithMissingSortOrder()
108
    {
109
        $inputArray = [
110
            'priority' => 0,
111
            'remoteId' => 'remote-id',
112
            'sortField' => 'PATH',
113
        ];
114
115
        $locationUpdate = $this->getParser();
116
        $result = $locationUpdate->parse($inputArray, $this->getParsingDispatcherMock());
117
118
        $this->assertInstanceOf(
119
            RestLocationUpdateStruct::class,
120
            $result
121
        );
122
123
        $this->assertInstanceOf(
124
            LocationUpdateStruct::class,
125
            $result->locationUpdateStruct
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
126
        );
127
128
        $this->assertNull(
129
            $result->locationUpdateStruct->sortOrder
0 ignored issues
show
Documentation introduced by
The property locationUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
130
        );
131
    }
132
133
    /**
134
     * Returns the LocationUpdateStruct parser.
135
     *
136
     * @return \eZ\Publish\Core\REST\Server\Input\Parser\LocationUpdate
137
     */
138
    protected function internalGetParser()
139
    {
140
        return new LocationUpdate(
141
            $this->getLocationServiceMock(),
142
            $this->getParserTools()
143
        );
144
    }
145
146
    /**
147
     * Get the location service mock object.
148
     *
149
     * @return \eZ\Publish\API\Repository\LocationService
150
     */
151
    protected function getLocationServiceMock()
152
    {
153
        $locationServiceMock = $this->createMock(LocationService::class);
154
155
        $locationServiceMock->expects($this->any())
156
            ->method('newLocationUpdateStruct')
157
            ->will(
158
                $this->returnValue(new LocationUpdateStruct())
159
            );
160
161
        return $locationServiceMock;
162
    }
163
}
164