1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* PHP: Nelson Martell Library file |
4
|
|
|
* |
5
|
|
|
* Content: |
6
|
|
|
* - Trait definition |
7
|
|
|
* |
8
|
|
|
* Copyright © 2017 Nelson Martell (http://nelson6e65.github.io) |
9
|
|
|
* |
10
|
|
|
* Licensed under The MIT License (MIT) |
11
|
|
|
* For full copyright and license information, please see the LICENSE |
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
13
|
|
|
* |
14
|
|
|
* @copyright 2017 Nelson Martell |
15
|
|
|
* @link http://nelson6e65.github.io/php_nml/ |
16
|
|
|
* @since v0.7.0 |
17
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) |
18
|
|
|
* */ |
19
|
|
|
|
20
|
|
|
namespace NelsonMartell\Test\Helpers; |
21
|
|
|
|
22
|
|
|
use Cake\Utility\Inflector; |
23
|
|
|
use NelsonMartell\Extensions\Text; |
24
|
|
|
use NelsonMartell\IStrictPropertiesContainer; |
25
|
|
|
use SebastianBergmann\Exporter\Exporter; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Split of ImplementsIStrictPropertiesContainer, for classes implementing any write-only property. |
29
|
|
|
* |
30
|
|
|
* @author Nelson Martell <[email protected]> |
31
|
|
|
* */ |
32
|
|
|
trait HasWriteOnlyProperties |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @returns IStrictPropertiesContainer |
36
|
|
|
*/ |
37
|
|
|
public abstract function testImplementsIStrictPropertiesContainerInterface($obj); |
|
|
|
|
38
|
|
|
|
39
|
|
|
public abstract function writeonlyPropertiesProvider(); |
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @dataProvider writeonlyPropertiesProvider |
43
|
|
|
*/ |
44
|
|
|
public function testWriteonlyPropertiesAreWritables( |
45
|
|
|
IStrictPropertiesContainer $obj, |
46
|
|
|
$property, |
47
|
|
|
$value |
48
|
|
|
) { |
49
|
|
|
$obj->$property = $value; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @depends testWriteonlyPropertiesAreWritables |
54
|
|
|
* @dataProvider writeonlyPropertiesProvider |
55
|
|
|
* @expectedException \BadMethodCallException |
56
|
|
|
*/ |
57
|
|
|
public function testWriteonlyPropertiesAreNotReadables( |
58
|
|
|
IStrictPropertiesContainer $obj, |
59
|
|
|
$property, |
60
|
|
|
$value |
61
|
|
|
) { |
62
|
|
|
$obj->$property = $value; |
63
|
|
|
$actual = $obj->$property; |
|
|
|
|
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.