Skip to content

Commit 4ad07e1

Browse files
johnkaryamacneil
authored andcommitted
Add more tests for AbstractRequest and AbstractResponse. Closes #125
1 parent a9f01ba commit 4ad07e1

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

tests/Omnipay/Common/Message/AbstractRequestTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,56 @@ public function testNotifyUrl()
189189
$this->assertSame($this->request, $this->request->setNotifyUrl('https://www.example.com/notify'));
190190
$this->assertSame('https://www.example.com/notify', $this->request->getNotifyUrl());
191191
}
192+
193+
public function testInitializedParametersAreSet()
194+
{
195+
$params = array('testMode' => 'success');
196+
197+
$this->request->initialize($params);
198+
199+
$this->assertSame($this->request->getTestMode(), 'success');
200+
}
201+
202+
public function testGetParameters()
203+
{
204+
$this->request->setTestMode(true);
205+
$this->request->setToken('asdf');
206+
207+
$expected = array(
208+
'testMode' => true,
209+
'token' => 'asdf',
210+
);
211+
$this->assertEquals($expected, $this->request->getParameters());
212+
}
213+
214+
public function testCanValidateExistingParameters()
215+
{
216+
$this->request->setTestMode(true);
217+
$this->request->setToken('asdf');
218+
219+
$this->assertNull($this->request->validate('testMode', 'token'));
220+
}
221+
222+
/**
223+
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
224+
*/
225+
public function testInvalidParametersThrowsException()
226+
{
227+
$this->request->setTestMode(true);
228+
229+
$this->request->validate('testMode', 'token');
230+
}
231+
232+
public function testNoCurrencyReturnedIfCurrencyNotSet()
233+
{
234+
$this->assertNull($this->request->getCurrencyNumeric());
235+
}
236+
237+
/**
238+
* @expectedException \Omnipay\Common\Exception\RuntimeException
239+
*/
240+
public function testMustSendRequestBeforeGettingResponse()
241+
{
242+
$this->request->getResponse();
243+
}
192244
}

tests/Omnipay/Common/Message/AbstractResponseTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,16 @@ public function testDefaultMethods()
2424
$this->assertNull($response->getData());
2525
$this->assertNull($response->getTransactionReference());
2626
$this->assertNull($response->getMessage());
27+
$this->assertNull($response->getCode());
28+
}
29+
30+
/**
31+
* @expectedException \Omnipay\Common\Exception\RuntimeException
32+
*/
33+
public function testCannotRedirectResponseThatIsNotRedirectResponseInterface()
34+
{
35+
$response = m::mock('\Omnipay\Common\Message\AbstractResponse[isSuccessful,isRedirect]');
36+
37+
$response->getRedirectResponse();
2738
}
2839
}

0 commit comments

Comments
 (0)