Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
lib
unicaen
auth
Commits
ebc17517
Commit
ebc17517
authored
Oct 03, 2013
by
Bertrand Gauthier
Browse files
Utilisation de factories pour les aides de vue.
Tests unitaires correspondants.
parent
7bfdc98b
Changes
11
Show whitespace changes
Inline
Side-by-side
Module.php
View file @
ebc17517
...
...
@@ -128,25 +128,11 @@ class Module implements ConfigProviderInterface, ViewHelperProviderInterface, Se
{
return
array
(
'factories'
=>
array
(
'userConnection'
=>
function
(
HelperPluginManager
$sm
)
{
return
new
View\Helper\UserConnection
(
$sm
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
));
},
'userCurrent'
=>
function
(
HelperPluginManager
$sm
)
{
return
new
View\Helper\UserCurrent
(
$sm
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
));
},
'userStatus'
=>
function
(
HelperPluginManager
$sm
)
{
return
new
View\Helper\UserStatus
(
$sm
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
));
},
'userProfile'
=>
function
(
HelperPluginManager
$sm
)
{
$helper
=
new
View\Helper\UserProfile
(
$sm
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
));
$helper
->
setIdentityProvider
(
$sm
->
getServiceLocator
()
->
get
(
'BjyAuthorize\Service\Authorize'
)
->
getIdentityProvider
());
return
$helper
;
},
'userInfo'
=>
function
(
HelperPluginManager
$sm
)
{
$helper
=
new
View\Helper\UserInfo
(
$sm
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
));
$helper
->
setMapperStructure
(
$sm
->
getServiceLocator
()
->
get
(
'ldap_structure_mapper'
));
return
$helper
;
},
'userConnection'
=>
'UnicaenAuth\View\Helper\UserConnectionFactory'
,
'userCurrent'
=>
'UnicaenAuth\View\Helper\UserCurrentFactory'
,
'userStatus'
=>
'UnicaenAuth\View\Helper\UserStatusFactory'
,
'userProfile'
=>
'UnicaenAuth\View\Helper\UserProfileFactory'
,
'userInfo'
=>
'UnicaenAuth\View\Helper\UserInfoFactory'
,
),
'invokables'
=>
array
(
'appConnection'
=>
'UnicaenAuth\View\Helper\AppConnection'
,
...
...
src/UnicaenAuth/View/Helper/UserConnectionFactory.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAuth\View\Helper
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
/**
* Description of UserConnectionFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserConnectionFactory
implements
FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserConnection
*/
public
function
createService
(
ServiceLocatorInterface
$helperPluginManager
)
{
$authService
=
$helperPluginManager
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
);
return
new
UserConnection
(
$authService
);
}
}
\ No newline at end of file
src/UnicaenAuth/View/Helper/UserCurrentFactory.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAuth\View\Helper
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
/**
* Description of UserCurrentFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserCurrentFactory
implements
FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserCurrent
*/
public
function
createService
(
ServiceLocatorInterface
$helperPluginManager
)
{
$authService
=
$helperPluginManager
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
);
return
new
UserCurrent
(
$authService
);
}
}
\ No newline at end of file
src/UnicaenAuth/View/Helper/UserInfoFactory.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAuth\View\Helper
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
/**
* Description of UserInfoFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserInfoFactory
implements
FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserInfo
*/
public
function
createService
(
ServiceLocatorInterface
$helperPluginManager
)
{
$serviceLocator
=
$helperPluginManager
->
getServiceLocator
();
$authService
=
$serviceLocator
->
get
(
'zfcuser_auth_service'
);
$mapper
=
$serviceLocator
->
get
(
'ldap_structure_mapper'
);
$helper
=
new
UserInfo
(
$authService
);
$helper
->
setMapperStructure
(
$mapper
);
return
$helper
;
}
}
\ No newline at end of file
src/UnicaenAuth/View/Helper/UserProfileFactory.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAuth\View\Helper
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
/**
* Description of UserProfileFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserProfileFactory
implements
FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserProfile
*/
public
function
createService
(
ServiceLocatorInterface
$helperPluginManager
)
{
$serviceLocator
=
$helperPluginManager
->
getServiceLocator
();
$authService
=
$serviceLocator
->
get
(
'zfcuser_auth_service'
);
$authorize
=
$serviceLocator
->
get
(
'BjyAuthorize\Service\Authorize'
);
$identityProvider
=
$authorize
->
getIdentityProvider
();
$helper
=
new
UserProfile
(
$authService
);
$helper
->
setIdentityProvider
(
$identityProvider
);
return
$helper
;
}
}
\ No newline at end of file
src/UnicaenAuth/View/Helper/UserStatusFactory.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAuth\View\Helper
;
use
Zend\ServiceManager\FactoryInterface
;
use
Zend\ServiceManager\ServiceLocatorInterface
;
/**
* Description of UserStatusFactory
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserStatusFactory
implements
FactoryInterface
{
/**
* Create service
*
* @param ServiceLocatorInterface $helperPluginManager
* @return UserStatus
*/
public
function
createService
(
ServiceLocatorInterface
$helperPluginManager
)
{
$authService
=
$helperPluginManager
->
getServiceLocator
()
->
get
(
'zfcuser_auth_service'
);
return
new
UserStatus
(
$authService
);
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserConnectionFactoryTest.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAppTest\View\Helper
;
use
UnicaenAppTest\View\Helper\BaseServiceFactoryTest
;
/**
* Description of UserConnectionFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserConnectionFactoryTest
extends
BaseServiceFactoryTest
{
protected
$factoryClass
=
'UnicaenAuth\View\Helper\UserConnectionFactory'
;
protected
$serviceClass
=
'UnicaenAuth\View\Helper\UserConnection'
;
public
function
testCanCreateService
()
{
$authService
=
$this
->
getMock
(
'Zend\Authentication\AuthenticationService'
,
array
());
$this
->
serviceManager
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
'zfcuser_auth_service'
)
->
will
(
$this
->
returnValue
(
$authService
));
$service
=
$this
->
factory
->
createService
(
$this
->
pluginManager
);
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserCurrentFactoryTest.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAppTest\View\Helper
;
use
UnicaenAppTest\View\Helper\BaseServiceFactoryTest
;
/**
* Description of UserCurrentFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserCurrentFactoryTest
extends
BaseServiceFactoryTest
{
protected
$factoryClass
=
'UnicaenAuth\View\Helper\UserCurrentFactory'
;
protected
$serviceClass
=
'UnicaenAuth\View\Helper\UserCurrent'
;
public
function
testCanCreateService
()
{
$authService
=
$this
->
getMock
(
'Zend\Authentication\AuthenticationService'
,
array
());
$this
->
serviceManager
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
'zfcuser_auth_service'
)
->
will
(
$this
->
returnValue
(
$authService
));
$service
=
$this
->
factory
->
createService
(
$this
->
pluginManager
);
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserInfoFactoryTest.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAppTest\View\Helper
;
use
UnicaenAppTest\View\Helper\BaseServiceFactoryTest
;
/**
* Description of UserInfoFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserInfoFactoryTest
extends
BaseServiceFactoryTest
{
protected
$factoryClass
=
'UnicaenAuth\View\Helper\UserInfoFactory'
;
protected
$serviceClass
=
'UnicaenAuth\View\Helper\UserInfo'
;
public
function
testCanCreateService
()
{
$authService
=
$this
->
getMock
(
'Zend\Authentication\AuthenticationService'
,
array
());
$mapper
=
$this
->
getMock
(
'UnicaenApp\Mapper\Ldap\Structure'
,
array
());
$this
->
serviceManager
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'get'
)
->
will
(
$this
->
returnValueMap
(
array
(
array
(
'zfcuser_auth_service'
,
$authService
),
array
(
'ldap_structure_mapper'
,
$mapper
))));
$service
=
$this
->
factory
->
createService
(
$this
->
pluginManager
);
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
$this
->
assertSame
(
$mapper
,
$service
->
getMapperStructure
());
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserProfileFactoryTest.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAppTest\View\Helper
;
use
UnicaenAppTest\View\Helper\BaseServiceFactoryTest
;
/**
* Description of UserProfileFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserProfileFactoryTest
extends
BaseServiceFactoryTest
{
protected
$factoryClass
=
'UnicaenAuth\View\Helper\UserProfileFactory'
;
protected
$serviceClass
=
'UnicaenAuth\View\Helper\UserProfile'
;
public
function
testCanCreateService
()
{
$authService
=
$this
->
getMock
(
'Zend\Authentication\AuthenticationService'
,
array
());
$authorize
=
$this
->
getMock
(
'BjyAuthorize\Service\Authorize'
,
array
(
'getIdentityProvider'
),
array
(),
''
,
false
);
$identityProvider
=
$this
->
getMockForAbstractClass
(
'BjyAuthorize\Provider\Identity\ProviderInterface'
,
array
());
$authorize
->
expects
(
$this
->
once
())
->
method
(
'getIdentityProvider'
)
->
will
(
$this
->
returnValue
(
$identityProvider
));
$this
->
serviceManager
->
expects
(
$this
->
exactly
(
2
))
->
method
(
'get'
)
->
will
(
$this
->
returnValueMap
(
array
(
array
(
'zfcuser_auth_service'
,
$authService
),
array
(
'BjyAuthorize\Service\Authorize'
,
$authorize
))));
$service
=
$this
->
factory
->
createService
(
$this
->
pluginManager
);
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
$this
->
assertSame
(
$identityProvider
,
$service
->
getIdentityProvider
());
}
}
\ No newline at end of file
tests/UnicaenAuthTest/View/Helper/UserStatusFactoryTest.php
0 → 100644
View file @
ebc17517
<?php
namespace
UnicaenAppTest\View\Helper
;
use
UnicaenAppTest\View\Helper\BaseServiceFactoryTest
;
/**
* Description of UserStatusFactoryTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
UserStatusFactoryTest
extends
BaseServiceFactoryTest
{
protected
$factoryClass
=
'UnicaenAuth\View\Helper\UserStatusFactory'
;
protected
$serviceClass
=
'UnicaenAuth\View\Helper\UserStatus'
;
public
function
testCanCreateService
()
{
$authService
=
$this
->
getMock
(
'Zend\Authentication\AuthenticationService'
,
array
());
$this
->
serviceManager
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
'zfcuser_auth_service'
)
->
will
(
$this
->
returnValue
(
$authService
));
$service
=
$this
->
factory
->
createService
(
$this
->
pluginManager
);
$this
->
assertInstanceOf
(
$this
->
serviceClass
,
$service
);
}
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment