Skip to content

Commit

Permalink
Remove all calls to at() in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed May 5, 2022
1 parent 872f684 commit da053ac
Show file tree
Hide file tree
Showing 28 changed files with 995 additions and 1,147 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"doctrine/dbal": "^2.7 || ^3.0",
"doctrine/orm": "^2.5",
"doctrine/persistence": "^1.3.3 || ^2.0",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"propel/propel1": "~1.7",
"psr/log": "~1.0",
"laminas/laminas-db": "^2.0",
Expand All @@ -68,7 +68,7 @@
"symfony/form": "^4.4 || ^5.0",
"symfony/templating": "^4.4 || ^5.0",
"symfony/validator": "^4.4 || ^5.0",
"symfony/phpunit-bridge": "^6.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.0",
"authorizenet/authorizenet": "^1.8.1",
"sofort/sofortlib-php": "^3.0",
Expand Down
158 changes: 70 additions & 88 deletions src/Payum/Core/Tests/Action/AuthorizePaymentActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Payum\Core\Request\GetHumanStatus;
use Payum\Core\Security\TokenInterface;
use Payum\Core\Tests\GenericActionTest;
use function iterator_to_array;

class AuthorizePaymentActionTest extends GenericActionTest
{
Expand Down Expand Up @@ -46,25 +47,22 @@ public function shouldExecuteConvertRequestIfStatusNew()

$gatewayMock = $this->createGatewayMock();
$gatewayMock
->expects($this->at(0))
->expects($this->atLeast(2))
->method('execute')
->with($this->isInstanceOf(GetHumanStatus::class))
->will($this->returnCallback(function (GetHumanStatus $request) {
$request->markNew();
}))
;
$gatewayMock
->expects($this->at(1))
->method('execute')
->with($this->isInstanceOf(Convert::class))
->will($this->returnCallback(function (Convert $request) use ($testCase, $payment) {
$testCase->assertSame($payment, $request->getSource());
$testCase->assertSame('array', $request->getTo());
$testCase->assertNull($request->getToken());

$request->setResult(array());
}))
;
->withConsecutive([$this->isInstanceOf(GetHumanStatus::class)], [$this->isInstanceOf(Convert::class)])
->willReturnOnConsecutiveCalls(
$this->returnCallback(function (GetHumanStatus $request) {
$request->markNew();
}),
$this->returnCallback(function (Convert $request) use ($testCase, $payment) {
$testCase->assertSame($payment, $request->getSource());
$testCase->assertSame('array', $request->getTo());
$testCase->assertNull($request->getToken());

$request->setResult([]);
}
)
);

$action = new AuthorizePaymentAction();
$action->setGateway($gatewayMock);
Expand All @@ -83,28 +81,22 @@ public function shouldSetConvertedResultToPaymentAsDetails()
{
$payment = new Payment();

$testCase = $this;

$gatewayMock = $this->createGatewayMock();
$gatewayMock
->expects($this->at(0))
->expects($this->atLeast(2))
->method('execute')
->with($this->isInstanceOf(GetHumanStatus::class))
->will($this->returnCallback(function (GetHumanStatus $request) {
$request->markNew();
}))
;
$gatewayMock
->expects($this->at(1))
->method('execute')
->with($this->isInstanceOf(Convert::class))
->will($this->returnCallback(function (Convert $request) use ($testCase, $payment) {
$details['foo'] = 'fooVal';

$request->setResult(array(
'foo' => 'fooVal',
));
}))
->withConsecutive([$this->isInstanceOf(GetHumanStatus::class)], [$this->isInstanceOf(Convert::class)])
->willReturnOnConsecutiveCalls(
$this->returnCallback(function (GetHumanStatus $request) {
$request->markNew();
}),
$this->returnCallback(function (Convert $request) {

$request->setResult(array(
'foo' => 'fooVal',
));
})
)
;

$action = new AuthorizePaymentAction();
Expand Down Expand Up @@ -134,24 +126,20 @@ public function shouldExecuteConvertRequestWithTokenIfOnePresent()

$gatewayMock = $this->createGatewayMock();
$gatewayMock
->expects($this->at(0))
->method('execute')
->with($this->isInstanceOf(GetHumanStatus::class))
->will($this->returnCallback(function (GetHumanStatus $request) {
$request->markNew();
}))
;
$gatewayMock
->expects($this->at(1))
->expects($this->atLeast(2))
->method('execute')
->with($this->isInstanceOf(Convert::class))
->will($this->returnCallback(function (Convert $request) use ($testCase, $payment, $token) {
$testCase->assertSame($payment, $request->getSource());
$testCase->assertSame($token, $request->getToken());

$request->setResult(array());
}))
;
->withConsecutive([$this->isInstanceOf(GetHumanStatus::class)], [$this->isInstanceOf(Convert::class)])
->willReturnOnConsecutiveCalls(
$this->returnCallback(function (GetHumanStatus $request) {
$request->markNew();
}),
$this->returnCallback(function (Convert $request) use ($testCase, $payment, $token) {
$testCase->assertSame($payment, $request->getSource());
$testCase->assertSame($token, $request->getToken());

$request->setResult(array());
})
);

$action = new AuthorizePaymentAction();
$action->setGateway($gatewayMock);
Expand Down Expand Up @@ -180,25 +168,22 @@ public function shouldSetDetailsBackToPaymentAfterAuthorizeDetailsExecution()

$gatewayMock = $this->createGatewayMock();
$gatewayMock
->expects($this->at(0))
->expects($this->atLeast(2))
->method('execute')
->with($this->isInstanceOf(GetHumanStatus::class))
->will($this->returnCallback(function (GetHumanStatus $request) {
$request->markPending();
}))
;
$gatewayMock
->expects($this->at(1))
->method('execute')
->with($this->isInstanceOf(Authorize::class))
->will($this->returnCallback(function (Authorize $request) use ($testCase, $expectedDetails) {
$details = $request->getModel();

$testCase->assertInstanceOf('ArrayAccess', $details);
$testCase->assertEquals($expectedDetails, iterator_to_array($details));

$details['bar'] = 'barVal';
}))
->withConsecutive([$this->isInstanceOf(GetHumanStatus::class)], [$this->isInstanceOf(Authorize::class)])
->willReturnOnConsecutiveCalls(
$this->returnCallback(function (GetHumanStatus $request) {
$request->markPending();
}),
$this->returnCallback(function (Authorize $request) use ($testCase, $expectedDetails) {
$details = $request->getModel();

$testCase->assertInstanceOf('ArrayAccess', $details);
$testCase->assertEquals($expectedDetails, iterator_to_array($details));

$details['bar'] = 'barVal';
})
)
;

$action = new AuthorizePaymentAction();
Expand All @@ -223,23 +208,20 @@ public function shouldSetDetailsBackToPaymentEvenIfExceptionThrown()

$gatewayMock = $this->createGatewayMock();
$gatewayMock
->expects($this->at(0))
->expects($this->atLeast(2))
->method('execute')
->with($this->isInstanceOf(GetHumanStatus::class))
->will($this->returnCallback(function (GetHumanStatus $request) {
$request->markPending();
}))
;
$gatewayMock
->expects($this->at(1))
->method('execute')
->with($this->isInstanceOf(Authorize::class))
->will($this->returnCallback(function (Authorize $request) {
$details = $request->getModel();
$details['bar'] = 'barVal';

throw new \Exception();
}))
->withConsecutive([$this->isInstanceOf(GetHumanStatus::class)], [$this->isInstanceOf(Authorize::class)])
->willReturnOnConsecutiveCalls(
$this->returnCallback(function (GetHumanStatus $request) {
$request->markPending();
}),
$this->returnCallback(function (Authorize $request) {
$details = $request->getModel();
$details['bar'] = 'barVal';

throw new \Exception();
})
)
;

$action = new AuthorizePaymentAction();
Expand Down

0 comments on commit da053ac

Please sign in to comment.