diff --git a/.travis.yml b/.travis.yml index 2fdb0214..5bb3c5f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ php: - 7.2 - 7.3 - 7.4 + - 8.0 before_install: - composer self-update @@ -19,8 +20,8 @@ install: script: - if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then php php-cs-fixer.phar fix --dry-run -v; fi - - if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then bin/phpunit --coverage-clover build/logs/clover.xml; fi - - if [ "$TRAVIS_PHP_VERSION" != "7.2" ]; then bin/phpunit; fi + - if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi + - if [ "$TRAVIS_PHP_VERSION" != "7.2" ]; then vendor/bin/phpunit; fi after_script: - if [ "$TRAVIS_PHP_VERSION" == "7.2" ]; then php php-coveralls.phar -v; fi diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index bfb8fa19..189718ba 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -6,3 +6,6 @@ CHANGELOG for 2.0.x 2.0.1 (2021-04-07) * [CodeStyle] Clean code with php-cs-fixer + +2.1.0 (2021-04-07) +* [NewFeature] Update PHPUnit 8.4+ diff --git a/composer.json b/composer.json index 0819cbb7..3cce07e5 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,14 @@ }, "autoload": { "psr-0": { - "LightSaml\\Tests\\": "tests/", "LightSaml\\": "src/" } }, + "autoload-dev": { + "psr-0": { + "LightSaml\\Tests\\": "tests/" + } + }, "require": { "php": ">=7.2.5", "robrichards/xmlseclibs": "~2.0|~3.0|~4.0", @@ -34,16 +38,13 @@ "symfony/dom-crawler": "~5.0", "symfony/css-selector": "~5.0", "pimple/pimple": "~3.0", - "phpunit/phpunit": "~5.7|~7", - "monolog/monolog": "~1.3" + "phpunit/phpunit": "^8.4", + "monolog/monolog": "^2.0.0" }, "suggest": { "lightsaml/symfony-bridge": "Symfony 2 build container bridge", "lightsaml/sp-bundle": "Symfony 2 SP security bundle" }, - "config": { - "bin-dir": "bin" - }, "prefer-stable": true, "minimum-stability": "stable" } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 00000000..d6d20437 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,16 @@ + + + + + ./tests + + + + + ./src + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index ea876e9f..00000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - tests - - - - - - - - src - - - - - diff --git a/tests/LightSaml/Tests/Action/Assertion/AbstractAssertionActionTest.php b/tests/LightSaml/Tests/Action/Assertion/AbstractAssertionActionTest.php index 5fcae78e..714376de 100644 --- a/tests/LightSaml/Tests/Action/Assertion/AbstractAssertionActionTest.php +++ b/tests/LightSaml/Tests/Action/Assertion/AbstractAssertionActionTest.php @@ -28,13 +28,11 @@ public function test_do_execute_called_with_assertion_context() $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Expected AssertionContext - */ public function test_throws_context_exception_for_non_assertion_context() { $action = $this->getAbstractAssertionActionMock([$this->getLoggerMock()]); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $this->expectExceptionMessage("Expected AssertionContext"); $action->execute($this->getMockBuilder(ContextInterface::class)->getMock()); } diff --git a/tests/LightSaml/Tests/Action/Assertion/Inbound/AssertionIssuerFormatValidatorActionTest.php b/tests/LightSaml/Tests/Action/Assertion/Inbound/AssertionIssuerFormatValidatorActionTest.php index 289044eb..d6e99dc2 100644 --- a/tests/LightSaml/Tests/Action/Assertion/Inbound/AssertionIssuerFormatValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Assertion/Inbound/AssertionIssuerFormatValidatorActionTest.php @@ -16,12 +16,9 @@ public function test_constructs_with_logger_and_name_id_format() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Assertion element must have an issuer element - */ public function test_throws_context_exception_when_assertion_has_no_issuer() { + $action = new AssertionIssuerFormatValidatorAction( $loggerMock = $this->getLoggerMock(), $expectedIssuerFormat = SamlConstants::NAME_ID_FORMAT_EMAIL @@ -33,13 +30,12 @@ public function test_throws_context_exception_when_assertion_has_no_issuer() ->method('error') ->with('Assertion element must have an issuer element', $this->isType('array')); + $this->expectExceptionMessage("Assertion element must have an issuer element"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Response Issuer Format if set must have value 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' but it was 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent' - */ public function test_throws_context_exception_when_assertion_issuer_format_does_not_matches_expected_format() { $action = new AssertionIssuerFormatValidatorAction( @@ -57,6 +53,9 @@ public function test_throws_context_exception_when_assertion_issuer_format_does_ $this->isType('array') ); + $this->expectExceptionMessage("Response Issuer Format if set must have value 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' but it was 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent'"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($context); } diff --git a/tests/LightSaml/Tests/Action/Assertion/Inbound/InResponseToValidatorActionTest.php b/tests/LightSaml/Tests/Action/Assertion/Inbound/InResponseToValidatorActionTest.php index 495c93f7..36fde7b4 100644 --- a/tests/LightSaml/Tests/Action/Assertion/Inbound/InResponseToValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Assertion/Inbound/InResponseToValidatorActionTest.php @@ -34,10 +34,6 @@ public function test_does_nothing_if_assertion_has_no_subject() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Unknown InResponseTo '123123123' - */ public function test_throws_context_exception_on_unknown_in_response_to() { $action = new InResponseToValidatorAction( @@ -51,6 +47,9 @@ public function test_throws_context_exception_on_unknown_in_response_to() $subjectConfirmation->setSubjectConfirmationData(new SubjectConfirmationData()); $subjectConfirmation->getSubjectConfirmationData()->setInResponseTo('123123123'); + $this->expectExceptionMessage("Unknown InResponseTo '123123123'"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($context); } diff --git a/tests/LightSaml/Tests/Action/Assertion/Inbound/KnownAssertionIssuerActionTest.php b/tests/LightSaml/Tests/Action/Assertion/Inbound/KnownAssertionIssuerActionTest.php index 6eb4d73d..2605ad7c 100644 --- a/tests/LightSaml/Tests/Action/Assertion/Inbound/KnownAssertionIssuerActionTest.php +++ b/tests/LightSaml/Tests/Action/Assertion/Inbound/KnownAssertionIssuerActionTest.php @@ -15,10 +15,6 @@ public function test_constructs_with_logger_and_entity_descriptor_store() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Assertion element must have an issuer element - */ public function test_throws_context_exception_when_assertion_has_no_issuer() { $action = new KnownAssertionIssuerAction( @@ -32,15 +28,15 @@ public function test_throws_context_exception_when_assertion_has_no_issuer() ->method('error') ->with('Assertion element must have an issuer element'); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $this->expectExceptionMessage("Assertion element must have an issuer element"); + $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Unknown issuer 'http://issuer.com' - */ public function test_throws_context_exception_on_unknown_issuer() { + $action = new KnownAssertionIssuerAction( $loggerMock = $this->getLoggerMock(), $entityDescriptorStoreMock = $this->getEntityDescriptorStoreMock() @@ -58,6 +54,9 @@ public function test_throws_context_exception_on_unknown_issuer() ->method('error') ->with("Unknown issuer 'http://issuer.com'"); + $this->expectExceptionMessage("Unknown issuer 'http://issuer.com'"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($context); } diff --git a/tests/LightSaml/Tests/Action/Assertion/Inbound/RecipientValidatorActionTest.php b/tests/LightSaml/Tests/Action/Assertion/Inbound/RecipientValidatorActionTest.php index d6d90304..544143ed 100644 --- a/tests/LightSaml/Tests/Action/Assertion/Inbound/RecipientValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Assertion/Inbound/RecipientValidatorActionTest.php @@ -51,10 +51,6 @@ public function test_does_nothing_when_assertion_has_authn_statement_but_no_bear $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Bearer SubjectConfirmation must contain Recipient attribute - */ public function test_throws_context_exception_when_bearer_confirmation_has_no_recipient() { $action = new RecipientValidatorAction($loggerMock = $this->getLoggerMock(), $this->getEndpointResolverMock()); @@ -69,15 +65,16 @@ public function test_throws_context_exception_when_bearer_confirmation_has_no_re ->method('error') ->with('Bearer SubjectConfirmation must contain Recipient attribute'); + $this->expectExceptionMessage("Bearer SubjectConfirmation must contain Recipient attribute"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($assertionContext); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Recipient 'http://recipient.com' does not match SP descriptor - */ public function test_throws_context_exception_when_recipient_does_not_match_any_own_acs_service_location() { + $this->expectExceptionMessage("Recipient 'http://recipient.com' does not match SP descriptor"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new RecipientValidatorAction( $loggerMock = $this->getLoggerMock(), $endpointResolver = $this->getEndpointResolverMock() diff --git a/tests/LightSaml/Tests/Action/Assertion/Inbound/RepeatedIdValidatorActionTest.php b/tests/LightSaml/Tests/Action/Assertion/Inbound/RepeatedIdValidatorActionTest.php index 14960edb..b9fa6a46 100644 --- a/tests/LightSaml/Tests/Action/Assertion/Inbound/RepeatedIdValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Assertion/Inbound/RepeatedIdValidatorActionTest.php @@ -31,10 +31,6 @@ public function test_does_nothing_if_assertion_has_no_bearer_subject() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Bearer Assertion must have ID attribute - */ public function test_throws_context_exception_when_bearer_assertion_has_no_id() { $action = new RepeatedIdValidatorAction( @@ -52,13 +48,12 @@ public function test_throws_context_exception_when_bearer_assertion_has_no_id() ->method('error') ->with('Bearer Assertion must have ID attribute', $this->isType('array')); + $this->expectExceptionMessage("Bearer Assertion must have ID attribute"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($assertionContext); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Bearer Assertion must have Issuer element - */ public function test_throws_context_exception_when_bearer_assertion_has_no_issuer() { $action = new RepeatedIdValidatorAction( @@ -77,13 +72,12 @@ public function test_throws_context_exception_when_bearer_assertion_has_no_issue ->method('error') ->with('Bearer Assertion must have Issuer element', $this->isType('array')); + $this->expectExceptionMessage("Bearer Assertion must have Issuer element"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($assertionContext); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Repeated assertion id '123' of issuer 'http://issuer.com' - */ public function test_throws_context_exception_for_known_assertion_id() { $action = new RepeatedIdValidatorAction( @@ -108,15 +102,15 @@ public function test_throws_context_exception_for_known_assertion_id() ->method('error') ->with("Repeated assertion id '123' of issuer 'http://issuer.com'", $this->isType('array')); + $this->expectExceptionMessage("Repeated assertion id '123' of issuer 'http://issuer.com'"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($assertionContext); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Bearer SubjectConfirmation must have SubjectConfirmationData element - */ public function test_throws_context_exception_if_no_subject_confirmation_data() { + $action = new RepeatedIdValidatorAction( $loggerMock = $this->getLoggerMock(), $idStoreMock = $this->getIdStoreMock() @@ -139,15 +133,16 @@ public function test_throws_context_exception_if_no_subject_confirmation_data() ->method('error') ->with('Bearer SubjectConfirmation must have SubjectConfirmationData element', $this->isType('array')); + $this->expectExceptionMessage("Bearer SubjectConfirmation must have SubjectConfirmationData element"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); + $action->execute($assertionContext); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Bearer SubjectConfirmation must have NotOnOrAfter attribute - */ public function test_throws_context_exception_if_no_not_on_or_after_attribute() { + $this->expectExceptionMessage("Bearer SubjectConfirmation must have NotOnOrAfter attribute"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new RepeatedIdValidatorAction( $loggerMock = $this->getLoggerMock(), $idStoreMock = $this->getIdStoreMock() diff --git a/tests/LightSaml/Tests/Action/CompositeActionTest.php b/tests/LightSaml/Tests/Action/CompositeActionTest.php index 6d8dae48..daa46a40 100644 --- a/tests/LightSaml/Tests/Action/CompositeActionTest.php +++ b/tests/LightSaml/Tests/Action/CompositeActionTest.php @@ -127,7 +127,7 @@ public function test_to_string_returns_json_debug_tree_string() } EOT; - $this->assertEquals($expectedValue, $actualValue); + $this->assertJsonStringEqualsJsonString($expectedValue, $actualValue); } /** diff --git a/tests/LightSaml/Tests/Action/Profile/AbstractProfileActionTest.php b/tests/LightSaml/Tests/Action/Profile/AbstractProfileActionTest.php index a32363f4..da946e0e 100644 --- a/tests/LightSaml/Tests/Action/Profile/AbstractProfileActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/AbstractProfileActionTest.php @@ -24,12 +24,10 @@ public function test_calls_do_execute_with_profile_context() $action->execute($profileContext); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Expected ProfileContext but got - */ public function test_throws_exception_on_non_profile_context() { + $this->expectExceptionMessage("Expected ProfileContext but got"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); /** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject $loggerMock */ $loggerMock = $this->getMockBuilder(LoggerInterface::class)->getMock(); $loggerMock->expects($this->once()) diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AbstractDestinationValidatorActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AbstractDestinationValidatorActionTest.php index d04efa62..97ce0c80 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AbstractDestinationValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AbstractDestinationValidatorActionTest.php @@ -107,12 +107,10 @@ public function test_makes_descriptor_type_criteria_for_own_role($ownRole, $desc $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Invalid inbound message destination "http://localhost/foo" - */ public function test_throws_exception_when_destination_does_not_match() { + $this->expectExceptionMessage("Invalid inbound message destination \"http://localhost/foo\""); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $loggerMock = $this->getLoggerMock(); $endpointResolverMock = $this->getEndpointResolverMock(); /** @var AbstractDestinationValidatorAction $action */ diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AssertBindingTypeActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AssertBindingTypeActionTest.php index 4f03cb0d..80dacb06 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AssertBindingTypeActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/AssertBindingTypeActionTest.php @@ -34,12 +34,10 @@ public function test_passes_with_inbound_binding_type_being_one_of_expected() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Unexpected binding type "urn:oasis:names:tc:SAML:2.0:bindings:SOAP" - expected binding types are: urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST - */ public function test_throws_when_inbound_binding_type_not_one_of_expected() { + $this->expectExceptionMessage("Unexpected binding type \"urn:oasis:names:tc:SAML:2.0:bindings:SOAP\" - expected binding types are: urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new AssertBindingTypeAction( $logger = $this->getLoggerMock(), [SamlConstants::BINDING_SAML2_HTTP_POST] diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/EntityIdFromMessageIssuerActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/EntityIdFromMessageIssuerActionTest.php index 3e4f3291..14cd7114 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/EntityIdFromMessageIssuerActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/EntityIdFromMessageIssuerActionTest.php @@ -25,12 +25,10 @@ public function test_sets_inbound_message_issuer_entity_id_to_party_context() $this->assertEquals($expectedEntityId, $context->getPartyEntityContext()->getEntityId()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Inbound messages does not have Issuer - */ public function test_throws_when_inbound_message_has_no_issuer() { + $this->expectExceptionMessage("Inbound messages does not have Issuer"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new EntityIdFromMessageIssuerAction($this->getLoggerMock()); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/IssuerValidatorActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/IssuerValidatorActionTest.php index 0b450135..243bf730 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/IssuerValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/IssuerValidatorActionTest.php @@ -20,12 +20,10 @@ public function test_constructs_with_logger_name_id_validator_and_string() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Inbound message must have Issuer element - */ public function test_throws_if_inbound_message_has_no_issuer() { + $this->expectExceptionMessage("Inbound message must have Issuer element"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new IssuerValidatorAction($this->getLoggerMock(), $this->getNameIdValidatorMock(), ''); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); @@ -34,12 +32,10 @@ public function test_throws_if_inbound_message_has_no_issuer() $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Response Issuer Format if set must have value 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' but it was 'non-allowed' - */ public function test_throws_if_inbound_message_issuer_format_different_then_allowed() { + $this->expectExceptionMessage("Response Issuer Format if set must have value 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress' but it was 'non-allowed'"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new IssuerValidatorAction($this->getLoggerMock(), $this->getNameIdValidatorMock(), SamlConstants::NAME_ID_FORMAT_EMAIL); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); @@ -71,12 +67,10 @@ public function test_calls_name_id_validator() $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Error from name id validator - */ public function test_wrapps_validation_exception_in_context_exception() { + $this->expectExceptionMessage("Error from name id validator"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $action = new IssuerValidatorAction($this->getLoggerMock(), $nameIdValidatorMock, $allowedFormat = SamlConstants::NAME_ID_FORMAT_EMAIL); diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/MessageSignatureValidatorActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/MessageSignatureValidatorActionTest.php index be6e8ba8..ec5664a6 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/MessageSignatureValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/MessageSignatureValidatorActionTest.php @@ -40,12 +40,10 @@ public function test_does_nothing_when_message_does_not_have_signature() $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlModelException - * @expectedExceptionMessage Expected AbstractSignatureReader - */ public function test_throws_if_not_signature_reader() { + $this->expectExceptionMessage("Expected AbstractSignatureReader"); + $this->expectException(\LightSaml\Error\LightSamlModelException::class); $action = new MessageSignatureValidatorAction( $logger = $this->getLoggerMock(), $signatureValidator = $this->getSignatureValidatorMock() diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ReceiveMessageActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ReceiveMessageActionTest.php index 4c2d27e8..f2a2f897 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ReceiveMessageActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ReceiveMessageActionTest.php @@ -17,12 +17,10 @@ public function test_constructs_with_logger_and_binding_factory() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlBindingException - * @expectedExceptionMessage Unable to resolve binding type, invalid or unsupported http request - */ public function test_throws_on_invalid_binding() { + $this->expectExceptionMessage("Unable to resolve binding type, invalid or unsupported http request"); + $this->expectException(\LightSaml\Error\LightSamlBindingException::class); $action = new ReceiveMessageAction($logger = $this->getLoggerMock(), $bindingFactory = $this->getBindingFactoryMock()); $context = new ProfileContext(Profiles::SSO_SP_SEND_AUTHN_REQUEST, ProfileContext::ROLE_SP); diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ResolvePartyEntityIdActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ResolvePartyEntityIdActionTest.php index b40c0383..2440b55f 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ResolvePartyEntityIdActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Message/ResolvePartyEntityIdActionTest.php @@ -46,12 +46,10 @@ public function test_does_nothing_if_party_entity_descriptor_and_trust_options_a $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage EntityID is not set in the party context - */ public function test_throws_if_entity_id_is_not_set_in_context() { + $this->expectExceptionMessage("EntityID is not set in the party context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new ResolvePartyEntityIdAction( $logger = $this->getLoggerMock(), $spEntityStore = $this->getEntityDescriptorStoreMock(), diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/DecryptAssertionsActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/DecryptAssertionsActionTest.php index 439de76b..836a8b47 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/DecryptAssertionsActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/DecryptAssertionsActionTest.php @@ -100,12 +100,10 @@ public function test_does_nothing_if_no_encrypted_assertions() $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage No credentials resolved for assertion decryption - */ public function test_throws_context_exception_when_no_credentials_resolved() { + $this->expectExceptionMessage("No credentials resolved for assertion decryption"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new DecryptAssertionsAction( $loggerMock = $this->getLoggerMock(), $credentialResolverMock = $this->getCredentialResolverMock() diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAssertionsValidatorActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAssertionsValidatorActionTest.php index 0d904b55..d8b430c7 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAssertionsValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAssertionsValidatorActionTest.php @@ -30,12 +30,10 @@ public function test_does_nothing_if_response_has_at_least_one_assertion() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Response must contain at least one assertion - */ public function test_throws_context_exception_if_no_assertions() { + $this->expectExceptionMessage("Response must contain at least one assertion"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new HasAssertionsValidatorAction($this->getLoggerMock()); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAuthnStatementValidatorActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAuthnStatementValidatorActionTest.php index c40d3e78..0a95fa7d 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAuthnStatementValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasAuthnStatementValidatorActionTest.php @@ -32,12 +32,10 @@ public function test_does_nothing_if_there_is_at_least_one_authn_statement() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Response must have at least one Assertion containing AuthnStatement element - */ public function test_throws_context_exception_if_no_authn_statement() { + $this->expectExceptionMessage("Response must have at least one Assertion containing AuthnStatement element"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new HasAuthnStatementValidatorAction($this->getLoggerMock()); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasBearerAssertionsValidatorActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasBearerAssertionsValidatorActionTest.php index 643e74d8..7fc9bed3 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasBearerAssertionsValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/Response/HasBearerAssertionsValidatorActionTest.php @@ -38,12 +38,10 @@ public function test_does_nothing_if_there_is_bearer_assertion() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Response must contain at least one bearer assertion - */ public function test_throws_context_exception_if_no_bearer_assertion() { + $this->expectExceptionMessage("Response must contain at least one bearer assertion"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new HasBearerAssertionsValidatorAction($this->getLoggerMock()); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/InResponseToValidatorActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/InResponseToValidatorActionTest.php index 6b4fb6bc..387685d5 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/InResponseToValidatorActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/InResponseToValidatorActionTest.php @@ -58,12 +58,10 @@ public function test_get_request_state_from_store_and_creates_context() $this->assertSame($requestState, $requestStateContext->getRequestState()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Unknown InResponseTo '1234567890' - */ public function test_throws_context_exception_if_no_request_state_for_in_response_to_from_message() { + $this->expectExceptionMessage("Unknown InResponseTo '1234567890'"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new InResponseToValidatorAction( $loggerMock = $this->getLoggerMock(), $requestStateStoreMock = $this->getRequestStateStoreMock() diff --git a/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/StatusActionTest.php b/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/StatusActionTest.php index 2001bef5..369b8581 100644 --- a/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/StatusActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Inbound/StatusResponse/StatusActionTest.php @@ -32,12 +32,10 @@ public function test_does_nothing_if_status_success() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Status response does not have Status set - */ public function test_throws_context_exception_if_no_status() { + $this->expectExceptionMessage("Status response does not have Status set"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new StatusAction($loggerMock = $this->getLoggerMock()); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); @@ -49,13 +47,10 @@ public function test_throws_context_exception_if_no_status() $action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlAuthenticationException - * @expectedExceptionMessage("Unsuccessful SAML response: urn:oasis:names:tc:SAML:2.0:status:Requester - * urn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding") - */ public function test_throws_authentication_exception_if_status_not_success() { + $this->expectExceptionMessage("Unsuccessful SAML response: urn:oasis:names:tc:SAML:2.0:status:Requester\n\nurn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding"); + $this->expectException(\LightSaml\Error\LightSamlAuthenticationException::class); $action = new StatusAction($loggerMock = $this->getLoggerMock()); $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP); diff --git a/tests/LightSaml/Tests/Action/Profile/Outbound/AuthnRequest/ACSUrlActionTest.php b/tests/LightSaml/Tests/Action/Profile/Outbound/AuthnRequest/ACSUrlActionTest.php index d2523a3c..70f6da87 100644 --- a/tests/LightSaml/Tests/Action/Profile/Outbound/AuthnRequest/ACSUrlActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Outbound/AuthnRequest/ACSUrlActionTest.php @@ -61,12 +61,10 @@ public function test_finds_acs_endpoint_and_sets_outbounding_authn_request_acs_u $this->assertEquals($endpoint->getLocation(), $authnRequest->getAssertionConsumerServiceURL()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing ACS Service with HTTP POST binding in own SP SSO Descriptor - */ public function test_throws_context_exception_if_no_own_acs_service() { + $this->expectExceptionMessage("Missing ACS Service with HTTP POST binding in own SP SSO Descriptor"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $action = new ACSUrlAction( $loggerMock = $this->getLoggerMock(), $endpointResolverMock = $this->getEndpointResolverMock() diff --git a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/AbstractResolveEndpointActionTest.php b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/AbstractResolveEndpointActionTest.php index d9a71231..bf44e85a 100644 --- a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/AbstractResolveEndpointActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/AbstractResolveEndpointActionTest.php @@ -32,7 +32,7 @@ abstract class AbstractResolveEndpointActionTest extends BaseTestCase /** * */ - protected function setUp() + protected function setUp() : void { $this->logger = $this->getLoggerMock(); $this->endpointResolver = $this->getMockBuilder(EndpointResolverInterface::class)->getMock(); diff --git a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointBaseActionTest.php b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointBaseActionTest.php index 7428ab29..eba2ebcb 100644 --- a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointBaseActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointBaseActionTest.php @@ -57,12 +57,10 @@ public function test_should_resolve_endpoint_and_set_to_context() $this->assertSame($endpoint, $context->getEndpoint()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Unable to determine endpoint for entity 'https://B1.bead.loc/adfs/services/trust' - */ public function test_throws_context_exception_when_no_endpoint_resolved() { + $this->expectExceptionMessage("Unable to determine endpoint for entity 'https://B1.bead.loc/adfs/services/trust'"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $message = new Response(); $context = $this->createContext(ProfileContext::ROLE_IDP, $message); diff --git a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointSloActionTest.php b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointSloActionTest.php index 2d596036..f76cf63c 100644 --- a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointSloActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/ResolveEndpointSloActionTest.php @@ -79,12 +79,10 @@ public function test_adds_idp_sso_descriptor_type_when_sso_sp_entity_is_own_id() $this->action->execute($context); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Unable to resolve logout target descriptor type - */ public function test_throws_context_exception_own_entity_id_does_not_match_sso_idp_nor_sp() { + $this->expectExceptionMessage("Unable to resolve logout target descriptor type"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $message = new AuthnRequest(); $context = $this->createContext(ProfileContext::ROLE_IDP, $message); diff --git a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/SignMessageActionTest.php b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/SignMessageActionTest.php index 0aa22560..d09ed388 100644 --- a/tests/LightSaml/Tests/Action/Profile/Outbound/Message/SignMessageActionTest.php +++ b/tests/LightSaml/Tests/Action/Profile/Outbound/Message/SignMessageActionTest.php @@ -52,11 +52,13 @@ public function does_not_support_message_provider() /** * @dataProvider does_not_support_message_provider - * @expectedException \LogicException - * @expectedExceptionMessage Unexpected message type + * + * */ public function test_does_not_support_message(SamlMessage $message) { + $this->expectExceptionMessage("Unexpected message type"); + $this->expectException(\LogicException::class); $action = new SignMessageAction($this->getLoggerMock(), $this->getSignatureResolverMock()); $context = $this->getProfileContext(); diff --git a/tests/LightSaml/Tests/Binding/BindingFactoryTest.php b/tests/LightSaml/Tests/Binding/BindingFactoryTest.php index ca3d4fa1..55fc25ab 100644 --- a/tests/LightSaml/Tests/Binding/BindingFactoryTest.php +++ b/tests/LightSaml/Tests/Binding/BindingFactoryTest.php @@ -23,32 +23,26 @@ public function test__create_http_post() $this->assertInstanceOf('LightSaml\Binding\HttpPostBinding', $binding); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage SOAP binding not implemented - */ public function test__create_throws_not_implemented_error_for_soap() { + $this->expectExceptionMessage("SOAP binding not implemented"); + $this->expectException(\LogicException::class); $factory = new BindingFactory(); $factory->create(SamlConstants::BINDING_SAML2_SOAP); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Artifact binding not implemented - */ public function test__create_throws_not_implemented_error_for_artifact() { + $this->expectExceptionMessage("Artifact binding not implemented"); + $this->expectException(\LogicException::class); $factory = new BindingFactory(); $factory->create(SamlConstants::BINDING_SAML2_HTTP_ARTIFACT); } - /** - * @expectedException \LightSaml\Error\LightSamlBindingException - * @expectedExceptionMessage Unknown binding type 'foo' - */ public function test__create_throws_for_unknown_binding() { + $this->expectExceptionMessage("Unknown binding type 'foo'"); + $this->expectException(\LightSaml\Error\LightSamlBindingException::class); $factory = new BindingFactory(); $factory->create('foo'); } diff --git a/tests/LightSaml/Tests/Binding/HttpPostBindingTest.php b/tests/LightSaml/Tests/Binding/HttpPostBindingTest.php index 68227ce6..398f7ac7 100644 --- a/tests/LightSaml/Tests/Binding/HttpPostBindingTest.php +++ b/tests/LightSaml/Tests/Binding/HttpPostBindingTest.php @@ -13,12 +13,10 @@ class HttpPostBindingTest extends BaseTestCase { - /** - * @expectedException \LightSaml\Error\LightSamlBindingException - * @expectedExceptionMessage Missing SAMLRequest or SAMLResponse parameter - */ public function test_receive_throws_when_no_message() { + $this->expectExceptionMessage("Missing SAMLRequest or SAMLResponse parameter"); + $this->expectException(\LightSaml\Error\LightSamlBindingException::class); $request = new Request(); $binding = new HttpPostBinding(); diff --git a/tests/LightSaml/Tests/Binding/HttpRedirectBindingTest.php b/tests/LightSaml/Tests/Binding/HttpRedirectBindingTest.php index 57a27482..fd75995a 100644 --- a/tests/LightSaml/Tests/Binding/HttpRedirectBindingTest.php +++ b/tests/LightSaml/Tests/Binding/HttpRedirectBindingTest.php @@ -9,12 +9,10 @@ class HttpRedirectBindingTest extends BaseTestCase { - /** - * @expectedException \LightSaml\Error\LightSamlBindingException - * @expectedExceptionMessage Missing SAMLRequest or SAMLResponse parameter - */ public function test__receive_throws_when_no_message() { + $this->expectExceptionMessage("Missing SAMLRequest or SAMLResponse parameter"); + $this->expectException(\LightSaml\Error\LightSamlBindingException::class); $request = new Request(); $binding = new HttpRedirectBinding(); diff --git a/tests/LightSaml/Tests/Builder/Action/CompositeActionBuilderTest.php b/tests/LightSaml/Tests/Builder/Action/CompositeActionBuilderTest.php index 5cbf5f3a..49308cc4 100644 --- a/tests/LightSaml/Tests/Builder/Action/CompositeActionBuilderTest.php +++ b/tests/LightSaml/Tests/Builder/Action/CompositeActionBuilderTest.php @@ -11,20 +11,16 @@ class CompositeActionBuilderTest extends BaseTestCase { - /** - * @expectedException \InvalidArgumentException - */ public function test__throws_on_priority_true() { + $this->expectException(\InvalidArgumentException::class); $compositeBuilder = new CompositeActionBuilder(); $compositeBuilder->add(new FooAction(), true); } - /** - * @expectedException \InvalidArgumentException - */ public function test__throws_on_priority_string() { + $this->expectException(\InvalidArgumentException::class); $compositeBuilder = new CompositeActionBuilder(); $compositeBuilder->add(new FooAction(), "asc"); } diff --git a/tests/LightSaml/Tests/Builder/Context/ProfileContextBuilderTest.php b/tests/LightSaml/Tests/Builder/Context/ProfileContextBuilderTest.php index ac7f9f69..e6ae429a 100644 --- a/tests/LightSaml/Tests/Builder/Context/ProfileContextBuilderTest.php +++ b/tests/LightSaml/Tests/Builder/Context/ProfileContextBuilderTest.php @@ -38,35 +38,29 @@ public function test_getters_setters($value, $setter, $getter) $this->assertSame($value, $builder->{$getter}()); } - /** - * @expectedException \LightSaml\Error\LightSamlBuildException - * @expectedExceptionMessage HTTP Request not set - */ public function test_build_throws_exception_when_request_not_set() { + $this->expectExceptionMessage("HTTP Request not set"); + $this->expectException(\LightSaml\Error\LightSamlBuildException::class); $builder = new ProfileContextBuilder(); $builder->build(); } - /** - * @expectedException \LightSaml\Error\LightSamlBuildException - * @expectedExceptionMessage Own EntityDescriptor not set - */ public function test_build_throws_exception_when_own_entity_descriptor_not_set() { + $this->expectExceptionMessage("Own EntityDescriptor not set"); + $this->expectException(\LightSaml\Error\LightSamlBuildException::class); $builder = new ProfileContextBuilder(); $builder->setRequest(new Request()); $builder->build(); } - /** - * @expectedException \LightSaml\Error\LightSamlBuildException - * @expectedExceptionMessage ProfileID not set - */ public function test_build_throws_exception_when_profile_id_not_set() { + $this->expectExceptionMessage("ProfileID not set"); + $this->expectException(\LightSaml\Error\LightSamlBuildException::class); $builder = new ProfileContextBuilder(); $builder->setRequest(new Request()); $builder->setOwnEntityDescriptorProvider(new FixedEntityDescriptorProvider(new EntityDescriptor())); @@ -74,12 +68,10 @@ public function test_build_throws_exception_when_profile_id_not_set() $builder->build(); } - /** - * @expectedException \LightSaml\Error\LightSamlBuildException - * @expectedExceptionMessage Profile role not set - */ public function test_build_throws_exception_when_profile_role_not_set() { + $this->expectExceptionMessage("Profile role not set"); + $this->expectException(\LightSaml\Error\LightSamlBuildException::class); $builder = new ProfileContextBuilder(); $builder->setRequest(new Request()); $builder->setOwnEntityDescriptorProvider(new FixedEntityDescriptorProvider(new EntityDescriptor())); diff --git a/tests/LightSaml/Tests/Context/AbstractContextTest.php b/tests/LightSaml/Tests/Context/AbstractContextTest.php index 202d914e..73eda792 100644 --- a/tests/LightSaml/Tests/Context/AbstractContextTest.php +++ b/tests/LightSaml/Tests/Context/AbstractContextTest.php @@ -71,12 +71,10 @@ public function test_get_sub_context_returns_null_for_not_set_context() $this->assertNull($context->getSubContext('other')); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Expected object or ContextInterface - */ public function test_add_sub_context_throws_if_not_a_context_value() { + $this->expectExceptionMessage("Expected object or ContextInterface"); + $this->expectException(\InvalidArgumentException::class); $context = $this->getContextMock(); $context->addSubContext($name = 'some', '123'); $context->getSubContext($name); @@ -237,8 +235,7 @@ public function test_to_string_gives_debug_tree_string() } } EOT; - - $this->assertEquals($expected, $actual); + $this->assertJsonStringEqualsJsonString($expected, $actual); } /** diff --git a/tests/LightSaml/Tests/Context/Profile/ProfileContextTest.php b/tests/LightSaml/Tests/Context/Profile/ProfileContextTest.php index 810d5b64..bc10fd8d 100644 --- a/tests/LightSaml/Tests/Context/Profile/ProfileContextTest.php +++ b/tests/LightSaml/Tests/Context/Profile/ProfileContextTest.php @@ -58,12 +58,10 @@ public function test__sub_context_creation($method, $expectedClass) $this->assertInstanceOf($expectedClass, $subContext); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing Request in HTTP request context - */ public function test__get_http_request_throws_on_empty_context() { + $this->expectExceptionMessage("Missing Request in HTTP request context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getHttpRequest(); } @@ -75,12 +73,10 @@ public function test__get_http_request_returns_from_context() $this->assertSame($expectedValue, $profileContext->getHttpRequest()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing message in inbound context - */ public function test__get_inbound_message_throws_on_empty_context() { + $this->expectExceptionMessage("Missing message in inbound context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getInboundMessage(); } @@ -92,12 +88,10 @@ public function test__get_inbound_message_returns_from_context() $this->assertSame($expectedValue, $profileContext->getInboundMessage()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing message in outbound context - */ public function test__get_outbound_message_throws_on_empty_context() { + $this->expectExceptionMessage("Missing message in outbound context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getOutboundMessage(); } @@ -109,12 +103,10 @@ public function test__get_outbound_message_returns_from_context() $this->assertSame($expectedValue, $profileContext->getOutboundMessage()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing Endpoint in endpoint context - */ public function test__get_endpoint_throws_on_empty_context() { + $this->expectExceptionMessage("Missing Endpoint in endpoint context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getEndpoint(); } @@ -126,12 +118,10 @@ public function test__get_endpoint_returns_from_context() $this->assertSame($expectedValue, $profileContext->getEndpoint()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing EntityDescriptor in own entity context - */ public function test__get_own_entity_descriptor_throws_on_empty_context() { + $this->expectExceptionMessage("Missing EntityDescriptor in own entity context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getOwnEntityDescriptor(); } @@ -143,12 +133,10 @@ public function test__get_own_entity_descriptor_returns_from_context() $this->assertSame($expectedValue, $profileContext->getOwnEntityDescriptor()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing EntityDescriptor in party entity context - */ public function test__get_party_entity_descriptor_throws_on_empty_context() { + $this->expectExceptionMessage("Missing EntityDescriptor in party entity context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getPartyEntityDescriptor(); } @@ -160,12 +148,10 @@ public function test__get_party_entity_descriptor_returns_from_context() $this->assertSame($expectedValue, $profileContext->getPartyEntityDescriptor()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing TrustOptions in party entity context - */ public function test__get_trust_options_throws_on_empty_context() { + $this->expectExceptionMessage("Missing TrustOptions in party entity context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getTrustOptions(); } @@ -177,12 +163,10 @@ public function test__get_trust_options_returns_from_context() $this->assertSame($expectedValue, $profileContext->getTrustOptions()); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Missing SsoSessionState in logout context - */ public function test__get_logout_sso_session_state_throws_on_empty_context() { + $this->expectExceptionMessage("Missing SsoSessionState in logout context"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP); $profileContext->getLogoutSsoSessionState(); } diff --git a/tests/LightSaml/Tests/Credential/Context/CredentialContextSetTest.php b/tests/LightSaml/Tests/Credential/Context/CredentialContextSetTest.php index 40174fe5..5d7c9f0d 100644 --- a/tests/LightSaml/Tests/Credential/Context/CredentialContextSetTest.php +++ b/tests/LightSaml/Tests/Credential/Context/CredentialContextSetTest.php @@ -33,12 +33,10 @@ public function test_returns_all_contexts() $this->assertSame($expected[1], $all[1]); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Expected CredentialContextInterface - */ public function test_throws_invalid_argument_exception_if_constructed_with_non_credential_context_array() { + $this->expectExceptionMessage("Expected CredentialContextInterface"); + $this->expectException(\InvalidArgumentException::class); new CredentialContextSet([new \stdClass()]); } diff --git a/tests/LightSaml/Tests/Credential/X509CertificateTest.php b/tests/LightSaml/Tests/Credential/X509CertificateTest.php index e1474eb3..2358ad0c 100644 --- a/tests/LightSaml/Tests/Credential/X509CertificateTest.php +++ b/tests/LightSaml/Tests/Credential/X509CertificateTest.php @@ -7,32 +7,26 @@ class X509CertificateTest extends BaseTestCase { - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Invalid PEM encoded certificate - */ public function test__error_on_invalid_load_pem_context() { + $this->expectExceptionMessage("Invalid PEM encoded certificate"); + $this->expectException(\InvalidArgumentException::class); $certificate = new X509Certificate(); $certificate->loadPem('not a pem format'); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage File not found '/non/existing/file/123' - */ public function test_error_on_invalid_load_from_file() { + $this->expectExceptionMessage("File not found '/non/existing/file/123'"); + $this->expectException(\InvalidArgumentException::class); $certificate = new X509Certificate(); $certificate->loadFromFile('/non/existing/file/123'); } - /** - * @expectedException \LightSaml\Error\LightSamlException - * @expectedExceptionMessage Certificate data not set - */ public function test_error_when_parse_called_with_out_data_set() { + $this->expectExceptionMessage("Certificate data not set"); + $this->expectException(\LightSaml\Error\LightSamlException::class); $certificate = new X509Certificate(); $certificate->parse(); } @@ -52,11 +46,13 @@ public function throws_exception_when_data_not_set_provider() /** * @dataProvider throws_exception_when_data_not_set_provider - * @expectedException \LightSaml\Error\LightSamlException - * @expectedExceptionMessage Certificate data not set + * + * */ public function test_throws_exception_when_data_not_set($method) { + $this->expectExceptionMessage("Certificate data not set"); + $this->expectException(\LightSaml\Error\LightSamlException::class); $certificate = new X509Certificate(); $certificate->{$method}(); } diff --git a/tests/LightSaml/Tests/Functional/Bridge/Pimple/ProfileTest.php b/tests/LightSaml/Tests/Functional/Bridge/Pimple/ProfileTest.php index dedb5ae7..9b81b7ca 100644 --- a/tests/LightSaml/Tests/Functional/Bridge/Pimple/ProfileTest.php +++ b/tests/LightSaml/Tests/Functional/Bridge/Pimple/ProfileTest.php @@ -110,32 +110,26 @@ public function test_receive_response_profile() ->getFirstAttributeByName(ClaimTypes::EMAIL_ADDRESS)->getFirstAttributeValue()); } - /** - * @expectedException \LightSaml\Error\LightSamlBuildException - * @expectedExceptionMessage Attribute value provider not set - */ public function test_attribute_value_provider_throws_exception() { + $this->expectExceptionMessage("Attribute value provider not set"); + $this->expectException(\LightSaml\Error\LightSamlBuildException::class); $buildContainer = $this->getBuildContainer(); $buildContainer->getProviderContainer()->getAttributeValueProvider(); } - /** - * @expectedException \LightSaml\Error\LightSamlBuildException - * @expectedExceptionMessage Session info provider not set - */ public function test_session_info_provider_throws_exception() { + $this->expectExceptionMessage("Session info provider not set"); + $this->expectException(\LightSaml\Error\LightSamlBuildException::class); $buildContainer = $this->getBuildContainer(); $buildContainer->getProviderContainer()->getSessionInfoProvider(); } - /** - * @expectedException \LightSaml\Error\LightSamlBuildException - * @expectedExceptionMessage Name ID provider not set - */ public function test_name_id_provider_throws_exception() { + $this->expectExceptionMessage("Name ID provider not set"); + $this->expectException(\LightSaml\Error\LightSamlBuildException::class); $buildContainer = $this->getBuildContainer(); $buildContainer->getProviderContainer()->getNameIdProvider(); } diff --git a/tests/LightSaml/Tests/Functional/Model/Metadata/EntitiesDescriptorFunctionalTest.php b/tests/LightSaml/Tests/Functional/Model/Metadata/EntitiesDescriptorFunctionalTest.php index 38365e0d..f36eb612 100644 --- a/tests/LightSaml/Tests/Functional/Model/Metadata/EntitiesDescriptorFunctionalTest.php +++ b/tests/LightSaml/Tests/Functional/Model/Metadata/EntitiesDescriptorFunctionalTest.php @@ -220,12 +220,10 @@ public function test_deserialize_ukfederation_metadata() $this->assertCount(2935, $entitiesDescriptor->getAllEntityDescriptors()); } - /** - * @expectedException \LightSaml\Error\LightSamlXmlException - * @expectedExceptionMessage Expected 'EntitiesDescriptor' xml node and 'urn:oasis:names:tc:SAML:2.0:metadata' namespace but got node 'EntityDescriptor' and namespace 'urn:oasis:names:tc:SAML:2.0:metadata' - */ public function test_throws_on_entity_descriptor() { + $this->expectExceptionMessage("Expected 'EntitiesDescriptor' xml node and 'urn:oasis:names:tc:SAML:2.0:metadata' namespace but got node 'EntityDescriptor' and namespace 'urn:oasis:names:tc:SAML:2.0:metadata'"); + $this->expectException(\LightSaml\Error\LightSamlXmlException::class); EntitiesDescriptor::load(__DIR__.'/../../../../../../resources/sample/EntityDescriptor/idp-ed.xml'); } } diff --git a/tests/LightSaml/Tests/Functional/Model/Metadata/EntityDescriptorFunctionalTest.php b/tests/LightSaml/Tests/Functional/Model/Metadata/EntityDescriptorFunctionalTest.php index 071f36b2..bba52dd0 100644 --- a/tests/LightSaml/Tests/Functional/Model/Metadata/EntityDescriptorFunctionalTest.php +++ b/tests/LightSaml/Tests/Functional/Model/Metadata/EntityDescriptorFunctionalTest.php @@ -120,12 +120,10 @@ public function test_deserialize_engine_surfconext_nl_authentication_idp_metadat $this->assertEquals('https://engine.surfconext.nl/authentication/idp/metadata', $ed->getEntityID()); } - /** - * @expectedException \LightSaml\Error\LightSamlXmlException - * @expectedExceptionMessage Expected 'EntityDescriptor' xml node and 'urn:oasis:names:tc:SAML:2.0:metadata' namespace but got node 'EntitiesDescriptor' and namespace 'urn:oasis:names:tc:SAML:2.0:metadata' - */ public function test_throws_on_entities_descriptor_document() { + $this->expectExceptionMessage("Expected 'EntityDescriptor' xml node and 'urn:oasis:names:tc:SAML:2.0:metadata' namespace but got node 'EntitiesDescriptor' and namespace 'urn:oasis:names:tc:SAML:2.0:metadata'"); + $this->expectException(\LightSaml\Error\LightSamlXmlException::class); EntityDescriptor::load(__DIR__.'/../../../../../../resources/sample/EntitiesDescriptor/testshib-providers.xml'); } diff --git a/tests/LightSaml/Tests/HelperTest.php b/tests/LightSaml/Tests/HelperTest.php index 7dd86f20..9e511621 100644 --- a/tests/LightSaml/Tests/HelperTest.php +++ b/tests/LightSaml/Tests/HelperTest.php @@ -96,11 +96,9 @@ public function test__get_timestamp_from_value_with_int($value, $timestamp) $this->assertEquals($timestamp, Helper::getTimestampFromValue($timestamp)); } - /** - * @expectedException \InvalidArgumentException - */ public function test__get_timestamp_from_value_with_invalid_value() { + $this->expectException(\InvalidArgumentException::class); Helper::getTimestampFromValue(array()); } @@ -116,11 +114,9 @@ public function test__generate_random_bytes_length() $this->assertEquals(32, strlen($random)); } - /** - * @expectedException \InvalidArgumentException - */ public function test__generate_random_bytes_error_on_invalid_length() { + $this->expectException(\InvalidArgumentException::class); Helper::generateRandomBytes(''); } diff --git a/tests/LightSaml/Tests/Model/Metadata/EntitiesDescriptorTest.php b/tests/LightSaml/Tests/Model/Metadata/EntitiesDescriptorTest.php index 69f4f283..940219fc 100644 --- a/tests/LightSaml/Tests/Model/Metadata/EntitiesDescriptorTest.php +++ b/tests/LightSaml/Tests/Model/Metadata/EntitiesDescriptorTest.php @@ -31,20 +31,16 @@ public function test_set_positive_int_to_valid_until() $this->assertTrue(true); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_on_set_invalid_string_to_valid_until() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->setValidUntil('something'); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_on_set_negative_int_to_valid_until() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->setValidUntil(-1); } @@ -56,11 +52,9 @@ public function test_set_valid_period_string_to_cache_duration() $this->assertTrue(true); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_on_invalid_period_string_set_to_cache_duration() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->setCacheDuration('83D2Y'); } @@ -79,47 +73,37 @@ public function test_add_item_entity_descriptor() $this->assertTrue(true); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_on_invalid_object_type_given_to_add_item() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->addItem(new \stdClass()); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_on_array_given_to_add_item() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->addItem(array()); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_on_string_given_to_add_item() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->addItem('foo'); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_on_int_given_to_add_item() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->addItem(123); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_when_itself_given_to_add_item() { + $this->expectException(\InvalidArgumentException::class); $ed = new EntitiesDescriptor(); $ed->addItem($ed); } @@ -151,11 +135,9 @@ public function test_contains_item_work() $this->assertFalse($o3->containsItem($x2)); } - /** - * @expectedException \InvalidArgumentException - */ public function test_throw_when_circular_reference_detected_in_add_item() { + $this->expectException(\InvalidArgumentException::class); $esd1 = new EntitiesDescriptor(); $esd1->addItem(new EntityDescriptor('ed1')); $esd1->addItem(new EntityDescriptor('ed2')); diff --git a/tests/LightSaml/Tests/Model/Metadata/RoleDescriptorTest.php b/tests/LightSaml/Tests/Model/Metadata/RoleDescriptorTest.php index e7efe9a2..6640b5d7 100644 --- a/tests/LightSaml/Tests/Model/Metadata/RoleDescriptorTest.php +++ b/tests/LightSaml/Tests/Model/Metadata/RoleDescriptorTest.php @@ -15,11 +15,9 @@ public function test__set_valid_cache_duration() $this->assertEquals($expectedValue, $rd->getCacheDuration()); } - /** - * @expectedException \InvalidArgumentException - */ public function test__set_invalid_cache_duration() { + $this->expectException(\InvalidArgumentException::class); $rd = new RoleDescriptorMock(); $rd->setCacheDuration('123'); } diff --git a/tests/LightSaml/Tests/Model/XmlDSig/SignatureStringReaderTest.php b/tests/LightSaml/Tests/Model/XmlDSig/SignatureStringReaderTest.php index 57efd6e2..9528c8f3 100644 --- a/tests/LightSaml/Tests/Model/XmlDSig/SignatureStringReaderTest.php +++ b/tests/LightSaml/Tests/Model/XmlDSig/SignatureStringReaderTest.php @@ -50,23 +50,19 @@ public function test_validate_correct_signature() $this->assertTrue($result); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage SignatureStringReader can not be serialized - */ public function test_serialize_throws_exception() { + $this->expectExceptionMessage("SignatureStringReader can not be serialized"); + $this->expectException(\LogicException::class); $context = new SerializationContext(); $reader = new SignatureStringReader(); $reader->serialize($context->getDocument(), $context); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage SignatureStringReader can not be deserialized - */ public function test_deserialize_throws_exception() { + $this->expectExceptionMessage("SignatureStringReader can not be deserialized"); + $this->expectException(\LogicException::class); $context = new DeserializationContext(); $reader = new SignatureStringReader(); $reader->deserialize($context->getDocument(), $context); diff --git a/tests/LightSaml/Tests/Model/XmlDSig/SignatureWriterTest.php b/tests/LightSaml/Tests/Model/XmlDSig/SignatureWriterTest.php index 19863386..e3597258 100644 --- a/tests/LightSaml/Tests/Model/XmlDSig/SignatureWriterTest.php +++ b/tests/LightSaml/Tests/Model/XmlDSig/SignatureWriterTest.php @@ -42,12 +42,10 @@ public function test_can_be_constructed_wout_arguments() $this->assertTrue(true); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage SignatureWriter can not be deserialized - */ public function test_throws_logic_exception_on_deserialize() { + $this->expectExceptionMessage("SignatureWriter can not be deserialized"); + $this->expectException(\LogicException::class); $deserializationContext = new DeserializationContext(); $deserializationContext->getDocument()->loadXML(''); $writer = new SignatureWriter(); diff --git a/tests/LightSaml/Tests/Model/Xsd/AbstractXsdValidationTest.php b/tests/LightSaml/Tests/Model/Xsd/AbstractXsdValidationTest.php index 0ecb38d6..bb29ea38 100644 --- a/tests/LightSaml/Tests/Model/Xsd/AbstractXsdValidationTest.php +++ b/tests/LightSaml/Tests/Model/Xsd/AbstractXsdValidationTest.php @@ -16,7 +16,7 @@ abstract class AbstractXsdValidationTest extends BaseTestCase { - protected function setUp() + protected function setUp() : void { libxml_use_internal_errors(true); } diff --git a/tests/LightSaml/Tests/Resolver/Signature/OwnSignatureResolverTest.php b/tests/LightSaml/Tests/Resolver/Signature/OwnSignatureResolverTest.php index a19d9577..362144af 100644 --- a/tests/LightSaml/Tests/Resolver/Signature/OwnSignatureResolverTest.php +++ b/tests/LightSaml/Tests/Resolver/Signature/OwnSignatureResolverTest.php @@ -27,12 +27,10 @@ public function test_constructs_with_credential_resolver() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlContextException - * @expectedExceptionMessage Unable to find signing credential - */ public function test_throws_context_exception_when_no_credential_resolved() { + $this->expectExceptionMessage("Unable to find signing credential"); + $this->expectException(\LightSaml\Error\LightSamlContextException::class); $signatureResolver = new OwnSignatureResolver($credentialResolverMock = $this->getCredentialResolverMock()); $context = $this->getProfileContext(); @@ -104,12 +102,10 @@ public function test_credential_criterias($profileRole, $expectedMetadataType) $signatureResolver->getSignature($context); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Expected X509CredentialInterface but got - */ public function test_throws_logic_exception_when_returned_value_if_not_credential() { + $this->expectExceptionMessage("Expected X509CredentialInterface but got"); + $this->expectException(\LogicException::class); $signatureResolver = new OwnSignatureResolver($credentialResolverMock = $this->getCredentialResolverMock()); $context = $this->getProfileContext(); diff --git a/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionTimeValidatorTest.php b/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionTimeValidatorTest.php index 948cc0b1..837ea387 100644 --- a/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionTimeValidatorTest.php +++ b/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionTimeValidatorTest.php @@ -13,12 +13,10 @@ class AssertionTimeValidatorTest extends BaseTestCase { - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Conditions.NotBefore must not be in the future - */ public function test_conditions_not_before_fails() { + $this->expectExceptionMessage("Conditions.NotBefore must not be in the future"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $now = 1000; $assertion = new Assertion(); @@ -30,12 +28,10 @@ public function test_conditions_not_before_fails() $validator->validateTimeRestrictions($assertion, $now, 10); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Conditions.NotOnOrAfter must not be in the past - */ public function test_conditions_not_on_or_after_fails() { + $this->expectExceptionMessage("Conditions.NotOnOrAfter must not be in the past"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $now = 1000; $assertion = new Assertion(); @@ -47,12 +43,10 @@ public function test_conditions_not_on_or_after_fails() $validator->validateTimeRestrictions($assertion, $now, 10); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnStatement attribute SessionNotOnOrAfter MUST be in the future - */ public function test_authn_statement_session_not_on_or_after_fails() { + $this->expectExceptionMessage("AuthnStatement attribute SessionNotOnOrAfter MUST be in the future"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $now = 1000; $assertion = new Assertion(); @@ -64,12 +58,10 @@ public function test_authn_statement_session_not_on_or_after_fails() $validator->validateTimeRestrictions($assertion, $now, 10); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage SubjectConfirmationData.NotBefore must not be in the future - */ public function test_subject_not_before_fails() { + $this->expectExceptionMessage("SubjectConfirmationData.NotBefore must not be in the future"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $now = 1000; $assertion = new Assertion(); @@ -87,12 +79,10 @@ public function test_subject_not_before_fails() $validator->validateTimeRestrictions($assertion, $now, 10); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage SubjectConfirmationData.NotOnOrAfter must not be in the past - */ public function test_subject_not_on_or_after_fails() { + $this->expectExceptionMessage("SubjectConfirmationData.NotOnOrAfter must not be in the past"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $now = 1000; $assertion = new Assertion(); diff --git a/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionValidatorTest.php b/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionValidatorTest.php index 195b9eaf..a4ef8f4c 100644 --- a/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionValidatorTest.php +++ b/tests/LightSaml/Tests/Validator/Model/Assertion/AssertionValidatorTest.php @@ -16,12 +16,10 @@ class AssertionValidatorTest extends BaseTestCase { - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion element must have the Version attribute set - */ public function test_must_have_version() { + $this->expectExceptionMessage("Assertion element must have the Version attribute set"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $validator = new AssertionValidator( $this->getNameIdValidatorMock(), $this->getSubjectValidatorMock(), @@ -34,12 +32,10 @@ public function test_must_have_version() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion element must have the Version attribute value equal to 2.0 - */ public function test_must_have_version20() { + $this->expectExceptionMessage("Assertion element must have the Version attribute value equal to 2.0"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $validator = new AssertionValidator( $this->getNameIdValidatorMock(), $this->getSubjectValidatorMock(), @@ -52,12 +48,10 @@ public function test_must_have_version20() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion element must have the ID attribute set - */ public function test_must_have_id() { + $this->expectExceptionMessage("Assertion element must have the ID attribute set"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $validator = new AssertionValidator( $this->getNameIdValidatorMock(), $this->getSubjectValidatorMock(), @@ -69,12 +63,10 @@ public function test_must_have_id() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion element must have an ID attribute with at least 16 characters (the equivalent of 128 bits) - */ public function test_must_have_valid_id() { + $this->expectExceptionMessage("Assertion element must have an ID attribute with at least 16 characters (the equivalent of 128 bits)"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $validator = new AssertionValidator( $this->getNameIdValidatorMock(), $this->getSubjectValidatorMock(), @@ -87,12 +79,10 @@ public function test_must_have_valid_id() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion element must have the IssueInstant attribute set - */ public function test_must_have_issue_instant() { + $this->expectExceptionMessage("Assertion element must have the IssueInstant attribute set"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $validator = new AssertionValidator( $this->getNameIdValidatorMock(), $this->getSubjectValidatorMock(), @@ -105,12 +95,10 @@ public function test_must_have_issue_instant() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion element must have an issuer element - */ public function test_must_have_issuer() { + $this->expectExceptionMessage("Assertion element must have an issuer element"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $validator = new AssertionValidator( $this->getNameIdValidatorMock(), $this->getSubjectValidatorMock(), @@ -124,12 +112,10 @@ public function test_must_have_issuer() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion with no Statements must have a subject - */ public function test_no_subject_no_statements_fails() { + $this->expectExceptionMessage("Assertion with no Statements must have a subject"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -148,12 +134,10 @@ public function test_no_subject_no_statements_fails() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnStatement, AuthzDecisionStatement and AttributeStatement require a subject - */ public function test_authn_statement_requires_subject() { + $this->expectExceptionMessage("AuthnStatement, AuthzDecisionStatement and AttributeStatement require a subject"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -173,12 +157,10 @@ public function test_authn_statement_requires_subject() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnStatement, AuthzDecisionStatement and AttributeStatement require a subject - */ public function test_attribute_statement_requires_subject() { + $this->expectExceptionMessage("AuthnStatement, AuthzDecisionStatement and AttributeStatement require a subject"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -226,12 +208,10 @@ public function test_subject_validator_is_called() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Conditions NotBefore MUST BE less than NotOnOrAfter - */ public function test_conditions_not_before_must_be_less_than_not_on_or_after() { + $this->expectExceptionMessage("Conditions NotBefore MUST BE less than NotOnOrAfter"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -256,12 +236,10 @@ public function test_conditions_not_before_must_be_less_than_not_on_or_after() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion contained more than one condition of type OneTimeUse - */ public function test_conditions_one_time_use_not_more_than_one() { + $this->expectExceptionMessage("Assertion contained more than one condition of type OneTimeUse"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -286,12 +264,10 @@ public function test_conditions_one_time_use_not_more_than_one() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Count attribute of ProxyRestriction MUST BE a non-negative integer - */ public function test_conditions_proxy_restriction_count_must_be_non_negative_integer() { + $this->expectExceptionMessage("Count attribute of ProxyRestriction MUST BE a non-negative integer"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -315,12 +291,10 @@ public function test_conditions_proxy_restriction_count_must_be_non_negative_int $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage ProxyRestriction Audience MUST BE a wellformed uri - */ public function test_conditions_proxy_restriction_audience_must_be_well_formed_uri_string() { + $this->expectExceptionMessage("ProxyRestriction Audience MUST BE a wellformed uri"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -346,12 +320,10 @@ public function test_conditions_proxy_restriction_audience_must_be_well_formed_u $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Assertion contained more than one condition of type ProxyRestriction - */ public function test_conditions_proxy_restriction_not_more_than_one() { + $this->expectExceptionMessage("Assertion contained more than one condition of type ProxyRestriction"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); @@ -376,12 +348,10 @@ public function test_conditions_proxy_restriction_not_more_than_one() $validator->validateAssertion($assertion); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AudienceRestriction MUST BE a wellformed uri - */ public function test_conditions_audience_must_be_well_formed_uri_string() { + $this->expectExceptionMessage("AudienceRestriction MUST BE a wellformed uri"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); diff --git a/tests/LightSaml/Tests/Validator/Model/NameId/NameIdValidatorTest.php b/tests/LightSaml/Tests/Validator/Model/NameId/NameIdValidatorTest.php index ef065431..37548f58 100644 --- a/tests/LightSaml/Tests/Validator/Model/NameId/NameIdValidatorTest.php +++ b/tests/LightSaml/Tests/Validator/Model/NameId/NameIdValidatorTest.php @@ -20,12 +20,10 @@ public function test_ok_if_no_format() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID element has Format attribute 'invalid format' which is not a wellformed absolute uri - */ public function test_invalid_format() { + $this->expectExceptionMessage("NameID element has Format attribute 'invalid format' which is not a wellformed absolute uri"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat('invalid format'); @@ -49,12 +47,10 @@ public function test_valid_email_format() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Value of NameID is not a valid email address according to the IETF RFC 2822 specification - */ public function test_invalid_email_format() { + $this->expectExceptionMessage("Value of NameID is not a valid email address according to the IETF RFC 2822 specification"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_EMAIL) ->setValue('not_an_email'); @@ -66,12 +62,10 @@ public function test_invalid_email_format() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Email Format attribute MUST contain a Value that contains more than whitespace characters - */ public function test_empty_email_format() { + $this->expectExceptionMessage("NameID with Email Format attribute MUST contain a Value that contains more than whitespace characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_EMAIL); @@ -95,12 +89,10 @@ public function test_valid_x509_subject_format() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with X509SubjectName Format attribute MUST contain a Value that contains more than whitespace characters - */ public function test_empty_x509_subject_format() { + $this->expectExceptionMessage("NameID with X509SubjectName Format attribute MUST contain a Value that contains more than whitespace characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_X509_SUBJECT_NAME); @@ -137,12 +129,10 @@ public function test_valid_windows_format_with_out_domain() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Windows Format attribute MUST contain a Value that contains more than whitespace characters - */ public function test_empty_windows_format() { + $this->expectExceptionMessage("NameID with Windows Format attribute MUST contain a Value that contains more than whitespace characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_WINDOWS); @@ -179,12 +169,10 @@ public function test_valid_kerberos_format_short() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Kerberos Format attribute MUST contain a Value that contains a '@' - */ public function test_invalid_kerberos_format() { + $this->expectExceptionMessage("NameID with Kerberos Format attribute MUST contain a Value that contains a '@'"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS) ->setValue('name'); @@ -196,12 +184,10 @@ public function test_invalid_kerberos_format() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Kerberos Format attribute MUST contain a Value with at least 3 characters - */ public function test_invalid_kerberos_format_short() { + $this->expectExceptionMessage("NameID with Kerberos Format attribute MUST contain a Value with at least 3 characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS) ->setValue('a@'); @@ -213,12 +199,10 @@ public function test_invalid_kerberos_format_short() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Kerberos Format attribute MUST contain a Value that contains more than whitespace characters - */ public function test_invalid_kerberos_format_empty() { + $this->expectExceptionMessage("NameID with Kerberos Format attribute MUST contain a Value that contains more than whitespace characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_KERBEROS); @@ -242,12 +226,10 @@ public function test_valid_entity_format() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Entity Format attribute MUST contain a Value that contains more than whitespace characters - */ public function test_invalid_entity_format_empty() { + $this->expectExceptionMessage("NameID with Entity Format attribute MUST contain a Value that contains more than whitespace characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY); @@ -258,12 +240,10 @@ public function test_invalid_entity_format_empty() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Entity Format attribute MUST have a Value that contains no more than 1024 characters - */ public function test_invalid_entity_format_long() { + $this->expectExceptionMessage("NameID with Entity Format attribute MUST have a Value that contains no more than 1024 characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY) ->setValue(str_pad('long_string', 1030, 'x')); @@ -275,12 +255,10 @@ public function test_invalid_entity_format_long() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Entity Format attribute MUST NOT set the NameQualifier attribute - */ public function test_invalid_entity_format_with_name_qualifier() { + $this->expectExceptionMessage("NameID with Entity Format attribute MUST NOT set the NameQualifier attribute"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY) ->setValue('some:entity') @@ -293,12 +271,10 @@ public function test_invalid_entity_format_with_name_qualifier() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Entity Format attribute MUST NOT set the SPNameQualifier attribute - */ public function test_invalid_entity_format_with_sp_name_qualifier() { + $this->expectExceptionMessage("NameID with Entity Format attribute MUST NOT set the SPNameQualifier attribute"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY) ->setValue('some:entity') @@ -311,12 +287,10 @@ public function test_invalid_entity_format_with_sp_name_qualifier() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Entity Format attribute MUST NOT set the SPProvidedID attribute - */ public function test_invalid_entity_format_with_sp_provided_id() { + $this->expectExceptionMessage("NameID with Entity Format attribute MUST NOT set the SPProvidedID attribute"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_ENTITY) ->setValue('some:entity') @@ -359,12 +333,10 @@ public function test_valid_persistent_format_with_other_attributes() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Persistent Format attribute MUST contain a Value that contains more than whitespace characters - */ public function test_invalid_persistent_format_empty() { + $this->expectExceptionMessage("NameID with Persistent Format attribute MUST contain a Value that contains more than whitespace characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_PERSISTENT); @@ -375,12 +347,10 @@ public function test_invalid_persistent_format_empty() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Persistent Format attribute MUST have a Value that contains no more than 256 characters - */ public function test_invalid_persistent_format_long() { + $this->expectExceptionMessage("NameID with Persistent Format attribute MUST have a Value that contains no more than 256 characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_PERSISTENT) ->setValue(str_pad('a', 260, 'x')); @@ -422,12 +392,10 @@ public function test_valid_transient_format_with_other_attributes() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Transient Format attribute MUST contain a Value that contains more than whitespace characters - */ public function test_invalid_transient_format_empty() { + $this->expectExceptionMessage("NameID with Transient Format attribute MUST contain a Value that contains more than whitespace characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT); @@ -438,12 +406,10 @@ public function test_invalid_transient_format_empty() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID with Transient Format attribute MUST have a Value that contains no more than 256 characters - */ public function test_invalid_transient_format_long() { + $this->expectExceptionMessage("NameID with Transient Format attribute MUST have a Value that contains no more than 256 characters"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT) ->setValue(str_pad('a', 260, 'x')); @@ -455,12 +421,10 @@ public function test_invalid_transient_format_long() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage NameID '123456789012345' with Transient Format attribute MUST have a Value with at least 16 characters (the equivalent of 128 bits) - */ public function test_invalid_transient_format_short() { + $this->expectExceptionMessage("NameID '123456789012345' with Transient Format attribute MUST have a Value with at least 16 characters (the equivalent of 128 bits)"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $nameId = new NameID(); $nameId->setFormat(SamlConstants::NAME_ID_FORMAT_TRANSIENT) ->setValue('123456789012345'); diff --git a/tests/LightSaml/Tests/Validator/Model/Statement/StatementValidatorTest.php b/tests/LightSaml/Tests/Validator/Model/Statement/StatementValidatorTest.php index d8d116a9..62da25d4 100644 --- a/tests/LightSaml/Tests/Validator/Model/Statement/StatementValidatorTest.php +++ b/tests/LightSaml/Tests/Validator/Model/Statement/StatementValidatorTest.php @@ -13,12 +13,10 @@ class StatementValidatorTest extends BaseTestCase { - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessageRegExp /Unsupported Statement type '\w+'/ - */ public function test_unsupported_statement_fails() { + $this->expectExceptionMessageMatches("/Unsupported Statement type '\w+'/"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $statementMock = $this->getMockForAbstractClass('LightSaml\Model\Assertion\AbstractStatement'); $validator = new StatementValidator(); @@ -26,12 +24,10 @@ public function test_unsupported_statement_fails() $validator->validateStatement($statementMock); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnStatement MUST have an AuthnInstant attribute - */ public function test_authn_statement_fails_with_out_authn_instant() { + $this->expectExceptionMessage("AuthnStatement MUST have an AuthnInstant attribute"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $authnStatement = new AuthnStatement(); $validator = new StatementValidator(); @@ -39,12 +35,10 @@ public function test_authn_statement_fails_with_out_authn_instant() $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage SessionIndex attribute of AuthnStatement must contain at least one non-whitespace character - */ public function test_authn_statement_fails_with_session_index_empty_string() { + $this->expectExceptionMessage("SessionIndex attribute of AuthnStatement must contain at least one non-whitespace character"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $authnStatement = new AuthnStatement(); $authnStatement->setAuthnInstant(123456789) ->setSessionIndex(''); @@ -54,12 +48,10 @@ public function test_authn_statement_fails_with_session_index_empty_string() $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Address attribute of SubjectLocality must contain at least one non-whitespace character - */ public function test_authn_statement_fails_with_subject_locality_address_empty_string() { + $this->expectExceptionMessage("Address attribute of SubjectLocality must contain at least one non-whitespace character"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $subjectLocality = new SubjectLocality(); $subjectLocality->setAddress(''); @@ -72,12 +64,10 @@ public function test_authn_statement_fails_with_subject_locality_address_empty_s $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage DNSName attribute of SubjectLocality must contain at least one non-whitespace character - */ public function test_authn_statement_fails_with_subject_locality_dns_name_empty_string() { + $this->expectExceptionMessage("DNSName attribute of SubjectLocality must contain at least one non-whitespace character"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $subjectLocality = new SubjectLocality(); $subjectLocality->setDNSName(''); @@ -90,12 +80,10 @@ public function test_authn_statement_fails_with_subject_locality_dns_name_empty_ $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnStatement MUST have an AuthnContext element - */ public function test_authn_statement_fails_with_out_authn_context() { + $this->expectExceptionMessage("AuthnStatement MUST have an AuthnContext element"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $authnStatement = new AuthnStatement(); $authnStatement->setAuthnInstant(123456789); @@ -104,12 +92,10 @@ public function test_authn_statement_fails_with_out_authn_context() $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnContext element MUST contain at least one AuthnContextClassRef, AuthnContextDecl or AuthnContextDeclRef element - */ public function test_authn_statement_fails_with_empty_authn_context() { + $this->expectExceptionMessage("AuthnContext element MUST contain at least one AuthnContextClassRef, AuthnContextDecl or AuthnContextDeclRef element"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $authnContext = new AuthnContext(); $authnStatement = new AuthnStatement(); @@ -121,12 +107,10 @@ public function test_authn_statement_fails_with_empty_authn_context() $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnContext MUST NOT contain more than two elements - */ public function test_authn_statement_fails_with_authn_context_with_more_then_two_elements() { + $this->expectExceptionMessage("AuthnContext MUST NOT contain more than two elements"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $authnContext = new AuthnContext(); $authnContext->setAuthnContextClassRef('AuthnContextClassRef') ->setAuthnContextDecl('AuthnContextDecl') @@ -141,12 +125,10 @@ public function test_authn_statement_fails_with_authn_context_with_more_then_two $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnContextClassRef has a value which is not a wellformed absolute uri - */ public function test_authn_context_class_ref_must_be_well_formed_uri_string() { + $this->expectExceptionMessage("AuthnContextClassRef has a value which is not a wellformed absolute uri"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $authnContext = new AuthnContext(); $authnContext->setAuthnContextClassRef('in valid'); @@ -159,12 +141,10 @@ public function test_authn_context_class_ref_must_be_well_formed_uri_string() $validator->validateStatement($authnStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AuthnContextDeclRef has a value which is not a wellformed absolute uri - */ public function test_authn_context_decl_ref_must_be_well_formed_uri_string() { + $this->expectExceptionMessage("AuthnContextDeclRef has a value which is not a wellformed absolute uri"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $authnContext = new AuthnContext(); $authnContext->setAuthnContextDeclRef('in valid'); @@ -193,12 +173,10 @@ public function test_authn_statement_ok() $this->assertTrue(true); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage AttributeStatement MUST contain at least one Attribute or EncryptedAttribute - */ public function test_empty_attribute_statement_fails() { + $this->expectExceptionMessage("AttributeStatement MUST contain at least one Attribute or EncryptedAttribute"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $attributeStatement = new AttributeStatement(); $validator = new StatementValidator(); @@ -206,12 +184,10 @@ public function test_empty_attribute_statement_fails() $validator->validateStatement($attributeStatement); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Name attribute of Attribute element MUST contain at least one non-whitespace character - */ public function test_attribute_with_blank_name_fails() { + $this->expectExceptionMessage("Name attribute of Attribute element MUST contain at least one non-whitespace character"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $attributeStatement = new AttributeStatement(); $attributeStatement->addAttribute(new Attribute(' ')); diff --git a/tests/LightSaml/Tests/Validator/Model/Subject/SubjectValidatorTest.php b/tests/LightSaml/Tests/Validator/Model/Subject/SubjectValidatorTest.php index 3ea40733..609c21ad 100644 --- a/tests/LightSaml/Tests/Validator/Model/Subject/SubjectValidatorTest.php +++ b/tests/LightSaml/Tests/Validator/Model/Subject/SubjectValidatorTest.php @@ -12,12 +12,10 @@ class SubjectValidatorTest extends BaseTestCase { - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Subject MUST contain either an identifier or a subject confirmation - */ public function test_fails_when_no_subject_and_no_subject_confirmation() { + $this->expectExceptionMessage("Subject MUST contain either an identifier or a subject confirmation"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $subject = new Subject(); $nameIdValidatorMock = $this->getNameIdValidatorMock(); @@ -84,12 +82,10 @@ public function test_name_id_validator_is_called_for_subject_confirmation_name_i $validator->validateSubject($subject); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Method attribute of SubjectConfirmation MUST contain at least one non-whitespace character - */ public function test_fails_on_empty_method() { + $this->expectExceptionMessage("Method attribute of SubjectConfirmation MUST contain at least one non-whitespace character"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $subject = new Subject(); $subjectConfirmation = new SubjectConfirmation(); @@ -101,12 +97,10 @@ public function test_fails_on_empty_method() $validator->validateSubject($subject); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage SubjectConfirmation element has Method attribute which is not a wellformed absolute uri - */ public function test_fails_on_invalid_method() { + $this->expectExceptionMessage("SubjectConfirmation element has Method attribute which is not a wellformed absolute uri"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $subject = new Subject(); $subjectConfirmation = new SubjectConfirmation(); @@ -119,12 +113,10 @@ public function test_fails_on_invalid_method() $validator->validateSubject($subject); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage Recipient of SubjectConfirmationData must be a wellformed absolute URI - */ public function test_fails_on_invalid_recipient() { + $this->expectExceptionMessage("Recipient of SubjectConfirmationData must be a wellformed absolute URI"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $subject = new Subject(); $subjectConfirmationData = new SubjectConfirmationData(); @@ -141,12 +133,10 @@ public function test_fails_on_invalid_recipient() $validator->validateSubject($subject); } - /** - * @expectedException \LightSaml\Error\LightSamlValidationException - * @expectedExceptionMessage SubjectConfirmationData NotBefore MUST be less than NotOnOrAfter - */ public function test_fails_on_not_on_or_after_less_then_not_before() { + $this->expectExceptionMessage("SubjectConfirmationData NotBefore MUST be less than NotOnOrAfter"); + $this->expectException(\LightSaml\Error\LightSamlValidationException::class); $subject = new Subject(); $subjectConfirmationData = new SubjectConfirmationData();