Skip to content

Commit b31182d

Browse files
authored
Merge pull request #69 from lightSAML/maintenance
Support for Symfony 4 / update to lightsaml/symfony-bridge#1.3.0
2 parents b3cf8d9 + 37136e7 commit b31182d

11 files changed

Lines changed: 69 additions & 52 deletions

File tree

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ matrix:
1515
env: COMPOSER_FLAGS="--prefer-lowest"
1616

1717
before_install:
18-
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; else INI_FILE=/etc/hhvm/php.ini; fi;
19-
- echo "memory_limit = -1" >> $INI_FILE
20-
- echo "session.gc_probability = 0" >> $INI_FILE
18+
- echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
19+
- echo "session.gc_probability = 0" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
2120
- composer self-update
2221
- composer --version
2322
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer.phar; fi
2423
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then php php-cs-fixer.phar --version; fi
24+
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar; fi
2525

2626
install:
27-
- COMPOSER_ROOT_VERSION=dev-master composer update --prefer-source $COMPOSER_FLAGS
27+
- COMPOSER_ROOT_VERSION=dev-master composer update --prefer-source --no-interaction $COMPOSER_FLAGS
2828

2929
script:
3030
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then php php-cs-fixer.phar fix --dry-run -v; fi
3131
- if [ "$TRAVIS_PHP_VERSION" == "7.1" ]; then bin/phpunit --coverage-clover build/logs/clover.xml; else bin/phpunit; fi
3232

3333
after_script:
34-
- if [[ "$TRAVIS_PHP_VERSION" == "7.1" ]]; then php bin/coveralls -v; fi;
34+
- if [[ "$TRAVIS_PHP_VERSION" == "7.1" ]]; then php php-coveralls.phar -v; fi;

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
}
2020
},
2121
"require": {
22-
"php": ">=5.5.1",
23-
"symfony/framework-bundle": "~2.3|~3.0|~4.0",
24-
"symfony/security-bundle": "~2.3|~3.0|~4.0",
25-
"lightsaml/symfony-bridge": "~1.0"
22+
"php": ">=5.6",
23+
"symfony/framework-bundle": "~2.7|~3.0|~4.0",
24+
"symfony/security-bundle": "~2.7|~3.0|~4.0",
25+
"lightsaml/symfony-bridge": "~1.3"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "~4.6|~5.3",
29-
"symfony/symfony": "~2.3|~3.0|~4.0",
30-
"symfony/monolog-bundle": "~2.3|~3.0|~4.0",
31-
"satooshi/php-coveralls": "~0.6"
28+
"phpunit/phpunit": "^5.7",
29+
"sebastian/comparator": "^1.2.4|~2.0|~3.0",
30+
"symfony/symfony": "~2.7|~3.0|~4.0",
31+
"symfony/monolog-bundle": "~2.7|~3.0|~4.0"
3232
},
3333
"config": {
3434
"bin-dir": "bin"

src/LightSaml/SpBundle/Controller/DefaultController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function discoveryAction()
3131
{
3232
$parties = $this->get('lightsaml.container.build')->getPartyContainer()->getIdpEntityDescriptorStore()->all();
3333

34-
if (count($parties) == 1) {
34+
if (1 == count($parties)) {
3535
return $this->redirect($this->generateUrl('lightsaml_sp.login', ['idp' => $parties[0]->getEntityID()]));
3636
}
3737

src/LightSaml/SpBundle/Security/User/SimpleAttributeMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private function mapAttributeValues(array $attributes, Attribute $attribute)
6868
$key = $attribute->getName();
6969
$value = $attribute->getAllAttributeValues();
7070

71-
if (!array_key_exists($key, $attributes) && count($value) === 1) {
71+
if (!array_key_exists($key, $attributes) && 1 === count($value)) {
7272
$value = array_shift($value);
7373
}
7474

src/LightSaml/SpBundle/Security/User/SimpleUsernameMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function getUsernameFromAssertion(Assertion $assertion)
5959
if ($assertion->getSubject() &&
6060
$assertion->getSubject()->getNameID() &&
6161
$assertion->getSubject()->getNameID()->getValue() &&
62-
$assertion->getSubject()->getNameID()->getFormat() != SamlConstants::NAME_ID_FORMAT_TRANSIENT
62+
SamlConstants::NAME_ID_FORMAT_TRANSIENT != $assertion->getSubject()->getNameID()->getFormat()
6363
) {
6464
return $assertion->getSubject()->getNameID()->getValue();
6565
}

tests/LightSaml/SpBundle/Tests/Controller/DefaultControllerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public function test_metadata_action_returns_response_from_profile()
4545
*/
4646
private function getContainerMock()
4747
{
48-
return $this->getMock(\Symfony\Component\DependencyInjection\ContainerInterface::class);
48+
return $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
4949
}
5050

5151
/**
5252
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Builder\Profile\ProfileBuilderInterface
5353
*/
5454
private function getProfileBuilderMock()
5555
{
56-
return $this->getMock(\LightSaml\Builder\Profile\ProfileBuilderInterface::class);
56+
return $this->getMockBuilder(\LightSaml\Builder\Profile\ProfileBuilderInterface::class)->getMock();
5757
}
5858

5959
/**
@@ -71,14 +71,14 @@ private function getContextMock()
7171
*/
7272
private function getActionMock()
7373
{
74-
return $this->getMock(\LightSaml\Action\ActionInterface::class);
74+
return $this->getMockBuilder(\LightSaml\Action\ActionInterface::class)->getMock();
7575
}
7676

7777
/**
7878
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\Context\Profile\HttpResponseContext
7979
*/
8080
private function getHttpResponseContextMock()
8181
{
82-
return $this->getMock(\LightSaml\Context\Profile\HttpResponseContext::class);
82+
return $this->getMockBuilder(\LightSaml\Context\Profile\HttpResponseContext::class)->getMock();
8383
}
8484
}

tests/LightSaml/SpBundle/Tests/Functional/FunctionalTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
<?php
22

3-
namespace LightSaml\SpBundle\Tests\Controller;
3+
namespace LightSaml\SpBundle\Tests\Functional;
44

55
use LightSaml\State\Sso\SsoSessionState;
66
use LightSaml\State\Sso\SsoState;
77
use LightSaml\Store\Sso\SsoStateStoreInterface;
88
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9+
use Symfony\Component\Filesystem\Filesystem;
910
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1011

1112
class FunctionalTest extends WebTestCase
1213
{
1314
const OWN_ENTITY_ID = 'https://localhost/lightSAML/SPBundle';
1415

16+
protected function setUp()
17+
{
18+
parent::setUp();
19+
require_once __DIR__.'/app/AppKernel.php';
20+
$_SERVER['KERNEL_CLASS'] = \AppKernel::class;
21+
$_SERVER['KERNEL_DIR'] = __DIR__.'/app';
22+
$fs = new Filesystem();
23+
$fs->remove(__DIR__.'/app/cache');
24+
}
25+
26+
1527
public function test_metadata()
1628
{
1729
$client = static::createClient();
@@ -52,7 +64,7 @@ public function test_discovery()
5264
public function test_login()
5365
{
5466
$client = static::createClient();
55-
$client->getContainer()->set('session', $sessionMock = $this->getMock(SessionInterface::class));
67+
$client->getContainer()->set('session', $sessionMock = $this->getMockBuilder(SessionInterface::class)->getMock());
5668

5769
$crawler = $client->request('GET', '/saml/login?idp=https://localhost/lightSAML/lightSAML-IDP');
5870

@@ -80,7 +92,7 @@ public function test_sessions()
8092
$ssoState->addSsoSession((new SsoSessionState())->setIdpEntityId('idp1')->setSpEntityId('sp1'));
8193
$ssoState->addSsoSession((new SsoSessionState())->setIdpEntityId('idp2')->setSpEntityId('sp2'));
8294

83-
$ssoStateStoreMock = $this->getMock(SsoStateStoreInterface::class);
95+
$ssoStateStoreMock = $this->getMockBuilder(SsoStateStoreInterface::class)->getMock();
8496
$ssoStateStoreMock->method('get')
8597
->willReturn($ssoState);
8698

tests/LightSaml/SpBundle/Tests/Functional/app/config.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ framework:
55
csrf_protection: ~
66
templating: { engines: ['twig'] }
77
session:
8-
handler_id: session.handler.native_file
8+
storage_id: session.mock_storage
99

1010
monolog:
1111
handlers:
@@ -15,7 +15,7 @@ monolog:
1515
handler: nested
1616
nested:
1717
type: stream
18-
path: %kernel.logs_dir%/%kernel.environment%.log
18+
path: "%kernel.logs_dir%/%kernel.environment%.log"
1919
level: debug
2020

2121
security:
@@ -32,18 +32,23 @@ light_saml_symfony_bridge:
3232
entity_id: https://localhost/lightSAML/SPBundle
3333
credentials:
3434
-
35-
certificate: %kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/saml.crt
36-
key: %kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/saml.key
35+
certificate: "%kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/saml.crt"
36+
key: "%kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/saml.key"
3737
password: ~
3838
party:
3939
idp:
4040
files:
41-
- %kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/openidp.feide.no.xml
42-
- %kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/localhost-lightsaml-lightsaml-idp.xml
43-
- %kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/testshib-providers.xml
41+
- "%kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/openidp.feide.no.xml"
42+
- "%kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/localhost-lightsaml-lightsaml-idp.xml"
43+
- "%kernel.root_dir%/../../../../../../vendor/lightsaml/lightsaml/web/sp/testshib-providers.xml"
4444
store:
4545
id_state: id_store
4646

4747
services:
48+
session.mock_storage:
49+
class: Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage
4850
id_store:
4951
class: LightSaml\Store\Id\IdArrayStore
52+
lightsaml.store.sso_state:
53+
class: LightSaml\Store\Sso\SsoStateFixedStore
54+
public: true

tests/LightSaml/SpBundle/Tests/LightSamlSpBundleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public function test_build_adds_security_extension()
2828
*/
2929
private function getContainerBuilderMock()
3030
{
31-
return $this->getMock(\Symfony\Component\DependencyInjection\ContainerBuilder::class);
31+
return $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerBuilder::class)->getMock();
3232
}
3333

3434
/**
3535
* @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension
3636
*/
3737
private function getExtensionMock()
3838
{
39-
return $this->getMock(\Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension::class);
39+
return $this->getMockBuilder(\Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension::class)->getMock();
4040
}
4141
}

tests/LightSaml/SpBundle/Tests/Security/Authentication/Provider/LightsSamlSpAuthenticationProviderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public function test_calls_token_factory_if_provided()
365365
public function test_throws_logic_exception_on_unsupported_token()
366366
{
367367
$provider = new LightsSamlSpAuthenticationProvider('main');
368-
$provider->authenticate($this->getMock(TokenInterface::class));
368+
$provider->authenticate($this->getMockBuilder(TokenInterface::class)->getMock());
369369
}
370370

371371
/**
@@ -460,54 +460,54 @@ public function test_throws_authentication_exception_when_unable_to_resolve_user
460460
*/
461461
private function getUserCheckerMock()
462462
{
463-
return $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
463+
return $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
464464
}
465465

466466
/**
467467
* @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Security\Core\User\UserInterface
468468
*/
469469
private function getUserMock()
470470
{
471-
return $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
471+
return $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserInterface::class)->getMock();
472472
}
473473

474474
/**
475475
* @return \PHPUnit_Framework_MockObject_MockObject|\Symfony\Component\Security\Core\User\UserProviderInterface
476476
*/
477477
private function getUserProviderMock()
478478
{
479-
return $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
479+
return $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserProviderInterface::class)->getMock();
480480
}
481481

482482
/**
483483
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\SpBundle\Security\User\UsernameMapperInterface
484484
*/
485485
private function getUsernameMapperMock()
486486
{
487-
return $this->getMock(UsernameMapperInterface::class);
487+
return $this->getMockBuilder(UsernameMapperInterface::class)->getMock();
488488
}
489489

490490
/**
491491
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\SpBundle\Security\User\UserCreatorInterface
492492
*/
493493
private function getUserCreatorMock()
494494
{
495-
return $this->getMock(UserCreatorInterface::class);
495+
return $this->getMockBuilder(UserCreatorInterface::class)->getMock();
496496
}
497497

498498
/**
499499
* @return \PHPUnit_Framework_MockObject_MockObject|\LightSaml\SpBundle\Security\User\AttributeMapperInterface
500500
*/
501501
private function getAttributeMapperMock()
502502
{
503-
return $this->getMock(AttributeMapperInterface::class);
503+
return $this->getMockBuilder(AttributeMapperInterface::class)->getMock();
504504
}
505505

506506
/**
507507
* @return \PHPUnit_Framework_MockObject_MockObject|SamlSpTokenFactoryInterface
508508
*/
509509
private function getTokenFactoryMock()
510510
{
511-
return $this->getMock(SamlSpTokenFactoryInterface::class);
511+
return $this->getMockBuilder(SamlSpTokenFactoryInterface::class)->getMock();
512512
}
513513
}

0 commit comments

Comments
 (0)