Created
February 18, 2012 16:12
-
-
Save havvg/1859987 to your computer and use it in GitHub Desktop.
Symfony2 DIC mock with services
This file contains 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 Havvg\Bundle\CloudcontrolBundle\Tests; | |
abstract class AbstractTest extends \PHPUnit_Framework_TestCase | |
{ | |
// more stuff? | |
/** | |
* Return a mock object for the DI ContainerInterface. | |
* | |
* @param array $services A key-value list of services the container contains. | |
* | |
* @return \PHPUnit_Framework_MockObject_MockObject | |
*/ | |
protected function getContainerMock(array $services) | |
{ | |
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); | |
$container | |
->expects($this->atLeastOnce()) | |
->method('get') | |
->will($this->returnCallback(function($service) use ($services) { | |
return $services[$service]; | |
})) | |
; | |
return $container; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment