1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75:
<?php
namespace phpmock\environment;
use phpmock\Deactivatable;
use phpmock\Mock;
/**
* Container for several mocks.
*
* @author Markus Malkusch <markus@malkusch.de>
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
* @license http://www.wtfpl.net/txt/copying/ WTFPL
*/
class MockEnvironment implements Deactivatable
{
/**
* @var Mock[] Mock environment.
*/
private $mocks = [];
/**
* Sets the mocks for this environment.
*
* @param Mock[] $mocks The mocks for this environment.
*/
public function __construct(array $mocks = [])
{
$this->mocks = $mocks;
}
/**
* Adds a mock to this environment.
*
* @param Mock $mock Mock.
*/
public function addMock(Mock $mock)
{
$this->mocks[] = $mock;
}
/**
* Enable all mocks in this environment.
*/
public function enable()
{
foreach ($this->mocks as $mock) {
$mock->enable();
}
}
/**
* Define all mocks in this environment.
*
* @see phpmock\Mock::define()
*/
public function define()
{
foreach ($this->mocks as $mock) {
$mock->define();
}
}
/**
* Disable all mocks in this environment.
*/
public function disable()
{
foreach ($this->mocks as $mock) {
$mock->disable();
}
}
}