5.7. Properties¶
5.7.1. Setting a Single Property¶
You can set a properties when creating a mock using setProperty
:
$mock = $this->niceMock('MyClass')
->setProperty('foo', 'bar')
->get();
$this->foo; // bar
5.7.2. Setting Multiple Properties¶
Setting multiple properties can be done with setProperties
:
$mock = $this->niceMock('MyClass')
->setProperties([
'foo' => 'bar',
'bar' => 'baz',
])
->get();
$this->bar; // baz
When using setProperties
it will add on the provided properties, not
replace any previously set ones.
5.7.3. Other Information¶
Note: The property or properties are set after all other aspects of the mock have been setup. This means properties that may be set as part of a partial mock will be overridden by the properties provided.
This feature was introduced in Multiverse (Release v1.7.0).