diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 00000000..1fa84fbd --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,43 @@ +name: Unit Tests + +on: + push: + branches: + - master + pull_request: + branches: + - "*" + schedule: + - cron: '0 0 * * *' + +jobs: + php-tests: + runs-on: ubuntu-latest + timeout-minutes: 15 + env: + COMPOSER_NO_INTERACTION: 1 + + strategy: + matrix: + php: [8.0, 7.4, 7.3, 7.2] + dependency-version: [prefer-lowest, prefer-stable] + + name: P${{ matrix.php }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + tools: composer:v2 + + - name: Install dependencies + run: | + composer update --${{ matrix.dependency-version }} --prefer-dist --no-progress + + - name: Execute Unit Tests + run: composer test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2fe44cdd..00000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: php - -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - -before_script: - - composer install -n --dev --prefer-source - - export XDEBUG_MODE=coverage - -script: - - vendor/bin/phpcs --standard=PSR2 src - - vendor/bin/phpunit --coverage-text diff --git a/composer.json b/composer.json index 40ebdeb5..89fe42d6 100644 --- a/composer.json +++ b/composer.json @@ -34,12 +34,13 @@ } }, "require": { - "php": "^5.6|^7", + "php": "^7.2|^8", "omnipay/common": "~3.0" }, "require-dev": { - "omnipay/tests": "~3.0", - "squizlabs/php_codesniffer": "^3" + "omnipay/tests": "^4.1", + "squizlabs/php_codesniffer": "^3", + "phpspec/prophecy-phpunit": "^2.0" }, "extra": { "branch-alias": { diff --git a/tests/DirectGatewayTest.php b/tests/DirectGatewayTest.php index 46858557..e37d3f26 100644 --- a/tests/DirectGatewayTest.php +++ b/tests/DirectGatewayTest.php @@ -6,7 +6,7 @@ class DirectGatewayTest extends GatewayTestCase { - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/FormGatewayTest.php b/tests/FormGatewayTest.php index 8f141b5d..4f3ad1a2 100644 --- a/tests/FormGatewayTest.php +++ b/tests/FormGatewayTest.php @@ -6,7 +6,7 @@ class FormGatewayTest extends GatewayTestCase { - public function setUp() + public function setUp(): void { parent::setUp(); @@ -107,10 +107,10 @@ public function testPurchaseSuccess() * supplied, which largely amount to missing parameters. * * @dataProvider missingParameterProvider - * @expectedException \Omnipay\Common\Exception\InvalidRequestException */ public function testAuthorizeFailure($missingParameter) { + $this->expectException(\Omnipay\Common\Exception\InvalidRequestException::class); $parameters = $this->purchaseOptions; unset($parameters[$missingParameter]); @@ -180,37 +180,33 @@ public function testCompleteAuthorizeSuccess() /** * Invalid without any query parameter supplied. - * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompleteAuthorizeInvalid() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); $response = $this->gateway->completeAuthorize($this->completePurchaseOptions)->send(); } /** * Invalid without any query parameter supplied. - * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompletePurchaseInvalid1() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); } - /** - * @expectedException Omnipay\Common\Exception\InvalidResponseException - */ public function testCompletePurchaseInvalid2() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); // No leading '@'. $this->getHttpRequest()->initialize(['crypt' => 'ababab']); $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); } - /** - * @expectedException Omnipay\Common\Exception\InvalidResponseException - */ public function testCompletePurchaseInvalid3() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); // Not hexadecimal. $this->getHttpRequest()->initialize(['crypt' => '@ababxx']); $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); @@ -275,11 +271,10 @@ public function testCompletePurchaseSuccess() /** * The wrong transaction ID is supplied with the server request. - * - * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompletePurchaseReplayAttack() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); //$this->expectException(Complicated::class); // Set the "crypt" query parameter. @@ -295,11 +290,10 @@ public function testCompletePurchaseReplayAttack() /** * The missing expected transaction ID supplied by the app. - * - * @expectedException Omnipay\Common\Exception\InvalidRequestException */ public function testCompletePurchaseMissingExpectedParam() { + $this->expectException(\Omnipay\Common\Exception\InvalidRequestException::class); //$this->expectException(Complicated::class); // Set the "crypt" query parameter. diff --git a/tests/Message/DirectAuthorizeRequestTest.php b/tests/Message/DirectAuthorizeRequestTest.php index e18bf2ba..736da121 100644 --- a/tests/Message/DirectAuthorizeRequestTest.php +++ b/tests/Message/DirectAuthorizeRequestTest.php @@ -16,7 +16,7 @@ class DirectAuthorizeRequestTest extends TestCase */ protected $request; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -123,7 +123,7 @@ public function testBasket() // The element does exist, and must contain the basket XML, with optional XML header and // trailing newlines. $this->assertArrayHasKey('BasketXML', $data); - $this->assertContains($basketXml, $data['BasketXML']); + $this->assertStringContainsString($basketXml, $data['BasketXML']); } public function testBasketExtendItem() @@ -151,7 +151,7 @@ public function testBasketExtendItem() // The element does exist, and must contain the basket XML, with optional XML header and // trailing newlines. $this->assertArrayHasKey('BasketXML', $data); - $this->assertContains($basketXml, $data['BasketXML']); + $this->assertStringContainsString($basketXml, $data['BasketXML']); } public function testGetDataNoReferrerId() @@ -280,7 +280,7 @@ public function testBasketWithNoDiscount() // The element does exist, and must contain the basket XML, with optional XML header and // trailing newlines. $this->assertArrayHasKey('BasketXML', $data); - $this->assertNotContains('', $data['BasketXML']); + $this->assertStringNotContainsString('', $data['BasketXML']); } public function testMixedBasketWithSpecialChars() @@ -321,7 +321,7 @@ public function testMixedBasketWithSpecialChars() $data = $this->request->getData(); $this->assertArrayHasKey('BasketXML', $data); - $this->assertContains($expected, $data['BasketXML'], 'Basket XML does not match the expected output'); + $this->assertStringContainsString($expected, $data['BasketXML'], 'Basket XML does not match the expected output'); } public function testNonXmlBasket() diff --git a/tests/Message/DirectPurchaseRequestTest.php b/tests/Message/DirectPurchaseRequestTest.php index 1fb04176..6eb34b24 100644 --- a/tests/Message/DirectPurchaseRequestTest.php +++ b/tests/Message/DirectPurchaseRequestTest.php @@ -16,7 +16,7 @@ class DirectPurchaseRequestTest extends DirectAuthorizeRequestTest */ protected $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/DirectTokenRequestTest.php b/tests/Message/DirectTokenRequestTest.php index 3fb06dfa..9373615b 100644 --- a/tests/Message/DirectTokenRequestTest.php +++ b/tests/Message/DirectTokenRequestTest.php @@ -15,7 +15,7 @@ class DirectTokenRequestTest extends TestCase */ protected $card; - public function setUp() + public function setUp(): void { $this->request = new DirectTokenRegistrationRequest( $this->getHttpClient(), diff --git a/tests/Message/ResponseTest.php b/tests/Message/ResponseTest.php index c993f8b9..6602250b 100644 --- a/tests/Message/ResponseTest.php +++ b/tests/Message/ResponseTest.php @@ -4,10 +4,13 @@ use Omnipay\Common\Message\RequestInterface; use Omnipay\Tests\TestCase; +use Prophecy\PhpUnit\ProphecyTrait; class ResponseTest extends TestCase { - public function setUp() + use ProphecyTrait; + + public function setUp(): void { $this->getMockRequest()->shouldReceive('getTransactionId')->andReturn('123456'); } diff --git a/tests/Message/ServerAuthorizeRequestTest.php b/tests/Message/ServerAuthorizeRequestTest.php index 4439b693..052ae0da 100644 --- a/tests/Message/ServerAuthorizeRequestTest.php +++ b/tests/Message/ServerAuthorizeRequestTest.php @@ -8,7 +8,7 @@ class ServerAuthorizeRequestTest extends TestCase { const SURCHARGE_XML = 'VISA2.50'; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/ServerAuthorizeResponseTest.php b/tests/Message/ServerAuthorizeResponseTest.php index 50029e44..7e669b7d 100644 --- a/tests/Message/ServerAuthorizeResponseTest.php +++ b/tests/Message/ServerAuthorizeResponseTest.php @@ -6,7 +6,7 @@ class ServerAuthorizeResponseTest extends TestCase { - public function setUp() + public function setUp(): void { $this->getMockRequest()->shouldReceive('getTransactionId')->andReturn('123456'); } diff --git a/tests/Message/ServerNotifyRequestTest.php b/tests/Message/ServerNotifyRequestTest.php index 34dc9114..aa53b787 100644 --- a/tests/Message/ServerNotifyRequestTest.php +++ b/tests/Message/ServerNotifyRequestTest.php @@ -184,11 +184,10 @@ public function testError() $this->request->error('https://www.example.com/', 'detail'); } - /** - * @expectedException \Omnipay\Common\Exception\InvalidResponseException - */ public function testConfirmInvalidSignature() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); + $this->request = new ServerNotifyRequest( $this->getHttpClient(), $this->getHttpRequest() @@ -200,11 +199,10 @@ public function testConfirmInvalidSignature() $this->request->confirm('https://www.example.com/', 'detail'); } - /** - * @expectedException \Omnipay\Common\Exception\InvalidResponseException - */ public function testErrorInvalidSignature() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); + $this->request = new ServerNotifyRequest( $this->getHttpClient(), $this->getHttpRequest() diff --git a/tests/Message/ServerTokenRegistrationRequestTest.php b/tests/Message/ServerTokenRegistrationRequestTest.php index 2668b8f0..4e6b51e3 100644 --- a/tests/Message/ServerTokenRegistrationRequestTest.php +++ b/tests/Message/ServerTokenRegistrationRequestTest.php @@ -12,7 +12,7 @@ class ServerTokenRegistrationRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/ServerTokenRegistrationResponseTest.php b/tests/Message/ServerTokenRegistrationResponseTest.php index a40bfa59..d639b2b0 100644 --- a/tests/Message/ServerTokenRegistrationResponseTest.php +++ b/tests/Message/ServerTokenRegistrationResponseTest.php @@ -6,7 +6,7 @@ class ServerTokenRegistrationResponseTest extends TestCase { - public function setUp() + public function setUp(): void { $this->getMockRequest()->shouldReceive('getTransactionId')->andReturn('123456'); } diff --git a/tests/Message/SharedAbortRequestTest.php b/tests/Message/SharedAbortRequestTest.php index 95dc5c55..e7519a36 100644 --- a/tests/Message/SharedAbortRequestTest.php +++ b/tests/Message/SharedAbortRequestTest.php @@ -6,7 +6,7 @@ class SharedAbortRequestTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/SharedCaptureRequestTest.php b/tests/Message/SharedCaptureRequestTest.php index ba73081b..3b33e3f7 100644 --- a/tests/Message/SharedCaptureRequestTest.php +++ b/tests/Message/SharedCaptureRequestTest.php @@ -6,7 +6,7 @@ class SharedCaptureRequestTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); @@ -38,11 +38,10 @@ public function testTxType() $this->assertSame('RELEASE', $this->request->getTxType()); } - /** - * @expectedException \Omnipay\Common\Exception\InvalidRequestException - */ public function testMissingAmount() { + $this->expectException(\Omnipay\Common\Exception\InvalidRequestException::class); + $this->request->getData(); } @@ -60,22 +59,20 @@ public function testValid() $this->assertSame('4255', $data['TxAuthNo']); } - /** - * @expectedException \Omnipay\Common\Exception\InvalidRequestException - */ public function testAuthMissingDescription() { + $this->expectException(\Omnipay\Common\Exception\InvalidRequestException::class); + $this->request->setAmount(123.45); $this->request->setUseAuthenticate(true); $this->request->getData(); } - /** - * @expectedException \Omnipay\Common\Exception\InvalidRequestException - */ public function testAuthMissingTransactionId() { + $this->expectException(\Omnipay\Common\Exception\InvalidRequestException::class); + $this->request->setAmount(123.45); $this->request->setDescription('desc'); $this->request->setUseAuthenticate(true); diff --git a/tests/Message/SharedRefundRequestTest.php b/tests/Message/SharedRefundRequestTest.php index 320f5696..4054d831 100644 --- a/tests/Message/SharedRefundRequestTest.php +++ b/tests/Message/SharedRefundRequestTest.php @@ -6,7 +6,7 @@ class SharedRefundRequestTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/SharedRepeatAuthorizeRequestTest.php b/tests/Message/SharedRepeatAuthorizeRequestTest.php index a0a6e988..99257a00 100644 --- a/tests/Message/SharedRepeatAuthorizeRequestTest.php +++ b/tests/Message/SharedRepeatAuthorizeRequestTest.php @@ -11,7 +11,7 @@ class SharedRepeatAuthorizeRequestTest extends TestCase */ protected $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/SharedRepeatPurchaseRequestTest.php b/tests/Message/SharedRepeatPurchaseRequestTest.php index 166df08f..610bc453 100644 --- a/tests/Message/SharedRepeatPurchaseRequestTest.php +++ b/tests/Message/SharedRepeatPurchaseRequestTest.php @@ -11,7 +11,7 @@ class SharedRepeatPurchaseRequestTest extends TestCase */ protected $request; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Message/SharedTokenRemovalRequestTest.php b/tests/Message/SharedTokenRemovalRequestTest.php index cf223023..62136f39 100644 --- a/tests/Message/SharedTokenRemovalRequestTest.php +++ b/tests/Message/SharedTokenRemovalRequestTest.php @@ -11,7 +11,7 @@ class SharedTokenRemovalRequestTest extends TestCase */ private $request; - public function setUp() + public function setUp(): void { $this->request = new SharedTokenRemovalRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize(array( diff --git a/tests/Message/SharedVoidRequestTest.php b/tests/Message/SharedVoidRequestTest.php index 78f2b6d1..39804be1 100644 --- a/tests/Message/SharedVoidRequestTest.php +++ b/tests/Message/SharedVoidRequestTest.php @@ -6,7 +6,7 @@ class SharedVoidRequestTest extends TestCase { - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/ServerGatewayTest.php b/tests/ServerGatewayTest.php index d7042801..91d23f35 100644 --- a/tests/ServerGatewayTest.php +++ b/tests/ServerGatewayTest.php @@ -8,7 +8,7 @@ class ServerGatewayTest extends GatewayTestCase { protected $error_3082_text = '3082 : The Description value is too long.'; - public function setUp() + public function setUp(): void { parent::setUp(); @@ -129,11 +129,9 @@ public function testCompleteAuthorizeSuccess() $this->assertNull($response->getMessage()); } - /** - * @expectedException Omnipay\Common\Exception\InvalidResponseException - */ public function testCompleteAuthorizeInvalid() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); $response = $this->gateway->completeAuthorize($this->completePurchaseOptions)->send(); } @@ -190,11 +188,9 @@ public function testCompletePurchaseSuccess() $this->assertNull($response->getMessage()); } - /** - * @expectedException Omnipay\Common\Exception\InvalidResponseException - */ public function testCompletePurchaseInvalid() { + $this->expectException(\Omnipay\Common\Exception\InvalidResponseException::class); $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); }