Skip to content

Commit de457ea

Browse files
chore: changes to meet php>=7.2.5 requirements (#66)
Since we are deprecating php<7.2.5 some code changes are done here, due to that a bump for some dependencies is also done in this commit. One example is phpunit which requires that test units extends from PHPUnit\Framework\TestCas and no from \PHPUnit_Framework_TestCase. Another example is that the annotations @ExpectedException, @expectedExceptionMessage, @expectedExceptionMessageRegExp, among others, are deprecated in phpunit 9, and instead the code had to be refactored to use the recommended function for each annotation, such as instead of @ExpectedException we need to use expectException(exceptionClassName), etc.
1 parent ea20e69 commit de457ea

File tree

4 files changed

+48
-68
lines changed

4 files changed

+48
-68
lines changed

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
"issues": "https://github.com/aws/aws-sns-message-validator/issues"
1717
},
1818
"require": {
19-
"php": ">=5.4",
19+
"php": ">=7.2.5",
2020
"ext-openssl": "*",
21-
"psr/http-message": "^1.0"
21+
"psr/http-message": "^1.0 || ^2.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit": "^4.0",
24+
"phpunit/phpunit": "^5.6.3 || ^8.5 || ^9.5",
2525
"squizlabs/php_codesniffer": "^2.3",
26-
"guzzlehttp/psr7": "^1.4"
26+
"guzzlehttp/psr7": "^1.9.1 || ^2.4.5",
27+
"yoast/phpunit-polyfills": "^1.0"
28+
2729
},
2830
"autoload": {
2931
"psr-4": { "Aws\\Sns\\": "src/" }

tests/FunctionalValidationsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace Aws\Sns;
44

5+
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
6+
57
/**
68
* @covers Aws\Sns\MessageValidator
79
* @covers Aws\Sns\Message
810
*/
9-
class FunctionalValidationsTest extends \PHPUnit_Framework_TestCase
11+
class FunctionalValidationsTest extends TestCase
1012
{
1113
private static $certificate =
1214
'-----BEGIN CERTIFICATE-----

tests/MessageTest.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
namespace Aws\Sns;
33

44
use GuzzleHttp\Psr7\Request;
5+
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
56

67
/**
78
* @covers \Aws\Sns\Message
89
*/
9-
class MessageTest extends \PHPUnit_Framework_TestCase
10+
class MessageTest extends TestCase
1011
{
1112
public $messageData = array(
1213
'Message' => 'a',
@@ -25,7 +26,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
2526
public function testGetters()
2627
{
2728
$message = new Message($this->messageData);
28-
$this->assertInternalType('array', $message->toArray());
29+
$this->assertIsArray($message->toArray());
2930

3031
foreach ($this->messageData as $key => $expectedValue) {
3132
$this->assertTrue(isset($message[$key]));
@@ -65,29 +66,23 @@ public function messageTypeProvider()
6566
];
6667
}
6768

68-
/**
69-
* @expectedException \InvalidArgumentException
70-
*/
7169
public function testConstructorFailsWithNoType()
7270
{
71+
$this->expectException(\InvalidArgumentException::class);
7372
$data = $this->messageData;
7473
unset($data['Type']);
7574
new Message($data);
7675
}
7776

78-
/**
79-
* @expectedException \InvalidArgumentException
80-
*/
8177
public function testConstructorFailsWithMissingData()
8278
{
79+
$this->expectException(\InvalidArgumentException::class);
8380
new Message(['Type' => 'Notification']);
8481
}
8582

86-
/**
87-
* @expectedException \InvalidArgumentException
88-
*/
8983
public function testRequiresTokenAndSubscribeUrlForSubscribeMessage()
9084
{
85+
$this->expectException(\InvalidArgumentException::class);
9186
new Message(
9287
['Type' => 'SubscriptionConfirmation'] + array_diff_key(
9388
$this->messageData,
@@ -96,11 +91,9 @@ public function testRequiresTokenAndSubscribeUrlForSubscribeMessage()
9691
);
9792
}
9893

99-
/**
100-
* @expectedException \InvalidArgumentException
101-
*/
10294
public function testRequiresTokenAndSubscribeUrlForUnsubscribeMessage()
10395
{
96+
$this->expectException(\InvalidArgumentException::class);
10497
new Message(
10598
['Type' => 'UnsubscribeConfirmation'] + array_diff_key(
10699
$this->messageData,
@@ -125,19 +118,15 @@ public function testCanCreateFromRawPost()
125118
unset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE']);
126119
}
127120

128-
/**
129-
* @expectedException \RuntimeException
130-
*/
131121
public function testCreateFromRawPostFailsWithMissingHeader()
132122
{
123+
$this->expectException(\RuntimeException::class);
133124
Message::fromRawPostData();
134125
}
135126

136-
/**
137-
* @expectedException \RuntimeException
138-
*/
139127
public function testCreateFromRawPostFailsWithMissingData()
140128
{
129+
$this->expectException(\RuntimeException::class);
141130
$_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'] = 'Notification';
142131
Message::fromRawPostData();
143132
unset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE']);
@@ -155,11 +144,9 @@ public function testCanCreateFromPsr7Request()
155144
$this->assertInstanceOf('Aws\Sns\Message', $message);
156145
}
157146

158-
/**
159-
* @expectedException \RuntimeException
160-
*/
161147
public function testCreateFromPsr7RequestFailsWithMissingData()
162148
{
149+
$this->expectException(\RuntimeException::class);
163150
$request = new Request(
164151
'POST',
165152
'/',

tests/MessageValidatorTest.php

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<?php
22
namespace Aws\Sns;
33

4+
use Aws\Sns\Exception\InvalidSnsMessageException;
5+
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
6+
47
/**
58
* @covers Aws\Sns\MessageValidator
69
*/
7-
class MessageValidatorTest extends \PHPUnit_Framework_TestCase
10+
class MessageValidatorTest extends TestCase
811
{
912
const VALID_CERT_URL = 'https://sns.foo.amazonaws.com/bar.pem';
1013

1114
private static $pKey;
1215
private static $certificate;
1316

14-
public static function setUpBeforeClass()
17+
public static function set_up_before_class()
1518
{
1619
self::$pKey = openssl_pkey_new();
1720
$csr = openssl_csr_new([], self::$pKey);
@@ -20,7 +23,7 @@ public static function setUpBeforeClass()
2023
openssl_x509_free($x509);
2124
}
2225

23-
public static function tearDownAfterClass()
26+
public static function tear_down_after_class()
2427
{
2528
openssl_pkey_free(self::$pKey);
2629
}
@@ -34,38 +37,32 @@ public function testIsValidReturnsFalseOnFailedValidation()
3437
$this->assertFalse($validator->isValid($message));
3538
}
3639

37-
/**
38-
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
39-
* @expectedExceptionMessage The SignatureVersion "3" is not supported.
40-
*/
4140
public function testValidateFailsWhenSignatureVersionIsInvalid()
4241
{
42+
$this->expectException(InvalidSnsMessageException::class);
43+
$this->expectExceptionMessage('The SignatureVersion "3" is not supported.');
4344
$validator = new MessageValidator($this->getMockCertServerClient());
4445
$message = $this->getTestMessage([
4546
'SignatureVersion' => '3',
4647
]);
4748
$validator->validate($message);
4849
}
4950

50-
/**
51-
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
52-
* @expectedExceptionMessage The certificate is located on an invalid domain.
53-
*/
5451
public function testValidateFailsWhenCertUrlInvalid()
5552
{
53+
$this->expectException(InvalidSnsMessageException::class);
54+
$this->expectExceptionMessage('The certificate is located on an invalid domain.');
5655
$validator = new MessageValidator();
5756
$message = $this->getTestMessage([
5857
'SigningCertURL' => 'https://foo.amazonaws.com/bar.pem',
5958
]);
6059
$validator->validate($message);
6160
}
6261

63-
/**
64-
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
65-
* @expectedExceptionMessage The certificate is located on an invalid domain.
66-
*/
6762
public function testValidateFailsWhenCertUrlNotAPemFile()
6863
{
64+
$this->expectException(InvalidSnsMessageException::class);
65+
$this->expectExceptionMessage('The certificate is located on an invalid domain.');
6966
$validator = new MessageValidator();
7067
$message = $this->getTestMessage([
7168
'SigningCertURL' => 'https://foo.amazonaws.com/bar',
@@ -88,55 +85,47 @@ function () {
8885
$this->assertTrue($validator->isValid($message));
8986
}
9087

91-
/**
92-
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
93-
* @expectedExceptionMessageRegExp /Cannot get the certificate from ".+"./
94-
*/
9588
public function testValidateFailsWhenCannotGetCertificate()
9689
{
90+
$this->expectException(InvalidSnsMessageException::class);
91+
$this->expectDeprecationMessageMatches('/Cannot get the certificate from ".+"./');
9792
$validator = new MessageValidator($this->getMockHttpClient(false));
9893
$message = $this->getTestMessage();
9994
$validator->validate($message);
10095
}
10196

102-
/**
103-
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
104-
* @expectedExceptionMessage Cannot get the public key from the certificate.
105-
*/
10697
public function testValidateFailsWhenCannotDeterminePublicKey()
10798
{
99+
$this->expectException(InvalidSnsMessageException::class);
100+
$this->expectExceptionMessage('Cannot get the public key from the certificate.');
108101
$validator = new MessageValidator($this->getMockHttpClient());
109102
$message = $this->getTestMessage();
110103
$validator->validate($message);
111104
}
112105

113-
/**
114-
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
115-
* @expectedExceptionMessage The message signature is invalid.
116-
*/
117106
public function testValidateFailsWhenMessageIsInvalid()
118107
{
108+
$this->expectException(InvalidSnsMessageException::class);
109+
$this->expectExceptionMessage('The message signature is invalid.');
119110
$validator = new MessageValidator($this->getMockCertServerClient());
120111
$message = $this->getTestMessage([
121112
'Signature' => $this->getSignature('foo'),
122113
]);
123114
$validator->validate($message);
124115
}
125116

126-
/**
127-
* @expectedException \Aws\Sns\Exception\InvalidSnsMessageException
128-
* @expectedExceptionMessage The message signature is invalid.
129-
*/
130-
public function testValidateFailsWhenSha256MessageIsInvalid()
131-
{
132-
$validator = new MessageValidator($this->getMockCertServerClient());
133-
$message = $this->getTestMessage([
134-
'Signature' => $this->getSignature('foo'),
135-
'SignatureVersion' => '2'
117+
public function testValidateFailsWhenSha256MessageIsInvalid()
118+
{
119+
$this->expectException(InvalidSnsMessageException::class);
120+
$this->expectExceptionMessage('The message signature is invalid.');
121+
$validator = new MessageValidator($this->getMockCertServerClient());
122+
$message = $this->getTestMessage([
123+
'Signature' => $this->getSignature('foo'),
124+
'SignatureVersion' => '2'
136125

137-
]);
138-
$validator->validate($message);
139-
}
126+
]);
127+
$validator->validate($message);
128+
}
140129

141130
public function testValidateSucceedsWhenMessageIsValid()
142131
{

0 commit comments

Comments
 (0)