Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions functions/helloworld_get/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DeployTest extends TestCase
/**
* @dataProvider cases
*/
public function testFunction($status_code, $expected): void
public function testFunction($statusCode, $expected): void
{
// Send a request to the function.
$resp = $this->client->get('', [
Expand All @@ -52,7 +52,7 @@ public function testFunction($status_code, $expected): void

// Assert status code.
$this->assertEquals(
$status_code,
$statusCode,
$resp->getStatusCode()
);

Expand Down
4 changes: 2 additions & 2 deletions functions/helloworld_get/test/SystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class SystemTest extends TestCase
/**
* @dataProvider cases
*/
public function testFunction($status_code, $expected): void
public function testFunction($statusCode, $expected): void
{
// Send a request to the function.
$resp = $this->client->get('');

// Assert status code.
$this->assertEquals($status_code, $resp->getStatusCode());
$this->assertEquals($statusCode, $resp->getStatusCode());

// Assert function output.
$actual = trim((string) $resp->getBody());
Expand Down
2 changes: 1 addition & 1 deletion functions/helloworld_get/test/TestCasesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function cases(): array
{
return [
[
'status_code' => 200,
'statusCode' => 200,
'expected' => 'Hello, World!'
],
];
Expand Down
10 changes: 4 additions & 6 deletions functions/helloworld_get/test/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,11 @@ public static function setUpBeforeClass(): void
/**
* @dataProvider cases
*/
public function testFunction($status_code, $expected): void
public function testFunction($statusCode, $expected): void
{
foreach (self::cases() as $test) {
$request = new ServerRequest('GET', '');
$output = $this->runFunction(self::$name, [$request]);
$this->assertContains($expected, $output);
}
$request = new ServerRequest('GET', '');
$output = $this->runFunction(self::$name, [$request]);
$this->assertContains($expected, $output);
}

private static function runFunction($functionName, array $params = []): string
Expand Down
36 changes: 21 additions & 15 deletions functions/helloworld_http/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,26 @@ class DeployTest extends TestCase

private static $name = 'helloHttp';

public function testFunction(): void
{
foreach (self::cases() as $test) {
$body = json_encode($test['body']);
$resp = $this->client->post('', [
'body' => $body,
'query' => $test['query'],
// Uncomment and CURLOPT_VERBOSE debug content will be sent to stdout.
// 'debug' => true,
]);
$actual = trim((string) $resp->getBody());
$this->assertEquals($test['code'], $resp->getStatusCode(), $test['label'] . ':');
// Failures often lead to a large HTML page in the response body.
$this->assertContains($test['expected'], $actual, $test['label'] . ':');
}
/**
* @dataProvider cases
*/
public function testFunction(
$label,
$query,
$body,
$expected,
$statusCode
): void {
$body = json_encode($body);
$resp = $this->client->post('', [
'body' => $body, 'query' => $query ]);
$actual = trim((string) $resp->getBody());
$this->assertEquals(
$statusCode,
$resp->getStatusCode(),
$label . ':'
);
// Failures often lead to a large HTML page in the response body.
$this->assertContains($expected, $actual, $label . ':');
}
}
30 changes: 18 additions & 12 deletions functions/helloworld_http/test/SystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@ class SystemTest extends TestCase

private static $name = 'helloHttp';

public function testFunction(): void
{
foreach (self::cases() as $test) {
$body = json_encode($test['body']);
$resp = $this->client->post('/', [
'body' => $body,
'query' => $test['query'],
]);
$this->assertEquals($test['code'], $resp->getStatusCode(), $test['label'] . ' code:');
$actual = trim((string) $resp->getBody());
$this->assertContains($test['expected'], $actual, $test['label'] . ':');
}
/**
* @dataProvider cases
*/
public function testFunction(
$label,
$query,
$body,
$expected,
$statusCode
): void {
$body = json_encode($body);
$resp = $this->client->post('/', [
'body' => $body,
'query' => $query,
]);
$this->assertEquals($statusCode, $resp->getStatusCode(), $label . ' code:');
$actual = trim((string) $resp->getBody());
$this->assertContains($expected, $actual, $label . ':');
}
}
10 changes: 5 additions & 5 deletions functions/helloworld_http/test/TestCasesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,35 @@ public static function cases(): array
'query' => [],
'body' => [],
'expected' => 'Hello, World!',
'code' => '200',
'statusCode' => '200',
],
[
'label' => 'Querystring Sets Name',
'query' => ['name' => 'Galaxy'],
'body' => [],
'expected' => 'Hello, Galaxy!',
'code' => '200',
'statusCode' => '200',
],
[
'label' => 'Body Sets Name',
'query' => [],
'body' => ['name' => 'Universe'],
'expected' => 'Hello, Universe!',
'code' => '200',
'statusCode' => '200',
],
[
'label' => 'Querystring Overrides Body',
'query' => ['name' => 'Priority'],
'body' => ['name' => 'Overridden'],
'expected' => 'Hello, Priority!',
'code' => '200',
'statusCode' => '200',
],
[
'label' => 'HTML Escape',
'query' => [],
'body' => ['name' => '<script>script</script>'],
'expected' => sprintf('Hello, %s!', '&lt;script&gt;script&lt;/script&gt;'),
'code' => '200',
'statusCode' => '200',
],
];
}
Expand Down
24 changes: 15 additions & 9 deletions functions/helloworld_http/test/UnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,21 @@ public static function setUpBeforeClass(): void
require_once __DIR__ . '/../index.php';
}

public function testFunction(): void
{
foreach (self::cases() as $test) {
$body = json_encode($test['body']);
$request = (new ServerRequest('POST', '/', [], $body))
->withQueryParams($test['query']);
$actual = $this->runFunction(self::$name, [$request]);
$this->assertContains($test['expected'], $actual, $test['label'] . ':');
}
/**
* @dataProvider cases
*/
public function testFunction(
$label,
$query,
$body,
$expected,
$statusCode
): void {
$body = json_encode($body);
$request = (new ServerRequest('POST', '/', [], $body))
->withQueryParams($query);
$actual = $this->runFunction(self::$name, [$request]);
$this->assertContains($expected, $actual, $label . ':');
}

private static function runFunction($functionName, array $params = []): string
Expand Down