Commit 725d4932 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Retouche AbstractControllerTestCase

parent 5224ba99
Loading
Loading
Loading
Loading
Loading
+17 −19
Original line number Diff line number Diff line
@@ -3,18 +3,19 @@
namespace UnicaenTest\Controller;

use Doctrine\ORM\EntityManager;
use Laminas\ServiceManager\ServiceManager;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophet;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
use Psr\Container\ContainerExceptionInterface;
use RuntimeException;

/**
 * Class AbstractControllerTest
 *
 * @package ApplicationTest\Controller
 */
abstract class AbstractControllerTestCase extends AbstractHttpControllerTestCase
abstract class AbstractControllerTestCase extends \Laminas\Test\PHPUnit\Controller\AbstractControllerTestCase
{
//    public function setUp()
//    {
@@ -35,13 +36,13 @@ abstract class AbstractControllerTestCase extends AbstractHttpControllerTestCase

    /**
     * @param string $authorizeServiceClass
     * @return ObjectProphecy|UnicaenAuth\Service\AuthorizeService
     * @return ObjectProphecy|\UnicaenAuth\Service\AuthorizeService
     */
    protected function mockAuthorizeService($authorizeServiceClass)
    protected function mockAuthorizeService(string $authorizeServiceClass)
    {
        $prophet = new Prophet();

        /** @var ObjectProphecy|UnicaenAuth\Service\AuthorizeService $prophecy */
        /** @var ObjectProphecy|\UnicaenAuth\Service\AuthorizeService $prophecy */
        $prophecy = $prophet->prophesize();
        $prophecy->willExtend($authorizeServiceClass);

@@ -59,13 +60,13 @@ abstract class AbstractControllerTestCase extends AbstractHttpControllerTestCase

    /**
     * @param string $userContextServiceClass
     * @return ObjectProphecy|UnicaenAuth\Service\UserContext
     * @return ObjectProphecy|\UnicaenAuth\Service\UserContext
     */
    protected function mockUserContextService($userContextServiceClass)
    protected function mockUserContextService(string $userContextServiceClass)
    {
        $prophet = new Prophet();

        /** @var ObjectProphecy|UnicaenAuth\Service\UserContext $prophecy */
        /** @var ObjectProphecy|\UnicaenAuth\Service\UserContext $prophecy */
        $prophecy = $prophet->prophesize();
        $prophecy->willExtend($userContextServiceClass);

@@ -84,19 +85,16 @@ abstract class AbstractControllerTestCase extends AbstractHttpControllerTestCase
        return $prophecy;
    }

    /**
     * @var EntityManager
     */
    private $em;
    protected ?EntityManager $em = null;

    /**
     * @param string $name
     * @return EntityManager
     */
    protected function em($name = 'orm_default')
    protected function em(): EntityManager
    {
        if (null === $this->em) {
            $this->em = $this->getApplicationServiceLocator()->get("doctrine.entitymanager.$name");
            try {
                $this->em = $this->getApplicationServiceLocator()->get("doctrine.entitymanager.orm_default");
            } catch (ContainerExceptionInterface $e) {
                throw new RuntimeException("Impossible d'obtenir l'entity manager orm_default !", null, $e);
            }
        }

        return $this->em;