-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Recca Tsai
committed
Feb 7, 2017
1 parent
0d81b28
commit a331f62
Showing
18 changed files
with
352 additions
and
708 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,47 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Tests\Action\Api; | ||
|
||
use Mockery as m; | ||
use Payum\Core\Reply\HttpResponse; | ||
use PHPUnit\Framework\TestCase; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\CreateTransaction; | ||
use PayumTW\Mypay\Action\Api\CreateTransactionAction; | ||
|
||
class CreateTransactionActionTest extends PHPUnit_Framework_TestCase | ||
class CreateTransactionActionTest extends TestCase | ||
{ | ||
public function tearDown() | ||
protected function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function test_redirect_to_mypay() | ||
/** | ||
* @expectedException Payum\Core\Reply\HttpRedirect | ||
*/ | ||
public function testExecute() | ||
{ | ||
/* | ||
|------------------------------------------------------------ | ||
| Arrange | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$api = m::spy('PayumTW\Mypay\Api'); | ||
$request = m::spy('PayumTW\Mypay\Request\Api\CreateTransaction'); | ||
$details = new ArrayObject([ | ||
'url' => 'foo.url', | ||
]); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Act | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$request | ||
->shouldReceive('getModel')->twice()->andReturn($details); | ||
|
||
$api | ||
->shouldReceive('createTransaction')->once()->andReturn($details->toUnsafeArray()); | ||
|
||
$action = new CreateTransactionAction(); | ||
$action->setApi($api); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Assert | ||
|------------------------------------------------------------ | ||
*/ | ||
$request = new CreateTransaction($details = new ArrayObject(['foo' => 'bar'])); | ||
$action->setApi( | ||
$api = m::mock('PayumTW\Mypay\Api') | ||
); | ||
$api->shouldReceive('createTransaction')->once()->with((array) $details)->andReturn(['url' => 'foo']); | ||
|
||
try { | ||
$action->execute($request); | ||
} catch (HttpResponse $response) { | ||
$this->assertInstanceOf('Payum\Core\Reply\HttpRedirect', $response); | ||
} | ||
|
||
$request->shouldHaveReceived('getModel')->twice(); | ||
$api->shouldHaveReceived('createTransaction')->once(); | ||
$action->execute($request); | ||
} | ||
|
||
/** | ||
* @expectedException LogicException | ||
*/ | ||
public function test_redirect_to_mypay_fail() | ||
public function testExecuteFail() | ||
{ | ||
/* | ||
|------------------------------------------------------------ | ||
| Arrange | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$api = m::spy('PayumTW\Mypay\Api'); | ||
$request = m::spy('PayumTW\Mypay\Request\Api\CreateTransaction'); | ||
$details = new ArrayObject([ | ||
]); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Act | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$request | ||
->shouldReceive('getModel')->twice()->andReturn($details); | ||
|
||
$api | ||
->shouldReceive('createTransaction')->once()->andReturn($details->toUnsafeArray()); | ||
|
||
$action = new CreateTransactionAction(); | ||
$action->setApi($api); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Assert | ||
|------------------------------------------------------------ | ||
*/ | ||
$request = new CreateTransaction($details = new ArrayObject(['foo' => 'bar'])); | ||
$action->setApi( | ||
$api = m::mock('PayumTW\Mypay\Api') | ||
); | ||
$api->shouldReceive('createTransaction')->once()->with((array) $details)->andReturn(['foo' => 'foo']); | ||
|
||
$action->execute($request); | ||
$request->shouldHaveReceived('getModel')->twice(); | ||
$api->shouldHaveReceived('createTransaction')->once(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,29 @@ | ||
<?php | ||
|
||
namespace PayumTW\Mypay\Tests\Action\Api; | ||
|
||
use Mockery as m; | ||
use PHPUnit\Framework\TestCase; | ||
use Payum\Core\Bridge\Spl\ArrayObject; | ||
use PayumTW\Mypay\Request\Api\GetTransactionData; | ||
use PayumTW\Mypay\Action\Api\GetTransactionDataAction; | ||
|
||
class GetTransactionDataActionTest extends PHPUnit_Framework_TestCase | ||
class GetTransactionDataActionTest extends TestCase | ||
{ | ||
public function tearDown() | ||
protected function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function test_get_transaction_data() | ||
public function testExecute() | ||
{ | ||
/* | ||
|------------------------------------------------------------ | ||
| Arrange | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$api = m::spy('PayumTW\Mypay\Api'); | ||
$request = m::spy('PayumTW\Mypay\Request\Api\GetTransactionData'); | ||
$details = m::mock(new ArrayObject([])); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Act | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$request | ||
->shouldReceive('getModel')->andReturn($details); | ||
|
||
$api | ||
->shouldReceive('getTransactionData')->andReturn([ | ||
'RspCode' => '1', | ||
]); | ||
|
||
$action = new GetTransactionDataAction(); | ||
$action->setApi($api); | ||
$request = new GetTransactionData($details = new ArrayObject(['url' => 'foo'])); | ||
$action->setApi( | ||
$api = m::mock('PayumTW\Mypay\Api') | ||
); | ||
$api->shouldReceive('getTransactionData')->once()->with((array) $details)->andReturn($result = ['url' => 'bar']); | ||
$action->execute($request); | ||
|
||
/* | ||
|------------------------------------------------------------ | ||
| Assert | ||
|------------------------------------------------------------ | ||
*/ | ||
|
||
$request->shouldHaveReceived('getModel')->twice(); | ||
$api->shouldHaveReceived('getTransactionData')->once(); | ||
$details->shouldHaveReceived('replace')->once(); | ||
$this->assertSame($result, (array) $request->getModel()); | ||
} | ||
} |
Oops, something went wrong.