From 79f0aa7708a95f44eee32e62961f5bab1fb85a88 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Fri, 3 May 2019 12:11:19 -0400 Subject: [PATCH 1/4] Update readme --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 97564c3..8d258a7 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,14 @@ These events are dispatched via the HTTP client's `EventDispatcherInterface`. For example in the gateway's `sendData()` methods we can do: ```PHP - $request_name; // The name of the API endpoint being called $event_dispatcher = $this->httpClient->getEventDispatcher(); - $event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_BEFORE_SEND, new RequestEvent($request, $request_name)); + $event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_BEFORE_SEND, new RequestEvent($request)); ``` Logging Errors and Responses events can be emitted like so ```PHP - $event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_ERROR new ErrorEvent($exception', $request_name)); - $event_dispatcher->dispatch(Constants::OMNIPAY_RESPONSE_SUCCESS, new ResponseEvent($response, $request_name)); + $event_dispatcher->dispatch(Constants::OMNIPAY_REQUEST_ERROR new ErrorEvent($exception, $request)); + $event_dispatcher->dispatch(Constants::OMNIPAY_RESPONSE_SUCCESS, new ResponseEvent($response)); ``` `OmnipayGatewayRequestSubscriber.php` takes in a logger of type `LoggerInterface` which will listen to and log these events. From 7b050db7ce3aaebdbbfccbf122b7d47e133d9bb4 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Fri, 3 May 2019 12:18:05 -0400 Subject: [PATCH 2/4] Remove manzoj auth from files. Remove request name from event; this should be up to the client to determine --- src/Event/Constants.php | 1 - src/Event/ErrorEvent.php | 8 ++++---- src/Event/RequestEvent.php | 6 ++---- src/Event/ResponseEvent.php | 6 ++---- .../Subscriber/OmnipayGatewayRequestSubscriber.php | 1 - tests/OmnipayGatewayRequestSubscriberTest.php | 13 +++---------- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/Event/Constants.php b/src/Event/Constants.php index 14d0d24..068d1f7 100644 --- a/src/Event/Constants.php +++ b/src/Event/Constants.php @@ -6,7 +6,6 @@ * Class events. * * @package payment-gateway-logger - * @author manzoj * @version 1 */ diff --git a/src/Event/ErrorEvent.php b/src/Event/ErrorEvent.php index e919df9..b14ca61 100644 --- a/src/Event/ErrorEvent.php +++ b/src/Event/ErrorEvent.php @@ -3,7 +3,6 @@ * Error event to be used by the payment gateway logger. * * @package payment-gateway-logger - * @author manzoj * @version 1 */ @@ -11,16 +10,17 @@ use Exception; use Guzzle\Common\Event; +use Omnipay\Common\Message\RequestInterface; class ErrorEvent extends Event { /** * @param Exception $error - * @param string $request_name + * @param RequestInterface $request */ - public function __construct($error, $request_name) + public function __construct($error, $request) { - parent::__construct(array('error' => $error, 'request_name' => $request_name)); + parent::__construct(array('error' => $error, 'request' => $request)); } /** diff --git a/src/Event/RequestEvent.php b/src/Event/RequestEvent.php index c2cfd1c..6fec420 100644 --- a/src/Event/RequestEvent.php +++ b/src/Event/RequestEvent.php @@ -3,7 +3,6 @@ * Request event to be used by the payment gateway logger. * * @package payment-gateway-logger - * @author manzoj * @version 1 */ @@ -16,11 +15,10 @@ class RequestEvent extends Event { /** * @param RequestInterface $request - * @param string $request_name */ - public function __construct($request, $request_name) + public function __construct($request) { - parent::__construct(array('request' => $request, 'request_name' => $request_name)); + parent::__construct(array('request' => $request)); } /** diff --git a/src/Event/ResponseEvent.php b/src/Event/ResponseEvent.php index fc35dda..6ed650b 100644 --- a/src/Event/ResponseEvent.php +++ b/src/Event/ResponseEvent.php @@ -3,7 +3,6 @@ * Response event to be used by the payment gateway logger. * * @package payment-gateway-logger - * @author manzoj * @version 1 */ @@ -16,11 +15,10 @@ class ResponseEvent extends Event { /** * @param ResponseInterface $response - * @param string $request_name */ - public function __construct($response, $request_name) + public function __construct($response) { - parent::__construct(array('response' => $response, 'request_name' => $request_name)); + parent::__construct(array('response' => $response)); } /** diff --git a/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php b/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php index 1531398..ce5f57f 100644 --- a/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php +++ b/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php @@ -3,7 +3,6 @@ * payment-gateway-logger * * @package payment-gateway-logger - * @author manzoj * @version 1 */ diff --git a/tests/OmnipayGatewayRequestSubscriberTest.php b/tests/OmnipayGatewayRequestSubscriberTest.php index 3f6e8d2..3205adf 100644 --- a/tests/OmnipayGatewayRequestSubscriberTest.php +++ b/tests/OmnipayGatewayRequestSubscriberTest.php @@ -22,7 +22,6 @@ * payment-gateway-logger * * @package payment-gateway-logger - * @author manzoj * @version 1 */ @@ -42,11 +41,6 @@ class OmnipayGatewayRequestSubscriberTest extends TestCase */ private $logger; - /** - * @var string - */ - private $requestName = 'test_request_name'; - /** * @return void */ @@ -73,9 +67,9 @@ public function providerLoggingEvents() /** @var Exception $exception */ $exception = Mockery::mock('Exception'); - $requestEvent = new RequestEvent($request, $this->requestName); - $responseEvent = new ResponseEvent($response, $this->requestName); - $errorEvent = new ErrorEvent($exception, $this->requestName); + $requestEvent = new RequestEvent($request); + $responseEvent = new ResponseEvent($response); + $errorEvent = new ErrorEvent($exception, $request); $requestRecord = array( 'level' => LogLevel::INFO, @@ -116,7 +110,6 @@ public function testLogging($event_type, $event, array $record) $this->eventDispatcher->dispatch($event_type, $event); $context = $event->toArray(); - $this->assertEquals($this->requestName, $context['request_name']); if ($record['level'] === LogLevel::INFO) { $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $context['request']); From 22f24e2d8e4c439cf2d808dd933c245d79e4b6e9 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Sun, 5 May 2019 18:27:25 -0400 Subject: [PATCH 3/4] update docbloc to include request object in ErrorEvent --- src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php b/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php index ce5f57f..2bd1f25 100644 --- a/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php +++ b/src/Event/Subscriber/OmnipayGatewayRequestSubscriber.php @@ -101,7 +101,8 @@ public function onOmnipayResponseSuccess(Event $event) * * The event will be converted to an array before being logged. It will contain the following properties: * array( - * 'error' => Exception + * 'error' => Exception, + * 'request' => \Omnipay\Common\Message\AbstractRequest * ) * @param Event $event * @return void From c23af9a882e7506e56ea0c6543b57fe4a02ab2a2 Mon Sep 17 00:00:00 2001 From: "J.C. Manzo" Date: Sun, 5 May 2019 23:21:11 -0400 Subject: [PATCH 4/4] Add assertion for checking that ErrorEvent contains the request object --- tests/OmnipayGatewayRequestSubscriberTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/OmnipayGatewayRequestSubscriberTest.php b/tests/OmnipayGatewayRequestSubscriberTest.php index 3205adf..f15286b 100644 --- a/tests/OmnipayGatewayRequestSubscriberTest.php +++ b/tests/OmnipayGatewayRequestSubscriberTest.php @@ -121,6 +121,7 @@ public function testLogging($event_type, $event, array $record) $this->assertTrue($this->logger->hasNotice($record)); } else if ($record['level'] === LogLevel::ERROR) { $this->assertInstanceOf('\Exception', $context['error']); + $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $context['request']); $this->assertTrue($this->logger->hasErrorRecords()); $this->assertTrue($this->logger->hasError($record)); } else {