3
3
namespace PaymentGatewayLogger ;
4
4
5
5
use Exception ;
6
- use InvalidArgumentException ;
7
6
use Guzzle \Common \Event ;
7
+ use InvalidArgumentException ;
8
8
use Guzzle \Http \Client ;
9
9
use Mockery ;
10
10
use Omnipay \Common \Message \RequestInterface ;
@@ -42,6 +42,11 @@ class OmnipayGatewayRequestSubscriberTest extends TestCase
42
42
*/
43
43
private $ logger ;
44
44
45
+ /**
46
+ * @var string
47
+ */
48
+ private $ requestName = 'test_request_name ' ;
49
+
45
50
/**
46
51
* @return void
47
52
*/
@@ -51,7 +56,6 @@ protected function setUp()
51
56
$ this ->eventDispatcher = $ httpClient ->getEventDispatcher ();
52
57
$ this ->logger = new TestLogger ();
53
58
$ this ->subscriber = new OmnipayGatewayRequestSubscriber ('test ' , $ this ->logger );
54
-
55
59
parent ::setUp ();
56
60
}
57
61
@@ -69,17 +73,17 @@ public function providerLoggingEvents()
69
73
/** @var Exception $exception */
70
74
$ exception = Mockery::mock ('Exception ' );
71
75
72
- $ requestEvent = new RequestEvent ($ request );
73
- $ responseEvent = new ResponseEvent ($ response );
74
- $ errorEvent = new ErrorEvent ($ exception );
76
+ $ requestEvent = new RequestEvent ($ request, $ this -> requestName );
77
+ $ responseEvent = new ResponseEvent ($ response, $ this -> requestName );
78
+ $ errorEvent = new ErrorEvent ($ exception, $ this -> requestName );
75
79
76
80
$ requestRecord = array (
77
81
'level ' => LogLevel::INFO ,
78
82
'message ' => 'omnipay_test ' ,
79
83
'context ' => $ requestEvent ->toArray (),
80
84
);
81
85
$ responseRecord = array (
82
- 'level ' => LogLevel::INFO ,
86
+ 'level ' => LogLevel::NOTICE ,
83
87
'message ' => 'omnipay_test ' ,
84
88
'context ' => $ responseEvent ->toArray (),
85
89
);
@@ -111,10 +115,19 @@ public function testLogging($event_type, $event, array $record)
111
115
$ this ->eventDispatcher ->addSubscriber ($ this ->subscriber );
112
116
$ this ->eventDispatcher ->dispatch ($ event_type , $ event );
113
117
118
+ $ context = $ event ->toArray ();
119
+ $ this ->assertEquals ($ this ->requestName , $ context ['request_name ' ]);
120
+
114
121
if ($ record ['level ' ] === LogLevel::INFO ) {
122
+ $ this ->assertInstanceOf ('Omnipay\Common\Message\RequestInterface ' , $ context ['request ' ]);
115
123
$ this ->assertTrue ($ this ->logger ->hasInfoRecords ());
116
124
$ this ->assertTrue ($ this ->logger ->hasInfo ($ record ));
125
+ } else if ($ record ['level ' ] === LogLevel::NOTICE ) {
126
+ $ this ->assertInstanceOf ('Omnipay\Common\Message\ResponseInterface ' , $ context ['response ' ]);
127
+ $ this ->assertTrue ($ this ->logger ->hasNoticeRecords ());
128
+ $ this ->assertTrue ($ this ->logger ->hasNotice ($ record ));
117
129
} else if ($ record ['level ' ] === LogLevel::ERROR ) {
130
+ $ this ->assertInstanceOf ('\Exception ' , $ context ['error ' ]);
118
131
$ this ->assertTrue ($ this ->logger ->hasErrorRecords ());
119
132
$ this ->assertTrue ($ this ->logger ->hasError ($ record ));
120
133
} else {
0 commit comments