Page MenuHomeDevCentral

D639.id1598.diff
No OneTemporary

D639.id1598.diff

diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,7 @@
+# Changelog
+All notable changes to this project will be documented in this file.
+This project adheres to [semantic versioning](http://semver.org/).
+
+## [0.0.1] - 2016-09-01
+### Added
+- Initial version
\ No newline at end of file
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<phpunit bootstrap="./vendor/autoload.php">
+ <testsuites>
+ <testsuite name="Library test suite">
+ <directory>./tests/</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist>
+ <directory suffix=".php">src/</directory>
+ </whitelist>
+ </filter>
+</phpunit>
diff --git a/src/MailgunMessage.php b/src/MailgunMessage.php
--- a/src/MailgunMessage.php
+++ b/src/MailgunMessage.php
@@ -58,7 +58,7 @@
*/
public static function loadFromEventPayload (Client $client, $payload, $key) {
$url = self::extractUrlFromEventPayload($payload);
- return self($client, $url, $key);
+ return new self($client, $url, $key);
}
///
diff --git a/src/MailgunMessageFactory.php b/src/MailgunMessageFactory.php
--- a/src/MailgunMessageFactory.php
+++ b/src/MailgunMessageFactory.php
@@ -4,6 +4,8 @@
use GuzzleHttp\Client;
+use stdClass;
+
/**
* Allows to build several MailgunMessage instances
* with the same HTTP client and API key.
@@ -62,10 +64,10 @@
}
/**
- * @param object $payload The payload fired by MailGun routing API
+ * @param stdClass $payload The payload fired by MailGun routing API
* @return MailgunMessage
*/
- public function getMessageFromPayload (object $payload) {
+ public function getMessageFromPayload (stdClass $payload) {
return MailgunMessage::loadFromEventPayload(
$this->client, $payload, $this->key
);
@@ -74,10 +76,10 @@
/**
* Gets a JSON representation of a mail.
*
- * @param object $payload The payload fired by MailGun routing API
+ * @param stdClass $payload The payload fired by MailGun routing API
* @return object
*/
- public function fetchMessageFromPayload (object $payload) {
+ public function fetchMessageFromPayload (stdClass $payload) {
return $this->getMessageFromPayload($payload)->get();
}
diff --git a/tests/MailgunMessageFactoryTest.php b/tests/MailgunMessageFactoryTest.php
--- a/tests/MailgunMessageFactoryTest.php
+++ b/tests/MailgunMessageFactoryTest.php
@@ -5,7 +5,11 @@
use Keruald\Mailgun\MailgunMessageFactory;
use Keruald\Mailgun\MailgunMessage;
-class MailgunMessageFactoryTest {
+use PHPUnit_Framework_TestCase as TestCase;
+
+use stdClass;
+
+class MailgunMessageFactoryTest extends TestCase {
use WithMockHttpClient;
@@ -34,18 +38,18 @@
* @expectedException \InvalidArgumentException
*/
public function testGetMessageFromPayloadThrowsExceptionWhenPayloadDoesNotContainUrlInformation () {
- $this->factory->getMessageFromPayload(null);
+ $this->factory->getMessageFromPayload(new stdClass);
}
public function testFetchMessage () {
$message = $this->factory->fetchMessage("http://api/somemessage");
- $this->assertInternalType("string", $message);
+ $this->assertInstanceOf("stdClass", $message);
}
public function testFetchMessageFromPayload () {
$payload = self::mockEventPayload();
$message = $this->factory->fetchMessageFromPayload($payload);
- $this->assertInternalType("string", $message);
+ $this->assertInstanceOf("stdClass", $message);
}
-}
\ No newline at end of file
+}
diff --git a/tests/WithMockHttpClient.php b/tests/WithMockHttpClient.php
--- a/tests/WithMockHttpClient.php
+++ b/tests/WithMockHttpClient.php
@@ -1,7 +1,11 @@
<?php
-use GuzzleHttp\Psr7\Response;
+namespace Keruald\Mailgun\Tests;
+
use GuzzleHttp\Client;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\Psr7\Response;
trait WithMockHttpClient {
@@ -25,7 +29,7 @@
* @return stdClass
*/
public function mockEventPayload () {
- return json_decode(file_get_contents('payload.json'));
+ return json_decode(file_get_contents(__DIR__ . '/payload.json'));
}
///
@@ -38,14 +42,14 @@
protected static function getCustomMockHttpClientHandler ($code, $body, $headers = []) {
return HandlerStack::create(new MockHandler([
new Response($code, $headers, $body),
- ]);
+ ]));
}
/**
* @return string
*/
- protected mockHttpClientResponseBody () {
- return file_get_contents('response.json');
+ protected static function mockHttpClientResponseBody () {
+ return file_get_contents(__DIR__ . '/response.json');
}
}

File Metadata

Mime Type
text/plain
Expires
Mon, Jun 9, 00:52 (14 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2714709
Default Alt Text
D639.id1598.diff (4 KB)

Event Timeline