Created
February 27, 2015 10:52
-
-
Save fwolf/2571d537208a822ea10e to your computer and use it in GitHub Desktop.
MockContainer, not used, system function mock need create in per test case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Fwlib\Test; | |
use Fwlib\Base\AbstractServiceContainer; | |
use malkusch\phpmock\Mock; | |
/** | |
* Container of system function mocks | |
* | |
* @copyright Copyright 2015 Fwolf | |
* @license http://www.gnu.org/licenses/lgpl.html LGPL-3.0+ | |
*/ | |
class MockContainer extends AbstractServiceContainer | |
{ | |
/** | |
* Get full qualified function name | |
* | |
* @param string $namespace | |
* @param string $function | |
* @return string | |
*/ | |
protected function getFullName($namespace, $function) | |
{ | |
$namespace = trim($namespace, '\\'); | |
return "$namespace\\$function"; | |
} | |
/** | |
* @param string $namespace | |
* @param string $function | |
* @return Mock | |
*/ | |
public function getMock($namespace, $function) | |
{ | |
$fullName = $this->getFullName($namespace, $function); | |
return isset($this->serviceInstance[$fullName]) | |
? $this->serviceInstance[$fullName] | |
: null; | |
} | |
/** | |
* Register a mock instance | |
* | |
* @param string $namespace | |
* @param string $function | |
* @param Mock $mock | |
* @return static | |
*/ | |
public function registerMock($namespace, $function, $mock) | |
{ | |
$fullName = $this->getFullName($namespace, $function); | |
$this->registerInstance($fullName, $mock); | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment