Code Duplication    Length = 75-77 lines in 2 locations

eZ/Publish/API/Repository/Tests/Values/Content/SectionTest.php 1 location

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

eZ/Publish/Core/Repository/Tests/Values/User/RoleTest.php 1 location

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