diff --git a/.travis.yml b/.travis.yml index 2c64664..564a507 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,11 @@ php: - 5.5 - 5.6 - 7.0 + - 7.1 - hhvm sudo: false +dist: trusty install: - travis_retry composer update --no-interaction --prefer-dist diff --git a/composer.json b/composer.json index 3808aea..93415f0 100755 --- a/composer.json +++ b/composer.json @@ -15,16 +15,15 @@ "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sns-message-validator/issues" }, - "suggest": { - "aws/aws-sdk-php": "The official Amazon Web Services PHP SDK." - }, "require": { "php": ">=5.4", - "ext-openssl": "*" + "ext-openssl": "*", + "psr/http-message": "^1.0" }, "require-dev": { "phpunit/phpunit": "^4.0", - "squizlabs/php_codesniffer": "^2.3" + "squizlabs/php_codesniffer": "^2.3", + "guzzlehttp/psr7": "^1.4" }, "autoload": { "psr-4": { "Aws\\Sns\\": "src/" } diff --git a/src/Message.php b/src/Message.php index 539e3d8..890b780 100644 --- a/src/Message.php +++ b/src/Message.php @@ -1,6 +1,8 @@ getBody()); + } + + /** + * Creates a Message object from a JSON-decodable string. + * + * @param string $requestBody + * @return Message + */ + private static function fromJsonString($requestBody) + { + $data = json_decode($requestBody, true); if (JSON_ERROR_NONE !== json_last_error() || !is_array($data)) { throw new \RuntimeException('Invalid POST data.'); } diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 904dd67..c0d1486 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -1,8 +1,10 @@ messageData) + ); + $message = Message::fromPsrRequest($request); + $this->assertInstanceOf('Aws\Sns\Message', $message); + } + + /** + * @expectedException \RuntimeException + */ + public function testCreateFromPsr7RequestFailsWithMissingData() + { + $request = new Request( + 'POST', + '/', + [], + 'Not valid JSON' + ); + Message::fromPsrRequest($request); + } + public function testArrayAccess() { $message = new Message($this->messageData);