99% of 164OPs |
100% of 26Lines |
82% of 17Branches |
100% of 11Paths |
| Method | OPs | OPs % | Lines | Line % | Branches | Branches % | Paths | Path % |
|---|---|---|---|---|---|---|---|---|
| mageekguy\atoum\autoloader\mock::__construct() | 16 | 100% | 4 | 100% | 1 | 0% | 1 | 100% |
| mageekguy\atoum\autoloader\mock::setMockGenerator() | 16 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\autoloader\mock::getMockGenerator() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\autoloader\mock::setAdapter() | 16 | 100% | 2 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\autoloader\mock::getAdapter() | 6 | 100% | 1 | 100% | 1 | 100% | 1 | 100% |
| mageekguy\atoum\autoloader\mock::register() | 30 | 97% | 4 | 100% | 4 | 75% | 2 | 100% |
| mageekguy\atoum\autoloader\mock::unregister() | 26 | 96% | 4 | 100% | 4 | 75% | 2 | 100% |
| mageekguy\atoum\autoloader\mock::requireClass() | 48 | 100% | 8 | 100% | 4 | 100% | 2 | 100% |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum\autoloader; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum, |
| 7 |
mageekguy\atoum\exceptions |
| 8 |
; |
| 9 |
|
| 10 |
class mock |
| 11 |
{
|
| 12 |
protected $mockGenerator; |
| 13 |
protected $adapter; |
| 14 |
|
| 15 |
public function __construct(atoum\mock\generator $generator = null, atoum\adapter $adapter = null)100% |
| 16 |
{
|
| 17 |
$this |
| 18 |
->setAdapter($adapter) |
| 19 |
->setMockGenerator($generator) |
| 20 |
; |
| 21 |
} |
| 22 |
|
| 23 |
public function setMockGenerator(atoum\mock\generator $generator = null)100% |
| 24 |
{
|
| 25 |
$this->mockGenerator = $generator ?: new atoum\mock\generator(); |
| 26 |
|
| 27 |
return $this; |
| 28 |
} |
| 29 |
|
| 30 |
public function getMockGenerator()100% |
| 31 |
{
|
| 32 |
return $this->mockGenerator; |
| 33 |
} |
| 34 |
|
| 35 |
public function setAdapter(atoum\adapter $adapter = null)100% |
| 36 |
{
|
| 37 |
$this->adapter = $adapter ?: new atoum\adapter(); |
| 38 |
|
| 39 |
return $this; |
| 40 |
} |
| 41 |
|
| 42 |
public function getAdapter()100% |
| 43 |
{
|
| 44 |
return $this->adapter; |
| 45 |
} |
| 46 |
|
| 47 |
public function register()100% |
| 48 |
{
|
| 49 |
if ($this->adapter->spl_autoload_register(array($this, 'requireClass'), true, true) === false) |
| 50 |
{
|
| 51 |
throw new exceptions\runtime('Unable to register mock autoloader');
|
| 52 |
} |
| 53 |
|
| 54 |
return $this; |
| 55 |
} |
| 56 |
|
| 57 |
public function unregister()100% |
| 58 |
{
|
| 59 |
if ($this->adapter->spl_autoload_unregister(array($this, 'requireClass')) === false) |
| 60 |
{
|
| 61 |
throw new exceptions\runtime('Unable to unregister mock autoloader');
|
| 62 |
} |
| 63 |
|
| 64 |
return $this; |
| 65 |
} |
| 66 |
|
| 67 |
public function requireClass($class)100% |
| 68 |
{
|
| 69 |
$mockNamespace = ltrim($this->mockGenerator->getDefaultNamespace(), '\\'); |
| 70 |
$mockNamespacePattern = '/^\\\?' . preg_quote($mockNamespace) . '\\\/i'; |
| 71 |
$mockedClass = preg_replace($mockNamespacePattern, '', $class); |
| 72 |
|
| 73 |
if ($mockedClass !== $class) |
| 74 |
{
|
| 75 |
$this->mockGenerator->generate($mockedClass); |
| 76 |
} |
| 77 |
|
| 78 |
return $this; |
| 79 |
} |
| 80 |
} |