Commit 9e184cbb authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Commit initial.

parent d36a5727
<?php
namespace UnicaenTest;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$application = $e->getApplication();
$application->getServiceManager()->get('translator');
$eventManager = $application->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return [
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
],
],
];
}
}
{
"name": "unicaen/unicaen-test",
"description": "Module consacré aux tests",
"repositories": [
{
"type": "composer",
"url": "https://dev.unicaen.fr/packagist"
}
],
"require": {
"unicaen/unicaen-app": "^1.2",
"zendframework/zend-test": "^2.4",
"phpunit/PHPUnit": "^5.6",
"phpspec/prophecy": "^1.6"
},
"autoload": {
"psr-0": {
"UnicaenTest": "src/"
},
"classmap": [
"./Module.php"
]
}
}
This diff is collapsed.
File added
<?php
namespace UnicaenTest;
return [
'router' => [
'routes' => [
],
],
'service_manager' => [
'factories' => [
],
'invokables' => [
],
],
'controllers' => [
'invokables' => [
],
],
'navigation' => [
'default' => [
],
],
];
<?php
/**
* Configuration globale du module UnicaenTest.
*
* If you have a ./config/autoload/ directory set up for your project,
* drop this config file in it and change the values as you wish.
*/
return [
'unicaen-test' => [
],
];
\ No newline at end of file
<?php
/**
* Configuration locale du module UnicaenTest.
*
* If you have a ./config/autoload/ directory set up for your project,
* drop this config file in it and change the values as you wish.
*/
return [
'unicaen-test' => [
],
];
\ No newline at end of file
<?php
namespace UnicaenTest\Controller;
use Doctrine\ORM\EntityManager;
use Prophecy\Argument;
use Prophecy\Prophet;
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 \Prophecy\Prophecy\ObjectProphecy
*/
protected function mockAuthorizeService($authorizeServiceClass)
{
$prophet = new Prophet();
$prophecy = $prophet->prophesize();
$prophecy->willExtend($authorizeServiceClass);
$service = $prophecy->reveal();
/* @var $services \Zend\ServiceManager\ServiceManager */
$services = $this->getApplication()->getServiceManager();
$services->setAllowOverride(true);
$services->setFactory('BjyAuthorize\Service\Authorize', function() use ($service) {
return $service;
});
return $prophecy;
}
/**
* @param string $userContextServiceClass
* @return \Prophecy\Prophecy\ObjectProphecy
*/
protected function mockUserContextService($userContextServiceClass)
{
$prophet = new Prophet();
$prophecy = $prophet->prophesize();
$prophecy->willExtend($userContextServiceClass);
$prophecy->getEventManager()->willReturn($this->getApplication()->getEventManager());
$prophecy->setServiceLocator(Argument::any())->willReturn();
$service = $prophecy->reveal();
/* @var $services \Zend\ServiceManager\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;
}
}
\ No newline at end of file
<?php
namespace UnicaenTest\Entity\Db;
use Doctrine\ORM\EntityManager;
use SplStack;
use UnicaenApp\Service\EntityManagerAwareTrait;
use Zend\Stdlib\ArrayUtils;
/**
* Description of EntityProvider
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
abstract class AbstractEntityProvider
{
use EntityManagerAwareTrait;
/**
* @var array
*/
protected $config = [];
/**
* @var array
*/
protected $newEntities;
/**
*
* @param EntityManager $entityManager
* @param array $config
*/
public function __construct(EntityManager $entityManager, array $config = [])
{
$this->setEntityManager($entityManager);
$this->config = ArrayUtils::merge($this->config, $config);
//Asset::setSource($this->getSource());
$this->newEntities = new SplStack();
}
/**
* @var string
*/
protected $testClassName;
/**
*
* @param string $className
* @return $this
*/
public function setTestClassName($className)
{
$this->testClassName = $className;
return $this;
}
/**
* SUpprime du gestionnaire d'entité les éventuelles nouvelles instances d'entités créées.
*
* @param bool $flush
* @return $this
*/
public function removeNewEntities($flush = true)
{
$this->newEntities->rewind();
while ($this->newEntities->valid()) {
$entity = $this->newEntities->current();
// if ($entity instanceof ElementPedagogique) {
// // On historise les EP à la main car on n'arrive pas à éviter l'erreur suivante :
// // Doctrine\DBAL\DBALException: An exception occurred while executing
// // 'DELETE FROM V_ELEMENT_TYPE_INTERVENTION WHERE ELEMENT_PEDAGOGIQUE_ID = ?' with params [17970]:
// // ORA-01752: cannot delete from view without exactly one key-preserved table
// $entity->setHistoDestruction(new \DateTime());
// }
// else {
$this->getEntityManager()->remove($entity);
// }
$this->newEntities->next();
}
if ($flush) {
$this->getEntityManager()->flush();
}
return $this;
}
}
\ No newline at end of file
Markdown is supported
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