Skip to content

Commit

Permalink
Add use statements for all classes
Browse files Browse the repository at this point in the history
  • Loading branch information
pierredup committed Nov 6, 2023
1 parent cfb28d5 commit 39abdb0
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 52 deletions.
3 changes: 2 additions & 1 deletion Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Payum\Be2Bill\Action;

use ArrayAccess;
use Payum\Be2Bill\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function execute($request)
public function supports($request)
{
return $request instanceof Capture &&
$request->getModel() instanceof \ArrayAccess
$request->getModel() instanceof ArrayAccess
;
}
}
3 changes: 2 additions & 1 deletion Action/CaptureOffsiteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Payum\Be2Bill\Action;

use ArrayAccess;
use Payum\Be2Bill\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
Expand Down Expand Up @@ -73,7 +74,7 @@ public function execute($request)
public function supports($request)
{
return $request instanceof Capture &&
$request->getModel() instanceof \ArrayAccess
$request->getModel() instanceof ArrayAccess
;
}
}
3 changes: 2 additions & 1 deletion Action/NotifyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Payum\Be2Bill\Action;

use ArrayAccess;
use Payum\Be2Bill\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
Expand Down Expand Up @@ -51,7 +52,7 @@ public function execute($request)
public function supports($request)
{
return $request instanceof Notify &&
$request->getModel() instanceof \ArrayAccess
$request->getModel() instanceof ArrayAccess
;
}
}
3 changes: 2 additions & 1 deletion Action/StatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Payum\Be2Bill\Action;

use ArrayAccess;
use Payum\Be2Bill\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
Expand Down Expand Up @@ -43,7 +44,7 @@ public function execute($request)
public function supports($request)
{
return $request instanceof GetStatusInterface &&
$request->getModel() instanceof \ArrayAccess
$request->getModel() instanceof ArrayAccess
;
}
}
3 changes: 2 additions & 1 deletion Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Http\Message\MessageFactory;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\Http\HttpException;
use Payum\Core\Exception\InvalidArgumentException;
use Payum\Core\Exception\LogicException;
use Payum\Core\HttpClientInterface;

Expand Down Expand Up @@ -122,7 +123,7 @@ class Api
];

/**
* @throws \Payum\Core\Exception\InvalidArgumentException if an option is invalid
* @throws InvalidArgumentException if an option is invalid
*/
public function __construct(array $options, HttpClientInterface $client, MessageFactory $messageFactory)
{
Expand Down
39 changes: 23 additions & 16 deletions Tests/Action/CaptureActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace Payum\Be2Bill\Tests\Action;

use ArrayObject;
use DateTime;
use Payum\Be2Bill\Action\CaptureAction;
use Payum\Be2Bill\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Exception\LogicException;
use Payum\Core\Exception\RequestNotSupportedException;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayInterface;
use Payum\Core\Model\CreditCard;
Expand All @@ -15,6 +19,9 @@
use Payum\Core\Request\ObtainCreditCard;
use Payum\Core\Security\SensitiveValue;
use Payum\Core\Tests\GenericActionTest;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionClass;
use stdClass;

class CaptureActionTest extends GenericActionTest
{
Expand All @@ -24,42 +31,42 @@ class CaptureActionTest extends GenericActionTest

public function testShouldImplementActionInterface()
{
$rc = new \ReflectionClass(CaptureAction::class);
$rc = new ReflectionClass(CaptureAction::class);

$this->assertTrue($rc->implementsInterface(ActionInterface::class));
}

public function testShouldImplementGatewayAwareInterface()
{
$rc = new \ReflectionClass(CaptureAction::class);
$rc = new ReflectionClass(CaptureAction::class);

$this->assertTrue($rc->implementsInterface(GatewayAwareInterface::class));
}

public function testShouldImplementApiAwareInterface()
{
$rc = new \ReflectionClass(CaptureAction::class);
$rc = new ReflectionClass(CaptureAction::class);

$this->assertTrue($rc->implementsInterface(ApiAwareInterface::class));
}

public function testThrowIfUnsupportedApiGiven()
{
$this->expectException(\Payum\Core\Exception\UnsupportedApiException::class);
$this->expectException(UnsupportedApiException::class);
$action = new CaptureAction();

$action->setApi(new \stdClass());
$action->setApi(new stdClass());
}

public function testThrowIfCreditCardNotSetExplicitlyAndObtainRequestNotSupportedOnCapture()
{
$this->expectException(\Payum\Core\Exception\LogicException::class);
$this->expectException(LogicException::class);
$this->expectExceptionMessage('Credit card details has to be set explicitly or there has to be an action that supports ObtainCreditCard request.');
$gatewayMock = $this->createGatewayMock();
$gatewayMock
->expects($this->once())
->method('execute')
->with($this->isInstanceOf(\Payum\Core\Request\ObtainCreditCard::class))
->with($this->isInstanceOf(ObtainCreditCard::class))
->willThrowException(new RequestNotSupportedException())
;

Expand Down Expand Up @@ -155,11 +162,11 @@ public function testShouldCaptureWithObtainedCreditCard()
$gatewayMock
->expects($this->once())
->method('execute')
->with($this->isInstanceOf(\Payum\Core\Request\ObtainCreditCard::class))
->with($this->isInstanceOf(ObtainCreditCard::class))
->willReturnCallback(function (ObtainCreditCard $request) {
$card = new CreditCard();
$card->setNumber('1234567812345678');
$card->setExpireAt(new \DateTime('2014-10-01'));
$card->setExpireAt(new DateTime('2014-10-01'));
$card->setHolder('John Doe');
$card->setSecurityCode('123');

Expand Down Expand Up @@ -211,7 +218,7 @@ public function testShouldCaptureWithObtainedCreditCardWhenTokenReturned()
$gatewayMock
->expects($this->once())
->method('execute')
->with($this->isInstanceOf(\Payum\Core\Request\ObtainCreditCard::class))
->with($this->isInstanceOf(ObtainCreditCard::class))
->willReturnCallback(function (ObtainCreditCard $request) {
$card = new CreditCard();
$card->setToken('theCreditCardToken');
Expand Down Expand Up @@ -259,8 +266,8 @@ public function testShouldCaptureWithObtainedCreditCardWhenTokenReturned()

public function testShouldPassFirstAndCurrentModelsWithObtainCreditCardSubRequest()
{
$firstModel = new \stdClass();
$currentModel = new \ArrayObject([
$firstModel = new stdClass();
$currentModel = new ArrayObject([
'AMOUNT' => 10,
'CLIENTUSERAGENT' => 'anAgent',
'CLIENTIP' => '127.0.0.1',
Expand All @@ -280,13 +287,13 @@ public function testShouldPassFirstAndCurrentModelsWithObtainCreditCardSubReques
$gatewayMock
->expects($this->once())
->method('execute')
->with($this->isInstanceOf(\Payum\Core\Request\ObtainCreditCard::class))
->with($this->isInstanceOf(ObtainCreditCard::class))
->willReturnCallback(function (ObtainCreditCard $request) use ($firstModel, $currentModel) {
$this->assertSame($firstModel, $request->getFirstModel());
$this->assertSame($currentModel, $request->getModel());

$card = new CreditCard();
$card->setExpireAt(new \DateTime('2014-10-01'));
$card->setExpireAt(new DateTime('2014-10-01'));

$request->set($card);
})
Expand Down Expand Up @@ -314,15 +321,15 @@ public function testShouldThrowHttpResponseIfExecCode3DSecureRequired()
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|Api
* @return MockObject|Api
*/
protected function createApiMock()
{
return $this->createMock(Api::class, [], [], '', false);
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|GatewayInterface
* @return MockObject|GatewayInterface
*/
protected function createGatewayMock()
{
Expand Down
25 changes: 15 additions & 10 deletions Tests/Action/CaptureOffsiteActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
use Payum\Be2Bill\Api;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\Exception\UnsupportedApiException;
use Payum\Core\GatewayAwareInterface;
use Payum\Core\GatewayInterface;
use Payum\Core\Reply\HttpPostRedirect;
use Payum\Core\Request\Capture;
use Payum\Core\Request\GetHttpRequest;
use Payum\Core\Tests\GenericActionTest;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionClass;
use stdClass;

class CaptureOffsiteActionTest extends GenericActionTest
{
Expand All @@ -20,36 +25,36 @@ class CaptureOffsiteActionTest extends GenericActionTest

public function testShouldImplementActionInterface()
{
$rc = new \ReflectionClass(CaptureOffsiteAction::class);
$rc = new ReflectionClass(CaptureOffsiteAction::class);

$this->assertTrue($rc->implementsInterface(ActionInterface::class));
}

public function testShouldImplementGatewayAwareInterface()
{
$rc = new \ReflectionClass(CaptureOffsiteAction::class);
$rc = new ReflectionClass(CaptureOffsiteAction::class);

$this->assertTrue($rc->implementsInterface(GatewayAwareInterface::class));
}

public function testShouldImplementApiAwareInterface()
{
$rc = new \ReflectionClass(CaptureOffsiteAction::class);
$rc = new ReflectionClass(CaptureOffsiteAction::class);

$this->assertTrue($rc->implementsInterface(ApiAwareInterface::class));
}

public function testThrowIfUnsupportedApiGiven()
{
$this->expectException(\Payum\Core\Exception\UnsupportedApiException::class);
$this->expectException(UnsupportedApiException::class);
$action = new CaptureOffsiteAction();

$action->setApi(new \stdClass());
$action->setApi(new stdClass());
}

public function testShouldRedirectToBe2billSiteIfExecCodeNotPresentInQuery()
{
$this->expectException(\Payum\Core\Reply\HttpPostRedirect::class);
$this->expectException(HttpPostRedirect::class);
$model = [
'AMOUNT' => 1000,
'CLIENTIDENT' => 'payerId',
Expand All @@ -74,7 +79,7 @@ public function testShouldRedirectToBe2billSiteIfExecCodeNotPresentInQuery()
$gatewayMock
->expects($this->once())
->method('execute')
->with($this->isInstanceOf(\Payum\Core\Request\GetHttpRequest::class))
->with($this->isInstanceOf(GetHttpRequest::class))
;

$action = new CaptureOffsiteAction();
Expand Down Expand Up @@ -105,7 +110,7 @@ public function testShouldUpdateModelWhenComeBackFromBe2billSite()
$gatewayMock
->expects($this->once())
->method('execute')
->with($this->isInstanceOf(\Payum\Core\Request\GetHttpRequest::class))
->with($this->isInstanceOf(GetHttpRequest::class))
->willReturnCallback(function (GetHttpRequest $request) {
$request->query['EXECCODE'] = 1;
$request->query['FOO'] = 'fooVal';
Expand All @@ -132,15 +137,15 @@ public function testShouldUpdateModelWhenComeBackFromBe2billSite()
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|Api
* @return MockObject|Api
*/
protected function createApiMock()
{
return $this->createMock(Api::class, [], [], '', false);
}

/**
* @return \PHPUnit\Framework\MockObject\MockObject|GatewayInterface
* @return MockObject|GatewayInterface
*/
protected function createGatewayMock()
{
Expand Down
16 changes: 10 additions & 6 deletions Tests/Action/ConvertPaymentActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@

namespace Payum\Be2Bill\Tests\Action;

use Iterator;
use Payum\Be2Bill\Action\ConvertPaymentAction;
use Payum\Core\Model\Payment;
use Payum\Core\Model\PaymentInterface;
use Payum\Core\Request\Convert;
use Payum\Core\Request\Generic;
use Payum\Core\Security\TokenInterface;
use Payum\Core\Tests\GenericActionTest;
use stdClass;

class ConvertPaymentActionTest extends GenericActionTest
{
protected $actionClass = ConvertPaymentAction::class;

protected $requestClass = Convert::class;

public function provideSupportedRequests(): \Iterator
public function provideSupportedRequests(): Iterator
{
yield [new $this->requestClass(new Payment(), 'array')];
yield [new $this->requestClass($this->createMock(PaymentInterface::class), 'array')];
yield [new $this->requestClass(new Payment(), 'array', $this->createMock(\Payum\Core\Security\TokenInterface::class))];
yield [new $this->requestClass(new Payment(), 'array', $this->createMock(TokenInterface::class))];
}

public function provideNotSupportedRequests(): \Iterator
public function provideNotSupportedRequests(): Iterator
{
yield ['foo'];
yield [['foo']];
yield [new \stdClass()];
yield [$this->getMockForAbstractClass(\Payum\Core\Request\Generic::class, [[]])];
yield [new $this->requestClass(new \stdClass(), 'array')];
yield [new stdClass()];
yield [$this->getMockForAbstractClass(Generic::class, [[]])];
yield [new $this->requestClass(new stdClass(), 'array')];
yield [new $this->requestClass(new Payment(), 'foobar')];
yield [new $this->requestClass($this->createMock(PaymentInterface::class), 'foobar')];
}
Expand Down
Loading

0 comments on commit 39abdb0

Please sign in to comment.