Code Duplication    Length = 80-85 lines in 2 locations

eZ/Publish/Core/Repository/Tests/Values/ObjectState/ObjectStateGroupTest.php 1 location

@@ 18-97 (lines=80) @@
15
/**
16
 * Test internal integrity of @see \eZ\Publish\Core\Repository\Values\ObjectState\ObjectStateGroup ValueObject.
17
 */
18
class ObjectStateGroupTest extends PHPUnit_Framework_TestCase
19
{
20
    use ValueObjectTestTrait;
21
22
    /**
23
     * Test a new class and default values on properties.
24
     *
25
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__construct
26
     */
27
    public function testNewClass()
28
    {
29
        $objectStateGroup = new ObjectStateGroup();
30
31
        $this->assertPropertiesCorrect(
32
            [
33
                'id' => null,
34
                'identifier' => null,
35
                'defaultLanguageCode' => null,
36
                'languageCodes' => null,
37
                'names' => [],
38
                'descriptions' => [],
39
            ],
40
            $objectStateGroup
41
        );
42
    }
43
44
    /**
45
     * Test retrieving missing property.
46
     *
47
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__get
48
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
49
     */
50
    public function testMissingProperty()
51
    {
52
        $objectStateGroup = new ObjectStateGroup();
53
        $value = $objectStateGroup->notDefined;
54
        $this->fail('Succeeded getting non existing property');
55
    }
56
57
    /**
58
     * Test setting read only property.
59
     *
60
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__set
61
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
62
     */
63
    public function testReadOnlyProperty()
64
    {
65
        $objectStateGroup = new ObjectStateGroup();
66
        $objectStateGroup->id = 42;
67
        $this->fail('Succeeded setting read only property');
68
    }
69
70
    /**
71
     * Test if property exists.
72
     *
73
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__isset
74
     */
75
    public function testIsPropertySet()
76
    {
77
        $objectStateGroup = new ObjectStateGroup();
78
        $value = isset($objectStateGroup->notDefined);
79
        $this->assertEquals(false, $value);
80
81
        $value = isset($objectStateGroup->id);
82
        $this->assertEquals(true, $value);
83
    }
84
85
    /**
86
     * Test unsetting a property.
87
     *
88
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__unset
89
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
90
     */
91
    public function testUnsetProperty()
92
    {
93
        $objectStateGroup = new ObjectStateGroup(['id' => 2]);
94
        unset($objectStateGroup->id);
95
        $this->fail('Unsetting read-only property succeeded');
96
    }
97
}
98

eZ/Publish/Core/Repository/Tests/Values/ObjectState/ObjectStateTest.php 1 location

@@ 18-102 (lines=85) @@
15
/**
16
 * Test internal integrity of @see \eZ\Publish\Core\Repository\Values\ObjectState\ObjectState ValueObject.
17
 */
18
class ObjectStateTest extends PHPUnit_Framework_TestCase
19
{
20
    use ValueObjectTestTrait;
21
22
    /**
23
     * Test a new class and default values on properties.
24
     *
25
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__construct
26
     */
27
    public function testNewClass()
28
    {
29
        $objectState = new ObjectState();
30
31
        $this->assertPropertiesCorrect(
32
            [
33
                'id' => null,
34
                'identifier' => null,
35
                'priority' => null,
36
                'defaultLanguageCode' => null,
37
                'languageCodes' => null,
38
                'names' => [],
39
                'descriptions' => [],
40
            ],
41
            $objectState
42
        );
43
    }
44
45
    /**
46
     * Test retrieving missing property.
47
     *
48
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__get
49
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__get
50
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException
51
     */
52
    public function testMissingProperty()
53
    {
54
        $objectState = new ObjectState();
55
        $value = $objectState->notDefined;
56
        $this->fail('Succeeded getting non existing property');
57
    }
58
59
    /**
60
     * Test setting read only property.
61
     *
62
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__set
63
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__set
64
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
65
     */
66
    public function testReadOnlyProperty()
67
    {
68
        $objectState = new ObjectState();
69
        $objectState->id = 42;
70
        $this->fail('Succeeded setting read only property');
71
    }
72
73
    /**
74
     * Test if property exists.
75
     *
76
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__isset
77
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__isset
78
     */
79
    public function testIsPropertySet()
80
    {
81
        $objectState = new ObjectState();
82
        $value = isset($objectState->notDefined);
83
        $this->assertEquals(false, $value);
84
85
        $value = isset($objectState->id);
86
        $this->assertEquals(true, $value);
87
    }
88
89
    /**
90
     * Test unsetting a property.
91
     *
92
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectState::__unset
93
     * @covers \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup::__unset
94
     * @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException
95
     */
96
    public function testUnsetProperty()
97
    {
98
        $objectState = new ObjectState(array('id' => 2));
99
        unset($objectState->id);
100
        $this->fail('Unsetting read-only property succeeded');
101
    }
102
}
103