Skip to content

Commit 6ff3253

Browse files
authored
Add TestCase that simplify assertion on http form (#209)
1 parent e6e1283 commit 6ff3253

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

Test/TestCase.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace AsyncAws\Core\Test;
4+
5+
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
6+
7+
class TestCase extends PHPUnitTestCase
8+
{
9+
/**
10+
* Asserts that two Body documents are equal.
11+
*/
12+
public static function assertHttpFormEqualsHttpForm(string $expected, string $actual, string $message = '')
13+
{
14+
$expectedArray = \preg_split('/[\n&\s]+/', trim($expected));
15+
$actualArray = \preg_split('/[\n&\s]+/', trim($actual));
16+
17+
self::assertEqualsCanonicalizing($expectedArray, $actualArray, $message);
18+
}
19+
}
20+
21+
// Because AsyncAws use symfony/phpunit-bridge and don't requires phpunit/phpunit, this class may not exits but is required by the generator and static analyzer tools
22+
if (!\class_exists(PHPUnitTestCase::class)) {
23+
class DummyTestCase
24+
{
25+
public static function assertEqualsCanonicalizing($expected, $actual, string $message = ''): void
26+
{
27+
}
28+
}
29+
\class_alias(DummyTestCase::class, PHPUnitTestCase::class);
30+
}

Tests/Unit/Input/AssumeRoleRequestTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use AsyncAws\Core\Sts\Input\AssumeRoleRequest;
66
use AsyncAws\Core\Sts\Input\PolicyDescriptorType;
77
use AsyncAws\Core\Sts\Input\Tag;
8-
use PHPUnit\Framework\TestCase;
8+
use AsyncAws\Core\Test\TestCase;
99

1010
class AssumeRoleRequestTest extends TestCase
1111
{
@@ -35,7 +35,7 @@ public function testRequestBody(): void
3535
]);
3636

3737
/** @see https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html */
38-
$expected = trim('
38+
$expected = '
3939
Action=AssumeRole
4040
&Version=2011-06-15
4141
&RoleArn=arn%3Aaws%3A%3Aiam%3A%3A123456789012%3Arole%2Fdemo
@@ -53,8 +53,8 @@ public function testRequestBody(): void
5353
&TransitiveTagKeys.member.1=Project
5454
&TransitiveTagKeys.member.2=Cost-Center
5555
&ExternalId=123ABC
56-
');
56+
';
5757

58-
self::assertEquals($expected, \str_replace('&', "\n&", $input->requestBody()));
58+
self::assertHttpFormEqualsHttpForm($expected, $input->requestBody());
5959
}
6060
}

Tests/Unit/Input/GetCallerIdentityRequestTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace AsyncAws\Core\Tests\Unit\Input;
44

55
use AsyncAws\Core\Sts\Input\GetCallerIdentityRequest;
6-
use PHPUnit\Framework\TestCase;
6+
use AsyncAws\Core\Test\TestCase;
77

88
class GetCallerIdentityRequestTest extends TestCase
99
{
@@ -12,11 +12,11 @@ public function testRequestBody(): void
1212
$input = new GetCallerIdentityRequest();
1313

1414
/** @see https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html */
15-
$expected = trim('
15+
$expected = '
1616
Action=GetCallerIdentity
1717
&Version=2011-06-15
18-
');
18+
';
1919

20-
self::assertEquals($expected, \str_replace('&', "\n&", $input->requestBody()));
20+
self::assertHttpFormEqualsHttpForm($expected, $input->requestBody());
2121
}
2222
}

0 commit comments

Comments
 (0)