Skip to content
Snippets Groups Projects
Select Git revision
  • c710b8193f9262b58b83a1ac5da19e768d1fa4c4
  • master default protected
  • main
  • update_github_actions
  • 144_rocky8_support
  • 195-update-pdk-to-300
  • 144-rocky8
  • add_test_github_test_workflow
  • pdk_2.4.0
  • fix_unclosed_let_block_in_defines_client_spec
  • validation_fixes
  • freeradius_3_0_21_config_updates
  • data_types
  • PrepareBuster
  • travis
  • 4.0.1
  • 4.0.0
  • 3.9.2
  • 3.9.1
  • 3.9.0
  • 3.8.2
  • 3.8.1
  • 3.8.0
  • 3.7.0
  • 3.6.0
  • 3.5.0
  • 3.4.3
  • 3.4.2
  • 3.4.1
  • 3.4.0
  • 3.3.0
  • 3.2.0
  • 3.1.0
  • 3.0.0
  • 2.3.1
35 results

blank.pp

Blame
  • 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;
        }
    }