Skip to content

Commit 336945c

Browse files
committed
Update codensniffer, phpunit, psr/log and fix issues.
1 parent b45ae57 commit 336945c

File tree

9 files changed

+41
-43
lines changed

9 files changed

+41
-43
lines changed

ci/qa/phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,6 @@ parameters:
636636
count: 1
637637
path: ../../src/SAML2/BridgeContainer.php
638638

639-
-
640-
message: '#^Parameter \#1 \$message of method Psr\\Log\\LoggerInterface\:\:debug\(\) expects string, string\|false given\.$#'
641-
identifier: argument.type
642-
count: 1
643-
path: ../../src/SAML2/BridgeContainer.php
644-
645639
-
646640
message: '#^Property Surfnet\\SamlBundle\\SAML2\\Extensions\\Chunk\:\:\$value \(DOMElement\) does not accept DOMElement\|null\.$#'
647641
identifier: assign.propertyType

ci/qa/rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
->withAttributesSets(all: true)
1212
->withComposerBased(phpunit: true, symfony: true)
1313
->withTypeCoverageLevel(10)
14-
->withDeadCodeLevel(0)
15-
->withCodeQualityLevel(0);
14+
->withDeadCodeLevel(10)
15+
->withCodeQualityLevel(10);

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"php": "^8.1",
1010
"ext-dom": "*",
1111
"ext-openssl": "*",
12+
"psr/log": "^3.0",
1213
"robrichards/xmlseclibs": "^3.1.1",
1314
"simplesamlphp/saml2": "^4.6",
1415
"symfony/dependency-injection": "^6.3",
@@ -25,11 +26,10 @@
2526
"phpmd/phpmd": "^2.6",
2627
"phpstan/extension-installer": "^1.4",
2728
"phpstan/phpstan": "^2.1",
28-
"phpunit/phpunit": "^10.0.0",
29-
"psr/log": "~1.0",
29+
"phpunit/phpunit": "^11.0.0",
3030
"rector/rector": "^2.2",
31-
"sebastian/exporter": "^5.0.0",
32-
"squizlabs/php_codesniffer": "^3.7.1",
31+
"sebastian/exporter": "^6.3",
32+
"squizlabs/php_codesniffer": "^4.0",
3333
"symfony/phpunit-bridge": "^6.3"
3434
},
3535
"scripts": {

src/DependencyInjection/SurfnetSamlExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function parseRemoteConfiguration(array $remoteConfiguration, ContainerB
167167
*/
168168
private function parseRemoteIdentityProviderConfigurations(array $identityProviders, ContainerBuilder $container): void
169169
{
170-
$definitions = array_map(fn($config) => $this->parseRemoteIdentityProviderConfiguration($config), $identityProviders);
170+
$definitions = array_map(fn($config): Definition => $this->parseRemoteIdentityProviderConfiguration($config), $identityProviders);
171171

172172
$definition = new Definition(StaticIdentityProviderRepository::class, [
173173
$definitions
@@ -200,7 +200,7 @@ private function parseRemoteIdentityProviderConfiguration(array $identityProvide
200200
*/
201201
private function parseRemoteServiceProviderConfigurations(array $serviceProviders, ContainerBuilder $container): void
202202
{
203-
$definitions = array_map(fn($config) => $this->parseRemoteServiceProviderConfiguration($config), $serviceProviders);
203+
$definitions = array_map(fn($config): Definition => $this->parseRemoteServiceProviderConfiguration($config), $serviceProviders);
204204

205205
$definition = new Definition(StaticServiceProviderRepository::class, [
206206
$definitions

src/Monolog/SamlAuthenticationLogger.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
namespace Surfnet\SamlBundle\Monolog;
2121

2222
use Psr\Log\LoggerInterface;
23-
use Surfnet\SamlBundle\Exception\RuntimeException;
2423

2524
/**
2625
* Decorates a PSR logger and adds information pertaining to a SAML request procedure to each message's context.
@@ -46,47 +45,47 @@ public function forAuthentication(string $requestId): self
4645
return $logger;
4746
}
4847

49-
public function emergency($message, array $context = []): void
48+
public function emergency(string|\Stringable $message, array $context = []): void
5049
{
5150
$this->logger->emergency($message, $this->modifyContext($context));
5251
}
5352

54-
public function alert($message, array $context = []): void
53+
public function alert(string|\Stringable $message, array $context = []): void
5554
{
5655
$this->logger->alert($message, $this->modifyContext($context));
5756
}
5857

59-
public function critical($message, array $context = []): void
58+
public function critical(string|\Stringable $message, array $context = []): void
6059
{
6160
$this->logger->critical($message, $this->modifyContext($context));
6261
}
6362

64-
public function error($message, array $context = []): void
63+
public function error(string|\Stringable $message, array $context = []): void
6564
{
6665
$this->logger->error($message, $this->modifyContext($context));
6766
}
6867

69-
public function warning($message, array $context = []): void
68+
public function warning(string|\Stringable $message, array $context = []): void
7069
{
7170
$this->logger->warning($message, $this->modifyContext($context));
7271
}
7372

74-
public function notice($message, array $context = []): void
73+
public function notice(string|\Stringable $message, array $context = []): void
7574
{
7675
$this->logger->notice($message, $this->modifyContext($context));
7776
}
7877

79-
public function info($message, array $context = []): void
78+
public function info(string|\Stringable $message, array $context = []): void
8079
{
8180
$this->logger->info($message, $this->modifyContext($context));
8281
}
8382

84-
public function debug($message, array $context = []): void
83+
public function debug(string|\Stringable $message, array $context = []): void
8584
{
8685
$this->logger->debug($message, $this->modifyContext($context));
8786
}
8887

89-
public function log($level, $message, array $context = []): void
88+
public function log($level, string|\Stringable $message, array $context = []): void
9089
{
9190
$this->logger->log($level, $message, $this->modifyContext($context));
9291
}

src/SAML2/BridgeContainer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use BadMethodCallException;
2222
use DOMElement;
2323
use Psr\Log\LoggerInterface;
24+
use RuntimeException;
2425
use SAML2\Compat\AbstractContainer;
2526

2627
/**
@@ -55,6 +56,10 @@ public function debugMessage($message, $type): void
5556
$message = $message->ownerDocument->saveXML($message);
5657
}
5758

59+
if (!is_string($message)) {
60+
throw new RuntimeException("Debug message error: could not convert message to string.");
61+
}
62+
5863
$this->logger->debug($message, ['type' => $type]);
5964
}
6065

src/Tests/Unit/Http/PostBindingAuthnRequestTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function setUp(): void
6868
ContainerSingleton::setContainer(new MockContainer());
6969
}
7070

71-
public function test_receive_signed_authn_request_happy_flow()
71+
public function test_receive_signed_authn_request_happy_flow(): void
7272
{
7373
$requestUri = 'https://stepup.example.com/sso?with-some-addition=true';
7474
$post = [
@@ -100,7 +100,7 @@ public function test_receive_signed_authn_request_happy_flow()
100100
self::assertEquals('https://stepup.example.com/sso', $authnRequest->getDestination());
101101
}
102102

103-
public function test_receive_signed_authn_request_must_have_sp_repo()
103+
public function test_receive_signed_authn_request_must_have_sp_repo(): void
104104
{
105105
$requestUri = 'https://stepup.example.com/sso?with-some-addition=true';
106106
$post = [
@@ -118,7 +118,7 @@ public function test_receive_signed_authn_request_must_have_sp_repo()
118118
$postBinding->receiveSignedAuthnRequestFrom($request);
119119
}
120120

121-
public function test_receive_signed_authn_request_http_request_must_be_post()
121+
public function test_receive_signed_authn_request_http_request_must_be_post(): void
122122
{
123123
$requestUri = 'https://stepup.example.com/sso?with-some-addition=true';
124124
$post = [
@@ -132,7 +132,7 @@ public function test_receive_signed_authn_request_http_request_must_be_post()
132132
$this->postBinding->receiveSignedAuthnRequestFrom($request);
133133
}
134134

135-
public function test_receive_signed_authn_request_must_have_destination()
135+
public function test_receive_signed_authn_request_must_have_destination(): void
136136
{
137137
$requestUri = 'https://stepup.example.com/sso?with-some-addition=true';
138138
$post = [
@@ -147,7 +147,7 @@ public function test_receive_signed_authn_request_must_have_destination()
147147
$this->postBinding->receiveSignedAuthnRequestFrom($request);
148148
}
149149

150-
public function test_receive_signed_authn_request_request_uri_must_start_with_destination()
150+
public function test_receive_signed_authn_request_request_uri_must_start_with_destination(): void
151151
{
152152
$requestUri = 'https://stepup.example.com/sso';
153153
$post = [
@@ -163,7 +163,7 @@ public function test_receive_signed_authn_request_request_uri_must_start_with_de
163163
$this->postBinding->receiveSignedAuthnRequestFrom($request);
164164
}
165165

166-
public function test_receive_signed_authn_request_unknown_sp()
166+
public function test_receive_signed_authn_request_unknown_sp(): void
167167
{
168168
$requestUri = 'https://stepup.example.com/sso';
169169
$post = [
@@ -184,7 +184,7 @@ public function test_receive_signed_authn_request_unknown_sp()
184184
$this->postBinding->receiveSignedAuthnRequestFrom($request);
185185
}
186186

187-
public function test_receive_signed_authn_request_signature_validation_failed()
187+
public function test_receive_signed_authn_request_signature_validation_failed(): void
188188
{
189189
$requestUri = 'https://stepup.example.com/sso';
190190
$post = [

src/Tests/Unit/Http/PostBindingSamlResponseTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private function buildRequest(): Request
7979
return new Request([], $post, [], [], [], ['REQUEST_URI' => $requestUri]);
8080
}
8181

82-
public function test_process_response_happy_flow()
82+
public function test_process_response_happy_flow(): void
8383
{
8484
$request = $this->buildRequest();
8585
$request->setMethod(Request::METHOD_POST);
@@ -97,7 +97,7 @@ public function test_process_response_happy_flow()
9797
self::assertInstanceOf(Assertion::class, $samlResponse);
9898
}
9999

100-
public function test_process_response_must_have_saml_response()
100+
public function test_process_response_must_have_saml_response(): void
101101
{
102102
$requestUri = 'https://stepup.example.com/';
103103
$post = [
@@ -114,7 +114,7 @@ public function test_process_response_must_have_saml_response()
114114
$this->postBinding->processResponse($request, $idp, $sp);
115115
}
116116

117-
public function test_process_response_precondition_not_met()
117+
public function test_process_response_precondition_not_met(): void
118118
{
119119
$request = $this->buildRequest();
120120

@@ -131,7 +131,7 @@ public function test_process_response_precondition_not_met()
131131
self::expectException(NoAuthnContextSamlResponseException::class);
132132
$this->postBinding->processResponse($request, $idp, $sp);
133133
}
134-
public function test_process_response_authn_failed()
134+
public function test_process_response_authn_failed(): void
135135
{
136136
$request = $this->buildRequest();
137137

@@ -148,7 +148,7 @@ public function test_process_response_authn_failed()
148148
self::expectException(AuthnFailedSamlResponseException::class);
149149
$this->postBinding->processResponse($request, $idp, $sp);
150150
}
151-
public function test_process_response_other_precondition_not_met()
151+
public function test_process_response_other_precondition_not_met(): void
152152
{
153153
$request = $this->buildRequest();
154154

src/Tests/Unit/SAML2/AuthnRequestTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class AuthnRequestTest extends TestCase
5555
</samlp:AuthnRequest>
5656
AUTHNREQUEST_NO_SUBJECT;
5757

58-
private string $authRequestIsPassiveFalseAndNoForceAuthnFalse = <<<AUTHNREQUEST_IS_PASSIVE_F_AND_FORCE_AUTH_F
58+
private static string $authRequestIsPassiveFalseAndNoForceAuthnFalse = <<<AUTHNREQUEST_IS_PASSIVE_F_AND_FORCE_AUTH_F
5959
<samlp:AuthnRequest
6060
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
6161
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
@@ -68,7 +68,7 @@ class AuthnRequestTest extends TestCase
6868
</samlp:AuthnRequest>
6969
AUTHNREQUEST_IS_PASSIVE_F_AND_FORCE_AUTH_F;
7070

71-
private string $authRequestIsPassiveAndForceAuthnFalse = <<<AUTHNREQUEST_IS_PASSIVE_AND_FORCE_AUTHN_F
71+
private static string $authRequestIsPassiveAndForceAuthnFalse = <<<AUTHNREQUEST_IS_PASSIVE_AND_FORCE_AUTHN_F
7272
<samlp:AuthnRequest
7373
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
7474
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
@@ -82,7 +82,7 @@ class AuthnRequestTest extends TestCase
8282
</samlp:AuthnRequest>
8383
AUTHNREQUEST_IS_PASSIVE_AND_FORCE_AUTHN_F;
8484

85-
private string $authRequestIsPassiveFalseAndForceAuthn = <<<AUTHNREQUEST_IS_PASSIVE_F_AND_FORCE_AUTHN
85+
private static string $authRequestIsPassiveFalseAndForceAuthn = <<<AUTHNREQUEST_IS_PASSIVE_F_AND_FORCE_AUTHN
8686
<samlp:AuthnRequest
8787
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
8888
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
@@ -154,12 +154,12 @@ public function is_passive_and_force_authn_can_be_retrieved_from_the_authnreques
154154
$this->assertEquals($forceAuthn, $authnRequest->isForceAuthn());
155155
}
156156

157-
public function provideIsPassiveAndForceAuthnCombinations(): array
157+
public static function provideIsPassiveAndForceAuthnCombinations(): array
158158
{
159159
return [
160-
'isPassive false and ForceAuthn false' => [$this->authRequestIsPassiveFalseAndNoForceAuthnFalse, false, false],
161-
'isPassive and ForceAuthn false' => [$this->authRequestIsPassiveAndForceAuthnFalse, true, false],
162-
'isPassive false and ForceAuthn' => [$this->authRequestIsPassiveFalseAndForceAuthn, false, true]
160+
'isPassive false and ForceAuthn false' => [self::$authRequestIsPassiveFalseAndNoForceAuthnFalse, false, false],
161+
'isPassive and ForceAuthn false' => [self::$authRequestIsPassiveAndForceAuthnFalse, true, false],
162+
'isPassive false and ForceAuthn' => [self::$authRequestIsPassiveFalseAndForceAuthn, false, true]
163163
];
164164
}
165165

0 commit comments

Comments
 (0)