Cleanup pass based on prior PRs (#21)

* Updates to stub generation

* More idiomatic fixes from PHP team

* Moved tests from src/tests -> tests, got rid of extension-only tests

* fixed up test paths, regenerated arginfo
This commit is contained in:
Justin Boswell
2021-05-05 13:37:47 -07:00
committed by GitHub
parent 531330e1b2
commit 7e925c92fb
30 changed files with 99 additions and 119 deletions
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\Auth;
use AWS\CRT\NativeResource as NativeResource;
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\Auth;
use AWS\CRT\NativeResource as NativeResource;
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\Auth;
/**
+5 -2
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT;
use AWS\CRT\Internal\Extension;
@@ -102,7 +105,7 @@ final class CRT {
* @param object $elg Pointer to the event loop group to release
*/
function event_loop_group_release($elg) {
return self::$impl->aws_crt_event_loop_group_release($elg);
self::$impl->aws_crt_event_loop_group_release($elg);
}
/**
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\HTTP;
use AWS\CRT\Internal\Encoding;
+5 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\HTTP;
use AWS\CRT\NativeResource;
@@ -12,6 +15,7 @@ abstract class Message extends NativeResource {
private $headers;
public function __construct($method, $path, $query = [], $headers = []) {
parent::__construct();
$this->method = $method;
$this->path = $path;
$this->query = $query;
+5 -2
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\HTTP;
use AWS\CRT\IO\InputStream;
@@ -10,7 +13,7 @@ class Request extends Message {
public function __construct($method, $path, $query = [], $headers = [], $body_stream = null) {
parent::__construct($method, $path, $query, $headers);
if (!is_null($body_stream) && !($body_stream instanceof InputStream)) {
throw \InvalidArgumentException('body_stream must be an ' . InputStream::class);
throw InvalidArgumentException('body_stream must be an instance of ' . InputStream::class);
}
$this->body_stream = $body_stream;
}
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\HTTP;
class Response extends Message {
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\IO;
use AWS\CRT\NativeResource as NativeResource;
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\IO;
use AWS\CRT\NativeResource as NativeResource;
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\Internal;
final class Encoding {
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT\Internal;
use \RuntimeException;
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT;
use AWS\CRT\CRT as CRT;
+4 -1
View File
@@ -1,5 +1,8 @@
<?php
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
namespace AWS\CRT;
final class Options {
-43
View File
@@ -1,43 +0,0 @@
<?php
use AWS\CRT\Auth\AwsCredentials as AwsCredentials;
use AWS\CRT\Auth\StaticCredentialsProvider as StaticCredentialsProvider;
require_once('common.inc');
final class CredentialsTest extends CrtTestCase {
public function testEmptyCredentials() {
$this->expectException(InvalidArgumentException::class);
$creds = new AwsCredentials(AwsCredentials::defaults());
$this->assertNotNull($creds, "Failed to create default/empty credentials");
$creds = null;
}
private function getCredentialsConfig() {
$options = AwsCredentials::defaults();
$options['access_key_id'] = 'TESTAWSACCESSKEYID';
$options['secret_access_key'] = 'TESTSECRETaccesskeyThatDefinitelyDoesntWork';
$options['session_token'] = 'ThisIsMyTestSessionTokenIMadeItUpMyself';
$options['expiration_timepoint_seconds'] = 42;
return $options;
}
public function testCredentialsLifetime() {
$options = $this->getCredentialsConfig();
$creds = new AwsCredentials($options);
$this->assertNotNull($creds, "Failed to create Credentials with options");
$this->assertEquals($creds->access_key_id, $options['access_key_id']);
$this->assertEquals($creds->secret_access_key, $options['secret_access_key']);
$this->assertEquals($creds->session_token, $options['session_token']);
$this->assertEquals($creds->expiration_timepoint_seconds, $options['expiration_timepoint_seconds']);
$creds = null;
}
public function testStaticCredentialsProviderLifetime() {
$options = $this->getCredentialsConfig();
$provider = new StaticCredentialsProvider($options);
$this->assertNotNull($provider, "Failed to create StaticCredentialsProvider");
$provider = null;
}
}
-26
View File
@@ -1,26 +0,0 @@
<?php
use AWS\CRT\CRT;
final class ErrorTest extends PHPUnit_Framework_TestCase {
private static $crt = null;
public static function setUpBeforeClass() {
self::$crt = new CRT();
}
public static function tearDownAfterClass() {
self::$crt = null;
}
public function testNoInitialError() {
$this->assertEquals(0, CRT::last_error());
}
public function testCanResolveErrorName() {
$this->assertEquals("AWS_ERROR_SUCCESS", CRT::error_name(0));
}
public function testCanResolveErrorStr() {
$this->assertEquals("Success.", CRT::error_str(0));
}
}
-22
View File
@@ -1,22 +0,0 @@
<?php
use AWS\CRT\IO\EventLoopGroup as EventLoopGroup;
require_once('common.inc');
final class EventLoopGroupTest extends CrtTestCase {
public function testLifetime() {
$elg = new EventLoopGroup();
$this->assertNotNull($elg, "Failed to create default EventLoopGroup");
$elg = null;
}
public function testConstructionWithOptions() {
$options = EventLoopGroup::defaults();
$options['num_threads'] = 1;
$elg = new EventLoopGroup($options);
$this->assertNotNull($elg, "Failed to create EventLoopGroup with 1 thread");
$elg = null;
}
}
-93
View File
@@ -1,93 +0,0 @@
<?php
use AWS\CRT\HTTP\Message;
use AWS\CRT\HTTP\Headers;
use AWS\CRT\HTTP\Request;
use AWS\CRT\HTTP\Response;
require_once('common.inc');
final class HttpMessageTest extends CrtTestCase {
public function testHeaders() {
$headers = new Headers();
$this->assertSame(0, $headers->count());
}
public function testHeadersMarshalling() {
$headers_array = [
"host" => "s3.amazonaws.com",
"test" => "this is a test header value"
];
$headers = new Headers($headers_array);
$this->assertSame(2, $headers->count());
$this->assertSame($headers_array['host'], $headers->get('host'));
$this->assertSame($headers_array['test'], $headers->get('test'));
$buffer = Headers::marshall($headers);
$headers_copy = Headers::unmarshall($buffer);
$this->assertSame(2, $headers_copy->count());
$this->assertSame($headers_array['host'], $headers_copy->get('host'));
$this->assertSame($headers_array['test'], $headers_copy->get('test'));
}
private function assertMessagesMatch($a, $b) {
$this->assertSame($a->method(), $b->method());
$this->assertSame($a->path(), $b->path());
$this->assertSame($a->query(), $b->query());
$this->assertSame($a->headers()->toArray(), $b->headers()->toArray());
}
public function testRequestMarshalling() {
$headers = [
"host" => "s3.amazonaws.com",
"test" => "this is a test header value"
];
$method = "GET";
$path = "/index.php";
$query = [];
$msg = new Request($method, $path, $query, $headers);
$msg_buf = Request::marshall($msg);
$msg_copy = Request::unmarshall($msg_buf);
$this->assertMessagesMatch($msg, $msg_copy);
}
public function testRequestMarshallingWithQueryParams() {
$headers = [
"host" => "s3.amazonaws.com",
"test" => "this is a test header value"
];
$method = "GET";
$path = "/index.php";
$query = [
'request' => '1',
'test' => 'true',
'answer' => '42',
'foo' => 'bar',
];
$msg = new Request($method, $path, $query, $headers);
$msg_buf = Request::marshall($msg);
$msg_copy = Request::unmarshall($msg_buf);
$this->assertMessagesMatch($msg, $msg_copy);
}
public function testResponseMarshalling() {
$headers = [
"content-length" => "42",
"test" => "this is a test header value"
];
$method = "GET";
$path = "/index.php";
$query = [
'response' => '1'
];
$msg = new Response($method, $path, $query, $headers, 200);
$msg_buf = Request::marshall($msg);
$msg_copy = Request::unmarshall($msg_buf);
$this->assertMessagesMatch($msg, $msg_copy);
}
}
-31
View File
@@ -1,31 +0,0 @@
<?php
use AWS\CRT\IO\InputStream as InputStream;
require_once('common.inc');
final class InputStreamTest extends CrtTestCase {
const MEM_STREAM_CONTENTS = "THIS IS A TEST";
private function getMemoryStream() {
$stream = fopen("php://memory", 'r+');
fputs($stream, self::MEM_STREAM_CONTENTS);
rewind($stream);
return $stream;
}
public function testMemoryStream() {
$mem_stream = $this->getMemoryStream();
$stream = new InputStream($mem_stream);
$this->assertNotNull($stream, "Failed to create InputStream from PHP memory stream");
$this->assertEquals(strlen(self::MEM_STREAM_CONTENTS), $stream->length(), "Stream length doesn't match source buffer");
$this->assertEquals(self::MEM_STREAM_CONTENTS, $stream->read(), "Stream doesn't match source buffer");
$this->assertTrue($stream->eof(), "Stream is not EOF after reading");
$this->assertEquals(0, $stream->seek(0, InputStream::SEEK_BEGIN), "Unable to rewind stream");
$this->assertFalse($stream->eof(), "Stream is EOF after rewinding");
$this->assertEquals(0, $stream->seek(0, InputStream::SEEK_END), "Unable to seek to end of stream");
$this->assertTrue($stream->eof(), "Stream is not EOF after seeking to end");
$stream = null;
}
}
-12
View File
@@ -1,12 +0,0 @@
<?php
use AWS\CRT\CRT as CRT;
abstract class CrtTestCase extends PHPUnit_Framework_TestCase {
// Ensure that after every test there are no errors in the CRT itself
protected function assertPostConditions() {
if (CRT::last_error()) {
$this->fail("Test left an error on the stack: " . CRT::error_name(CRT::last_error()));
}
}
}