Skip to content

Commit bae57ce

Browse files
committed
CI & tests
1 parent ff02012 commit bae57ce

File tree

12 files changed

+458
-1
lines changed

12 files changed

+458
-1
lines changed

.scrutinizer.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
checks:
2+
php: true
3+
tools:
4+
external_code_coverage: true
5+
filter:
6+
paths: ["src/*"]

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: php
2+
3+
php:
4+
- 5.5
5+
- 5.6
6+
7+
before_script:
8+
- COMPOSER_ROOT_VERSION=dev-master composer install
9+
10+
script:
11+
- bin/phpcs --standard=PSR2 -n src
12+
- bin/phpunit --coverage-clover build/logs/clover.xml
13+
14+
after_script:
15+
- wget https://scrutinizer-ci.com/ocular.phar
16+
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml

autoload.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// if library is in dev environement with its own vendor, include its autoload
4+
if (file_exists(__DIR__ . '/vendor')) {
5+
require_once __DIR__ . '/vendor/autoload.php';
6+
} // if library is in vendor of another project, include the global autolaod
7+
else {
8+
require_once __DIR__ . '/../../autoload.php';
9+
}

build/logs/junit.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="Project Test Suite" tests="20" assertions="29" failures="0" errors="0" time="0.109263">
4+
<testsuite name="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\CreateLogoutRequestActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\CreateLogoutRequestActionTest.php" tests="2" assertions="1" failures="0" errors="0" time="0.027298">
5+
<testcase name="test_constructs_with_logger" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\CreateLogoutRequestActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\CreateLogoutRequestActionTest.php" line="13" assertions="0" time="0.018557"/>
6+
<testcase name="test_creates_logout_request_as_outbound_message" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\CreateLogoutRequestActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\CreateLogoutRequestActionTest.php" line="18" assertions="1" time="0.008741"/>
7+
</testsuite>
8+
<testsuite name="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest.php" tests="3" assertions="6" failures="0" errors="0" time="0.028111">
9+
<testcase name="test_constructs_with_logger_logout_resolver_and_proceed_action" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest.php" line="16" assertions="0" time="0.006691"/>
10+
<testcase name="test_sets_all_sessions_terminated_flag_when_no_sessions" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest.php" line="25" assertions="2" time="0.011157"/>
11+
<testcase name="test_sets_resolved_session_to_logout_context_and_calls_proceed_action" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\LogoutResolveActionTest.php" line="39" assertions="4" time="0.010263"/>
12+
</testsuite>
13+
<testsuite name="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNameIdActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNameIdActionTest.php" tests="2" assertions="3" failures="0" errors="0" time="0.007492">
14+
<testcase name="test_constructs_with_logger" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNameIdActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNameIdActionTest.php" line="14" assertions="0" time="0.002887"/>
15+
<testcase name="test_sets_name_id_to_outbound_logout_request" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNameIdActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNameIdActionTest.php" line="19" assertions="3" time="0.004605"/>
16+
</testsuite>
17+
<testsuite name="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNotOnOrAfterActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNotOnOrAfterActionTest.php" tests="2" assertions="2" failures="0" errors="0" time="0.008904">
18+
<testcase name="test_constructs_with_logger_time_provider_and_integer" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNotOnOrAfterActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNotOnOrAfterActionTest.php" line="14" assertions="0" time="0.004792"/>
19+
<testcase name="test_sets_not_on_or_after_to_outbound_logout_request" class="LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNotOnOrAfterActionTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest\SetNotOnOrAfterActionTest.php" line="23" assertions="2" time="0.004112"/>
20+
</testsuite>
21+
<testsuite name="LightSaml\Logout\Tests\Resolver\Logout\LogoutSessionResolverTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Resolver\Logout\LogoutSessionResolverTest.php" tests="10" assertions="16" failures="0" errors="0" time="0.035940">
22+
<testcase name="test_constructs_with_state_store" class="LightSaml\Logout\Tests\Resolver\Logout\LogoutSessionResolverTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Resolver\Logout\LogoutSessionResolverTest.php" line="12" assertions="0" time="0.005159"/>
23+
<testcase name="test_returns_null_on_empty_sessions" class="LightSaml\Logout\Tests\Resolver\Logout\LogoutSessionResolverTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\Resolver\Logout\LogoutSessionResolverTest.php" line="17" assertions="1" time="0.002902"/>
24+
<testsuite name="LightSaml\Logout\Tests\Resolver\Logout\LogoutSessionResolverTest::test_resolution" tests="8" assertions="15" failures="0" errors="0" time="0.027879">
25+
<testcase name="test_resolution with data set #0" assertions="1" time="0.002786"/>
26+
<testcase name="test_resolution with data set #1" assertions="2" time="0.003166"/>
27+
<testcase name="test_resolution with data set #2" assertions="2" time="0.003172"/>
28+
<testcase name="test_resolution with data set #3" assertions="2" time="0.003858"/>
29+
<testcase name="test_resolution with data set #4" assertions="2" time="0.003275"/>
30+
<testcase name="test_resolution with data set #5" assertions="2" time="0.004068"/>
31+
<testcase name="test_resolution with data set #6" assertions="2" time="0.003018"/>
32+
<testcase name="test_resolution with data set #7" assertions="2" time="0.004536"/>
33+
</testsuite>
34+
</testsuite>
35+
<testsuite name="LightSaml\Logout\Tests\RootDummyTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\RootDummyTest.php" tests="1" assertions="1" failures="0" errors="0" time="0.001518">
36+
<testcase name="test_dummy" class="LightSaml\Logout\Tests\RootDummyTest" file="D:\www\home\lightsaml\lightSAML-logout\tests\LightSaml\Logout\Tests\RootDummyTest.php" line="7" assertions="1" time="0.001518"/>
37+
</testsuite>
38+
</testsuite>
39+
</testsuites>

phpunit.xml.dist

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit
5+
backupGlobals = "false"
6+
backupStaticAttributes = "false"
7+
colors = "false"
8+
convertErrorsToExceptions = "true"
9+
convertNoticesToExceptions = "true"
10+
convertWarningsToExceptions = "true"
11+
processIsolation = "false"
12+
stopOnFailure = "false"
13+
syntaxCheck = "false"
14+
bootstrap = "autoload.php"
15+
>
16+
17+
<logging>
18+
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
19+
</logging>
20+
21+
<testsuites>
22+
<testsuite name="Project Test Suite">
23+
<directory>tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
27+
<!--
28+
<php>
29+
<server name="KERNEL_DIR" value="/path/to/your/app/" />
30+
</php>
31+
-->
32+
33+
<filter>
34+
<whitelist>
35+
<directory>src</directory>
36+
</whitelist>
37+
</filter>
38+
39+
40+
</phpunit>

src/LightSaml/Logout/Action/Profile/Outbound/LogoutRequest/LogoutResolveAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use LightSaml\Action\ActionInterface;
66
use LightSaml\Action\Profile\AbstractProfileAction;
77
use LightSaml\Context\Profile\ProfileContext;
8-
use LightSaml\Resolver\Logout\LogoutSessionResolverInterface;
8+
use LightSaml\Logout\Resolver\Logout\LogoutSessionResolverInterface;
99
use Psr\Log\LoggerInterface;
1010

1111
class LogoutResolveAction extends AbstractProfileAction
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest;
4+
5+
use LightSaml\Context\Profile\ProfileContext;
6+
use LightSaml\Logout\Action\Profile\Outbound\LogoutRequest\CreateLogoutRequestAction;
7+
use LightSaml\Model\Protocol\LogoutRequest;
8+
use LightSaml\Profile\Profiles;
9+
use Psr\Log\LoggerInterface;
10+
11+
class CreateLogoutRequestActionTest extends \PHPUnit_Framework_TestCase
12+
{
13+
public function test_constructs_with_logger()
14+
{
15+
new CreateLogoutRequestAction($this->getLoggerMock());
16+
}
17+
18+
public function test_creates_logout_request_as_outbound_message()
19+
{
20+
$action = new CreateLogoutRequestAction($this->getLoggerMock());
21+
$context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
22+
$action->execute($context);
23+
24+
$this->assertInstanceOf(LogoutRequest::class, $context->getOutboundMessage());
25+
}
26+
27+
/**
28+
* @return \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface
29+
*/
30+
private function getLoggerMock()
31+
{
32+
return $this->getMock(LoggerInterface::class);
33+
}
34+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest;
4+
5+
use LightSaml\Action\ActionInterface;
6+
use LightSaml\Context\Profile\ProfileContext;
7+
use LightSaml\Logout\Action\Profile\Outbound\LogoutRequest\LogoutResolveAction;
8+
use LightSaml\Logout\Resolver\Logout\LogoutSessionResolverInterface;
9+
use LightSaml\Model\Metadata\EntityDescriptor;
10+
use LightSaml\Profile\Profiles;
11+
use LightSaml\State\Sso\SsoSessionState;
12+
use Psr\Log\LoggerInterface;
13+
14+
class LogoutResolveActionTest extends \PHPUnit_Framework_TestCase
15+
{
16+
public function test_constructs_with_logger_logout_resolver_and_proceed_action()
17+
{
18+
new LogoutResolveAction(
19+
$this->getLoggerMock(),
20+
$this->getLogoutResolverMock(),
21+
$this->getActionMock()
22+
);
23+
}
24+
25+
public function test_sets_all_sessions_terminated_flag_when_no_sessions()
26+
{
27+
$loggerMock = $this->getLoggerMock();
28+
$resolverMock = $this->getLogoutResolverMock();
29+
$proceedActionMock = $this->getActionMock();
30+
$proceedActionMock->expects($this->never())->method('execute');
31+
32+
$context = $this->buildContext();
33+
$action = new LogoutResolveAction($loggerMock, $resolverMock, $proceedActionMock);
34+
$action->execute($context);
35+
36+
$this->assertTrue($context->getLogoutContext()->areAllSsoSessionsTerminated());
37+
}
38+
39+
public function test_sets_resolved_session_to_logout_context_and_calls_proceed_action()
40+
{
41+
$context = $this->buildContext();
42+
43+
$loggerMock = $this->getLoggerMock();
44+
$resolverMock = $this->getLogoutResolverMock();
45+
$proceedActionMock = $this->getActionMock();
46+
47+
$session = new SsoSessionState();
48+
49+
$resolverMock->expects($this->once())
50+
->method('resolve')
51+
->with($context->getOwnEntityDescriptor()->getEntityID())
52+
->willReturn($session)
53+
;
54+
55+
$proceedActionMock->expects($this->once())
56+
->method('execute')
57+
->with($context)
58+
;
59+
60+
$action = new LogoutResolveAction($loggerMock, $resolverMock, $proceedActionMock);
61+
$action->execute($context);
62+
63+
$this->assertNotNull($context->getLogoutContext()->getSsoSessionState());
64+
$this->assertSame($session, $context->getLogoutContext()->getSsoSessionState());
65+
}
66+
67+
/**
68+
* @param string $ownEntityId
69+
*
70+
* @return ProfileContext
71+
*/
72+
private function buildContext($ownEntityId = 'own.entity.id')
73+
{
74+
$context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
75+
$context->getOwnEntityContext()->setEntityDescriptor(new EntityDescriptor($ownEntityId));
76+
77+
return $context;
78+
}
79+
80+
/**
81+
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Action\ActionInterface
82+
*/
83+
private function getActionMock()
84+
{
85+
return $this->getMock(ActionInterface::class);
86+
}
87+
88+
/**
89+
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Logout\Resolver\Logout\LogoutSessionResolverInterface
90+
*/
91+
private function getLogoutResolverMock()
92+
{
93+
return $this->getMock(LogoutSessionResolverInterface::class);
94+
}
95+
96+
/**
97+
* @return \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface
98+
*/
99+
private function getLoggerMock()
100+
{
101+
return $this->getMock(LoggerInterface::class);
102+
}
103+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest;
4+
5+
use LightSaml\Context\Profile\ProfileContext;
6+
use LightSaml\Logout\Action\Profile\Outbound\LogoutRequest\SetNameIdAction;
7+
use LightSaml\Model\Protocol\LogoutRequest;
8+
use LightSaml\Profile\Profiles;
9+
use LightSaml\State\Sso\SsoSessionState;
10+
use Psr\Log\LoggerInterface;
11+
12+
class SetNameIdActionTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function test_constructs_with_logger()
15+
{
16+
new SetNameIdAction($this->getLoggerMock());
17+
}
18+
19+
public function test_sets_name_id_to_outbound_logout_request()
20+
{
21+
$context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
22+
$context->getOutboundContext()->setMessage($logoutRequest = new LogoutRequest());
23+
$context->getLogoutContext()->setSsoSessionState(
24+
(new SsoSessionState())
25+
->setNameId($nameId = 'name.id')
26+
->setNameIdFormat($nameIdFormat = 'name.id.format')
27+
);
28+
29+
$action = new SetNameIdAction($this->getLoggerMock());
30+
$action->execute($context);
31+
32+
$this->assertNotNull($logoutRequest->getNameID());
33+
$this->assertEquals($nameId, $logoutRequest->getNameID()->getValue());
34+
$this->assertEquals($nameIdFormat, $logoutRequest->getNameID()->getFormat());
35+
}
36+
37+
/**
38+
* @return \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface
39+
*/
40+
private function getLoggerMock()
41+
{
42+
return $this->getMock(LoggerInterface::class);
43+
}
44+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace LightSaml\Logout\Tests\Action\Profile\Outbound\LogoutRequest;
4+
5+
use LightSaml\Context\Profile\ProfileContext;
6+
use LightSaml\Logout\Action\Profile\Outbound\LogoutRequest\SetNotOnOrAfterAction;
7+
use LightSaml\Model\Protocol\LogoutRequest;
8+
use LightSaml\Profile\Profiles;
9+
use LightSaml\Provider\TimeProvider\TimeProviderInterface;
10+
use Psr\Log\LoggerInterface;
11+
12+
class SetNotOnOrAfterActionTest extends \PHPUnit_Framework_TestCase
13+
{
14+
public function test_constructs_with_logger_time_provider_and_integer()
15+
{
16+
new SetNotOnOrAfterAction(
17+
$this->getLoggerMock(),
18+
$this->getTimeProviderMock(),
19+
100
20+
);
21+
}
22+
23+
public function test_sets_not_on_or_after_to_outbound_logout_request()
24+
{
25+
$timeProviderMock = $this->getTimeProviderMock();
26+
$action = new SetNotOnOrAfterAction($this->getLoggerMock(), $timeProviderMock, $skew = 100);
27+
28+
$context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
29+
$context->getOutboundContext()->setMessage($logoutRequest = new LogoutRequest());
30+
31+
$timeProviderMock->expects($this->once())
32+
->method('getTimestamp')
33+
->willReturn($baseTimestamp = 1445953125);
34+
35+
$action->execute($context);
36+
37+
$expectedTimestamp = $baseTimestamp + $skew;
38+
39+
$this->assertEquals($expectedTimestamp, $logoutRequest->getNotOnOrAfterTimestamp());
40+
}
41+
42+
/**
43+
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Provider\TimeProvider\TimeProviderInterface
44+
*/
45+
private function getTimeProviderMock()
46+
{
47+
return $this->getMock(TimeProviderInterface::class);
48+
}
49+
50+
/**
51+
* @return \PHPUnit_Framework_MockObject_MockObject|\Psr\Log\LoggerInterface
52+
*/
53+
private function getLoggerMock()
54+
{
55+
return $this->getMock(LoggerInterface::class);
56+
}
57+
}

0 commit comments

Comments
 (0)