Select Git revision
install.php
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
AbstractControllerTestCase.php 3.05 KiB
<?php
namespace UnicaenTest\Controller;
use Doctrine\ORM\EntityManager;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophet;
use Zend\ServiceManager\ServiceManager;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
/**
* Class AbstractControllerTest
*
* @package ApplicationTest\Controller
*/
abstract class AbstractControllerTestCase extends AbstractHttpControllerTestCase
{
// public function setUp()
// {
// // The module configuration should still be applicable for tests.
// // You can override configuration here with test case specific values,
// // such as sample view templates, path stacks, module_listener_options,
// // etc.
// $configOverrides = [];
//
// $this->setApplicationConfig(ArrayUtils::merge(
// // Grabbing the full application configuration:
// include __DIR__ . '/../../../../config/application.config.php',
// $configOverrides
// ));
//
// parent::setUp();
// }
/**
* @param string $authorizeServiceClass
* @return ObjectProphecy|UnicaenAuth\Service\AuthorizeService
*/
protected function mockAuthorizeService($authorizeServiceClass)
{
$prophet = new Prophet();
/** @var ObjectProphecy|UnicaenAuth\Service\AuthorizeService $prophecy */
$prophecy = $prophet->prophesize();
$prophecy->willExtend($authorizeServiceClass);
$service = $prophecy->reveal();
/* @var $services ServiceManager */
$services = $this->getApplication()->getServiceManager();
$services->setAllowOverride(true);
$services->setFactory('BjyAuthorize\Service\Authorize', function() use ($service) {
return $service;
});
return $prophecy;
}
/**
* @param string $userContextServiceClass
* @return ObjectProphecy|UnicaenAuth\Service\UserContext
*/
protected function mockUserContextService($userContextServiceClass)
{
$prophet = new Prophet();
/** @var ObjectProphecy|UnicaenAuth\Service\UserContext $prophecy */
$prophecy = $prophet->prophesize();
$prophecy->willExtend($userContextServiceClass);
$prophecy->getEventManager()->willReturn($this->getApplication()->getEventManager());
$prophecy->setServiceLocator(Argument::any())->willReturn();
$service = $prophecy->reveal();
/* @var $services ServiceManager */
$services = $this->getApplication()->getServiceManager();
$services->setAllowOverride(true);
$services->setFactory('UnicaenAuth\Service\UserContext', function() use ($service) {
return $service;
});
return $prophecy;
}
/**
* @var EntityManager
*/
private $em;
/**
* @param string $name
* @return EntityManager
*/
protected function em($name = 'orm_default')
{
if (null === $this->em) {
$this->em = $this->getApplicationServiceLocator()->get("doctrine.entitymanager.$name");
}
return $this->em;
}
}