Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
Many improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tyx committed Aug 1, 2014
1 parent aaf7090 commit 9ef0bbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/MockContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,31 @@

class MockContainer extends Container
{
private $mockedServices = array();
private static $mockedServices = array();

public function overrideService($id, $mock)
{
$this->mockedServices[$id] = $mock;
self::$mockedServices[$id] = $mock;
}

public function removeMock($id)
{
if ($this->hasMockedService($id)) {
unset(self::$mockedServices[$id]);
}
}

public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
if ($this->hasMockedService($id, $this->mockedServices)) {
return $this->mockedServices[$id];
if ($this->hasMockedService($id)) {
return self::$mockedServices[$id];
}

return parent::get($id, $invalidBehavior);
}

public function hasMockedService($id)
{
return array_key_exists($id, $this->mockedServices);
return array_key_exists($id, self::$mockedServices);
}
}
8 changes: 7 additions & 1 deletion src/Mocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Rezzza\MockExtension;

use Behat\Mink\Mink;
use Symfony\Component\HttpKernel\KernelInterface;

class Mocker
Expand All @@ -12,7 +13,7 @@ class Mocker

private $bypassingContainer;

public function __construct(KernelInterface $kernel, $mink)
public function __construct(KernelInterface $kernel, Mink $mink)
{
$this->container = $kernel->getContainer();
$this->mink = $mink;
Expand All @@ -30,6 +31,11 @@ public function mockService($serviceId, MockEngine $adapter)
return $mock;
}

public function unmockService($serviceId)
{
$this->container->removeMock($serviceId);
}

public function getMockedService($serviceId)
{
return $this->container->get($serviceId);
Expand Down

0 comments on commit 9ef0bbb

Please sign in to comment.