Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
8 / 8 |
CachingGenerator | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
8 / 8 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
generate | |
100.00% |
1 / 1 |
2 | |
100.00% |
6 / 6 |
<?php | |
namespace Mockery\Generator; | |
class CachingGenerator implements Generator | |
{ | |
protected $generator; | |
protected $cache = array(); | |
public function __construct(Generator $generator) | |
{ | |
$this->generator = $generator; | |
} | |
public function generate(MockConfiguration $config) | |
{ | |
$hash = $config->getHash(); | |
if (isset($this->cache[$hash])) { | |
return $this->cache[$hash]; | |
} | |
$definition = $this->generator->generate($config); | |
$this->cache[$hash] = $definition; | |
return $definition; | |
} | |
} |