Skip to content

Instantly share code, notes, and snippets.

@fwolf
Created February 27, 2015 10:52
Show Gist options
  • Save fwolf/2571d537208a822ea10e to your computer and use it in GitHub Desktop.
Save fwolf/2571d537208a822ea10e to your computer and use it in GitHub Desktop.
MockContainer, not used, system function mock need create in per test case.
<?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