|
| 1 | + |
| 2 | +## Codeception\Specify\ConfigBuilder |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +Configure Specify usage. |
| 7 | + |
| 8 | +Specify copies properties of object and restores them for each specify block. |
| 9 | +Objects can be cloned deeply or using standard `clone` operator. |
| 10 | +Specify can be configured to prevent specific properties in specify blocks, to choose default cloning method, |
| 11 | +or cloning method for specific properties. |
| 12 | + |
| 13 | +```php |
| 14 | +<?php |
| 15 | +$this->specifyConfig() |
| 16 | + ->ignore('user') // do not clone |
| 17 | +?> |
| 18 | +``` |
| 19 | +#### *public* __construct($config = null) |
| 20 | +#### *public* ignore($properties = null) |
| 21 | +Ignore cloning specific object properties in specify blocks. |
| 22 | + |
| 23 | +```php |
| 24 | +<?php |
| 25 | +$this->user = new User; |
| 26 | +$this->specifyConfig()->ignore('user'); |
| 27 | +$this->specify('change user name', function() { |
| 28 | + $this->user->name = 'davert'; |
| 29 | +}); |
| 30 | +$this->user->name == 'davert'; // name changed |
| 31 | +?> |
| 32 | +``` |
| 33 | + |
| 34 | + * `param array` $properties |
| 35 | + * `return` $this |
| 36 | + |
| 37 | +#### *public* ignoreClasses($classes = null) |
| 38 | +Adds specific class to ignore list, if property is an instance of class it will not be cloned for specify block. |
| 39 | + |
| 40 | + * `param array` $classes |
| 41 | + * `return` $this |
| 42 | + |
| 43 | +#### *public* deepClone($properties = null) |
| 44 | +Turn on/off deep cloning mode. |
| 45 | +Deep cloning mode can also be specified for specific properties. |
| 46 | + |
| 47 | +```php |
| 48 | +<?php |
| 49 | +$this->user = new User; |
| 50 | +$this->post = new Post; |
| 51 | +$this->tag = new Tag; |
| 52 | + |
| 53 | +// turn on deep cloning by default |
| 54 | +$this->specifyConfig()->deepClone(); |
| 55 | + |
| 56 | +// turn off deep cloning by default |
| 57 | +$this->specifyConfig()->deepClone(false); |
| 58 | + |
| 59 | +// deep clone only user and tag property |
| 60 | +$this->specifyConfig()->deepClone('user', 'tag'); |
| 61 | + |
| 62 | +// alternatively |
| 63 | +$this->specifyConfig()->deepClone(['user', 'tag']); |
| 64 | +?> |
| 65 | +``` |
| 66 | + |
| 67 | + * `param bool` $properties |
| 68 | + * `return` $this |
| 69 | + |
| 70 | +#### *public* shallowClone($properties = null) |
| 71 | +Disable deep cloning mode, use shallow cloning by default, which is faster. |
| 72 | +Deep cloning mode can also be disabled for specific properties. |
| 73 | + |
| 74 | +```php |
| 75 | +<?php |
| 76 | +$this->user = new User; |
| 77 | +$this->post = new Post; |
| 78 | +$this->tag = new Tag; |
| 79 | + |
| 80 | +// turn off deep cloning by default |
| 81 | +$this->specifyConfig()->shallowClone(); |
| 82 | + |
| 83 | +// turn on deep cloning by default |
| 84 | +$this->specifyConfig()->shallowClone(false); |
| 85 | + |
| 86 | +// shallow clone only user and tag property |
| 87 | +$this->specifyConfig()->shallowClone('user', 'tag'); |
| 88 | + |
| 89 | +// alternatively |
| 90 | +$this->specifyConfig()->shallowClone(['user', 'tag']); |
| 91 | +?> |
| 92 | +``` |
| 93 | + |
| 94 | + * `param bool` $properties |
| 95 | + * `return` $this |
| 96 | + |
0 commit comments