Skip to content
Snippets Groups Projects
Select Git revision
  • d0a6223142c74eb06144cf7d62c18e15b46a46b7
  • master default protected
  • test
  • release_10.3.0
  • feature_module_doctorant
  • feature_module_admission
  • feature_fiche_rncp
  • feature_convention_mel_template
  • release_10.2.0
  • release_10.1.1
  • feature_portfolio
  • ameliorations_index_rapporteur
  • feature_flux_diplomation
  • feature_formation_export_xls
  • feature_fichiers
  • api_inscription_admin
  • feature_module_unicaen_maintenance_mode
  • dev
  • feature_renderer_template_variables
  • feature_notif_forcage_correc
  • feature_wf_rapport_activite
  • 10.2.1
  • 10.2.0
  • 10.1.0
  • 10.0.3
  • 10.0.2
  • 10.0.1
  • 10.0.0
  • 9.4.1
  • 9.4.0
  • 9.3.1
  • 9.3.0
  • 9.2.1
  • 9.2.0
  • 9.1.1
  • 9.1.0
  • 9.0.1
  • 9.0.0
  • 8.6.0
  • 8.5.1
  • 8.5.0
41 results

v1.2.4.md

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AbstractFactoryTest.php 3.32 KiB
    <?php
    namespace UnicaenAuthTest\Authentication\Adapter;
    
    use PHPUnit_Framework_TestCase;
    use UnicaenAuth\Authentication\Adapter\AbstractFactory;
    use UnicaenAuth\Service\User;
    use Zend\EventManager\EventManager;
    use Zend\EventManager\EventManagerAwareInterface;
    use Zend\ServiceManager\ServiceManager;
    
    /**
     * Description of AbstractFactoryTest
     *
     * @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
     */
    class AbstractFactoryTest extends PHPUnit_Framework_TestCase
    {
        protected $factory;
    
        protected function setUp()
        {
            $this->factory = new AbstractFactory();
        }
        
        public function getInvalidServiceClassName()
        {
            return array(
                'unknown-class'   => array('UnicaenAuth\Authentication\Adapter\Xxxx'),
                'wrong-namespace' => array('Any\Other\Namespaced\Class'),
            );
        }
        
        /**
         * @dataProvider getInvalidServiceClassName
         * @param string $serviceClassName
         */
        public function testCanRefuseCreatingServiceWithInvalidName($serviceClassName)
        {
            $this->assertFalse($this->factory->canCreateServiceWithName(new ServiceManager(), null, $serviceClassName));
        }
        
        public function getValidServiceClassName()
        {
            return array(
                'cas'  => array('UnicaenAuth\Authentication\Adapter\Cas'),
                'db'   => array('UnicaenAuth\Authentication\Adapter\Db'),
                'ldap' => array('UnicaenAuth\Authentication\Adapter\Ldap'),
            );
        }
        
        /**
         * @dataProvider getValidServiceClassName
         * @param string $serviceClassName
         */
        public function testCanAcceptCreatingServiceWithValidName($serviceClassName)
        {
            $this->assertTrue($this->factory->canCreateServiceWithName(new ServiceManager(), null, $serviceClassName));
        }
        
        /**
         * @dataProvider getInvalidServiceClassName
         * @expectedException \UnicaenApp\Exception
         * @param string $serviceClassName
         */
        public function testCreateServiceWithNameThrowsExceptionIfInvalidServiceSpecified($serviceClassName)
        {
            $this->factory->createServiceWithName(new ServiceManager(), null, $serviceClassName);
        }
        
        /**
         * @dataProvider getValidServiceClassName
         * @param string $serviceClassName
         */
        public function testCanCreateServiceWithName($serviceClassName)
        {
            $eventManager = new EventManager();
            
            $serviceLocator = $this->getMock('Zend\ServiceManager\ServiceManager', array('get'));
            $serviceLocator->expects($this->any())
                           ->method('get')
                           ->will($this->returnCallback(function($serviceName) use ($eventManager) {
                               if ('unicaen-auth_user_service' === $serviceName) {
                                   return new User();
                               }
                               if ('event_manager' === $serviceName) {
                                   return $eventManager;
                               }
                               return null;
                           }));
            
            $adapter = $this->factory->createServiceWithName($serviceLocator, null, $serviceClassName);
                           
            $this->assertInstanceOf($serviceClassName, $adapter);
            
            if ($adapter instanceof EventManagerAwareInterface) {
                $this->assertSame($eventManager, $adapter->getEventManager());
            }
        }
    }