1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\API\Repository\Tests\Values\Content; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Language; |
12
|
|
|
use eZ\Publish\API\Repository\Tests\Values\ValueObjectTestTrait; |
13
|
|
|
use PHPUnit_Framework_TestCase; |
14
|
|
|
|
15
|
|
|
class LanguageTest extends PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
use ValueObjectTestTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test default properties of just created class. |
21
|
|
|
*/ |
22
|
|
|
public function testNewClass() |
23
|
|
|
{ |
24
|
|
|
$language = new Language(); |
25
|
|
|
|
26
|
|
|
$this->assertPropertiesCorrect( |
27
|
|
|
[ |
28
|
|
|
'id' => null, |
29
|
|
|
'languageCode' => null, |
30
|
|
|
'name' => null, |
31
|
|
|
'enabled' => null, |
32
|
|
|
], |
33
|
|
|
$language |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Test retrieving missing property. |
39
|
|
|
* |
40
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Language::__get |
41
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyNotFoundException |
42
|
|
|
* @expectedExceptionMessage Property 'notDefined' not found on class |
43
|
|
|
*/ |
44
|
|
|
public function testMissingProperty() |
45
|
|
|
{ |
46
|
|
|
$language = new Language(); |
47
|
|
|
$value = $language->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\Language::__set |
55
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
56
|
|
|
* @expectedExceptionMessage Property 'id' is readonly on class |
57
|
|
|
*/ |
58
|
|
|
public function testReadOnlyProperty() |
59
|
|
|
{ |
60
|
|
|
$language = new Language(); |
61
|
|
|
$language->id = 42; |
|
|
|
|
62
|
|
|
self::fail('Succeeded setting read only property'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test if property exists. |
67
|
|
|
* |
68
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Language::__isset |
69
|
|
|
*/ |
70
|
|
|
public function testIsPropertySet() |
71
|
|
|
{ |
72
|
|
|
$language = new Language(); |
73
|
|
|
$value = isset($language->notDefined); |
74
|
|
|
self::assertEquals(false, $value); |
75
|
|
|
|
76
|
|
|
$value = isset($language->id); |
77
|
|
|
self::assertEquals(true, $value); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Test unsetting a property. |
82
|
|
|
* |
83
|
|
|
* @covers \eZ\Publish\API\Repository\Values\Content\Language::__unset |
84
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\PropertyReadOnlyException |
85
|
|
|
* @expectedExceptionMessage Property 'id' is readonly on class |
86
|
|
|
*/ |
87
|
|
|
public function testUnsetProperty() |
88
|
|
|
{ |
89
|
|
|
$language = new Language(['id' => 2]); |
90
|
|
|
unset($language->id); |
91
|
|
|
self::fail('Unsetting read-only property succeeded'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write 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.