Skip to content
Snippets Groups Projects
Commit 76a90bed authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Add alias support to mock container.

parent e4711732
No related merge requests found
...@@ -55,6 +55,15 @@ class MockContainer implements ContainerInterface ...@@ -55,6 +55,15 @@ class MockContainer implements ContainerInterface
*/ */
protected $services = []; protected $services = [];
/**
* Common service aliases.
*
* @var array
*/
protected $aliases = [
'ViewHelperManager' => \Laminas\View\HelperPluginManager::class,
];
/** /**
* Test case (for building mock objects) * Test case (for building mock objects)
* *
...@@ -108,12 +117,13 @@ class MockContainer implements ContainerInterface ...@@ -108,12 +117,13 @@ class MockContainer implements ContainerInterface
/** /**
* Finds an entry of the container by its identifier and returns it. * Finds an entry of the container by its identifier and returns it.
* *
* @param string $id Identifier of the entry to look for. * @param string $rawId Identifier of the entry to look for.
* *
* @return mixed * @return mixed
*/ */
public function get($id) public function get($rawId)
{ {
$id = $this->aliases[$rawId] ?? $rawId;
if (!isset($this->services[$id])) { if (!isset($this->services[$id])) {
$this->services[$id] = $this->createMock($id); $this->services[$id] = $this->createMock($id);
} }
...@@ -124,12 +134,13 @@ class MockContainer implements ContainerInterface ...@@ -124,12 +134,13 @@ class MockContainer implements ContainerInterface
* Returns true if the container can return an entry for the given identifier. * Returns true if the container can return an entry for the given identifier.
* Returns false otherwise. * Returns false otherwise.
* *
* @param string $id Identifier of the entry to look for. * @param string $rawId Identifier of the entry to look for.
* *
* @return bool * @return bool
*/ */
public function has($id) public function has($rawId)
{ {
$id = $this->aliases[$rawId] ?? $rawId;
// Assume every service exists unless explicitly disabled // Assume every service exists unless explicitly disabled
return !in_array($id, $this->disabled); return !in_array($id, $this->disabled);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment