Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
auth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
lib
unicaen
auth
Commits
bea3710e
Commit
bea3710e
authored
Jul 4, 2013
by
Bertrand Gauthier
Browse files
Options
Downloads
Patches
Plain Diff
Adapteurs d'authentification Db : tests unitaires.
parent
204a2491
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/UnicaenAuth/Authentication/Adapter/Db.php
+1
-1
1 addition, 1 deletion
src/UnicaenAuth/Authentication/Adapter/Db.php
tests/UnicaenAuthTest/Authentication/Adapter/DbTest.php
+94
-0
94 additions, 0 deletions
tests/UnicaenAuthTest/Authentication/Adapter/DbTest.php
with
95 additions
and
1 deletion
src/UnicaenAuth/Authentication/Adapter/Db.php
+
1
−
1
View file @
bea3710e
...
...
@@ -13,7 +13,7 @@ use ZfcUser\Options\AuthenticationOptionsInterface;
* Adpater d'authentification à partir de la base de données.
*
* Ajout par rapport à la classe mère : si aucune base de données ou table n'existe,
* l'authentification
d
e plante pas.
* l'authentification
n
e plante pas
(i.e. renvoit false)
.
*
* @author Bertrand GAUTHIER <bertrand.gauthier@unicaen.fr>
*/
...
...
This diff is collapsed.
Click to expand it.
tests/UnicaenAuthTest/Authentication/Adapter/DbTest.php
0 → 100644
+
94
−
0
View file @
bea3710e
<?php
namespace
UnicaenAuthTest\Authentication\Adapter
;
use
PDOException
;
use
PHPUnit_Framework_TestCase
;
use
UnicaenAuth\Authentication\Adapter\Db
;
use
UnicaenAuth\Options\ModuleOptions
;
use
Zend\Http\PhpEnvironment\Request
;
use
Zend\ServiceManager\Exception\ServiceNotFoundException
;
use
Zend\Stdlib\Parameters
;
use
ZfcUser\Authentication\Adapter\AdapterChainEvent
;
/**
* Description of DbTest
*
* @author Bertrand GAUTHIER <bertrand.gauthier at unicaen.fr>
*/
class
DbTest
extends
PHPUnit_Framework_TestCase
{
protected
$adapter
;
protected
$moduleOptions
;
protected
$mapper
;
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*/
protected
function
setUp
()
{
$this
->
moduleOptions
=
$moduleOptions
=
new
ModuleOptions
(
array
(
'cas'
=>
array
(
'connection'
=>
array
(
'default'
=>
array
(
'params'
=>
array
(
'hostname'
=>
'cas.unicaen.fr'
,
'port'
=>
443
,
'version'
=>
"2.0"
,
'uri'
=>
""
,
'debug'
=>
false
,
),
),
),
),
));
$this
->
mapper
=
$mapper
=
$this
->
getMock
(
'ZfcUser\Mapper\User'
,
array
(
'findByUsername'
,
'findByEmail'
));
$serviceManager
=
$this
->
getMock
(
'Zend\ServiceManager\ServiceManager'
,
array
(
'get'
));
$serviceManager
->
expects
(
$this
->
any
())
->
method
(
'get'
)
->
will
(
$this
->
returnCallback
(
function
(
$serviceName
)
use
(
$moduleOptions
,
$mapper
)
{
if
(
'zfcuser_module_options'
===
$serviceName
)
{
return
new
\ZfcUser\Options\ModuleOptions
();
}
if
(
'unicaen-auth_module_options'
===
$serviceName
)
{
return
$moduleOptions
;
}
if
(
'zfcuser_user_mapper'
===
$serviceName
)
{
return
$mapper
;
}
return
null
;
}));
$this
->
adapter
=
new
Db
();
$this
->
adapter
->
setServiceManager
(
$serviceManager
);
}
public
function
getException
()
{
return
array
(
array
(
new
PDOException
()),
array
(
new
ServiceNotFoundException
()),
);
}
/**
* @dataProvider getException
*/
public
function
testAuthenticateReturnsFalseIfExceptionThrown
(
$exception
)
{
$this
->
mapper
->
expects
(
$this
->
once
())
->
method
(
$this
->
logicalOr
(
'findByUsername'
,
'findByEmail'
))
->
will
(
$this
->
throwException
(
$exception
));
$request
=
new
Request
();
$request
->
setPost
(
new
Parameters
(
array
(
'identity'
=>
'bob'
,
'credential'
=>
"xxxxx"
)));
$event
=
new
AdapterChainEvent
();
$event
->
setRequest
(
$request
);
$result
=
$this
->
adapter
->
authenticate
(
$event
);
$this
->
assertFalse
(
$result
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment