diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 0b3dedb..a040bb9 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,47 +1,46 @@ -name: Run tests +name: Run lint and tests on: pull_request: types: - opened - reopened - ready_for_review + workflow_dispatch: env: + PHP_VERSION: 8.3 PHP_EXTENSIONS: mbstring - PHP_TOOLS: composer:v2, phpunit:9.5 + PHP_TOOLS: composer:v2, phpunit:11 + +permissions: + id-token: write + contents: read jobs: run-tests: if: ${{ !github.event.pull_request.draft }} runs-on: ubuntu-latest - - strategy: - matrix: - php-version: - - 7.4 - steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Install PHP + - name: Install PHP ${{ env.PHP_VERSION }} uses: shivammathur/setup-php@v2 with: coverage: none - php-version: ${{ matrix.php-version }} + php-version: ${{ env.PHP_VERSION }} extensions: ${{ env.PHP_EXTENSIONS }} tools: ${{ env.PHP_TOOLS }} - - - name: Determine composer cache directory - id: determine-composer-cache-directory - run: echo "::set-output name=directory::$(composer config cache-dir)" - - name: Cache dependencies installed with composer - uses: actions/cache@v3 + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - uses: actions/cache@v4 with: - path: ${{ steps.determine-composer-cache-directory.outputs.directory }} - key: php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.json') }} - restore-keys: php-${{ matrix.php-version }}-composer- + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- # TODO test direct env php with github actios - name: Add config/env.test.php diff --git a/Readme.md b/Readme.md index 25aed9d..dcab949 100644 --- a/Readme.md +++ b/Readme.md @@ -8,13 +8,13 @@ Todos os passos e processos referentes à integração com o sistema de captura #### Pré-requisitos -- PHP `>=7.4` +- PHP `^8.2` #### Composer add composer.json ``` -"edson-nascimento/getnet-php": "^2.0" +"edson-nascimento/getnet-php": "^3.0" ``` ou execute ```base diff --git a/composer.json b/composer.json index 3d40e18..19dd61a 100644 --- a/composer.json +++ b/composer.json @@ -5,12 +5,12 @@ "license":"MIT", "type":"library", "require":{ - "php": ">=7.4" + "php": "^8.2" }, "require-dev":{ - "phpunit/phpunit":"^9", - "phpstan/phpstan":"^1.8.0", - "kint-php/kint":"^3.3", + "phpunit/phpunit": "^11.1.2", + "phpstan/phpstan": "^1.10.67", + "kint-php/kint": "^5.1.0", "monolog/monolog":"*" }, "autoload":{ @@ -30,7 +30,7 @@ "@phpstan", "@phpunit" ], - "test:unit":"phpunit --configuration phpunit.xml --testdox --exclude e2e", + "test:unit":"phpunit --configuration phpunit.xml --testdox --exclude-group e2e", "test:e2e":"phpunit --configuration phpunit.xml --testdox --group e2e", "test:coverage":"phpunit --configuration phpunit.xml --coverage-clover build/logs/clover.xml --coverage-html build/coverage" }, diff --git a/phpstan.neon b/phpstan.neon index 86baff6..ce4b30a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,15 @@ parameters: level: 5 + phpVersion: 80300 + checkFunctionNameCase: true + checkInternalClassCaseSensitivity: true + reportMaybesInPropertyPhpDocTypes: true + checkExplicitMixedMissingReturn: true + reportMaybesInMethodSignatures: true + reportStaticMethodSignatures: true + checkTooWideReturnTypesInProtectedAndPublicMethods: true + checkDynamicProperties: true + reportAlwaysTrueInLastCondition: true paths: - src - tests diff --git a/phpunit.xml b/phpunit.xml index 907c058..6e5550c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,12 +1,20 @@ - + colors="true" + backupGlobals="false" + cacheResult="false" + cacheDirectory="cache/phpunit" + backupStaticProperties="false" + displayDetailsOnIncompleteTests="true" + displayDetailsOnSkippedTests="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerErrors="true" + displayDetailsOnTestsThatTriggerNotices="true" + displayDetailsOnTestsThatTriggerWarnings="true" +> tests diff --git a/src/Getnet/API/BaseResponse.php b/src/Getnet/API/BaseResponse.php index dd25266..2bc7a75 100644 --- a/src/Getnet/API/BaseResponse.php +++ b/src/Getnet/API/BaseResponse.php @@ -43,7 +43,7 @@ class BaseResponse implements \JsonSerializable * * @return array */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return get_object_vars($this); } @@ -272,7 +272,7 @@ public function getStatus() $this->status = Transaction::STATUS_ERROR; } elseif ($this->status_code == 500) { $this->status = Transaction::STATUS_ERROR; - } elseif ($this->status_code == 1 || isset($this->redirect_url)) { + } elseif ($this->status_code == 1 || (property_exists($this, 'redirect_url') && isset($this->redirect_url))) { $this->status = Transaction::STATUS_PENDING; } elseif (isset($this->status_label)) { // TODO check why diff --git a/src/Getnet/API/Credit.php b/src/Getnet/API/Credit.php index 45f5d9a..3f44d02 100644 --- a/src/Getnet/API/Credit.php +++ b/src/Getnet/API/Credit.php @@ -1,6 +1,8 @@ credentials_on_file_type; + } + + /** + * + * @param mixed $credentials_on_file_type + */ + public function setCredentialsOnFileType($credentials_on_file_type) + { + if (!in_array($credentials_on_file_type, [ + static::COF_ONE_CLICK, static::COF_ONE_CLICK_PAYMENT, static::COF_RECURRING, static::COF_RECURRING_PAYMENT + ])) + throw new GetnetException('Escolha uma forma de recorrência válida'); + + $this->credentials_on_file_type = $credentials_on_file_type; + + return $this; + } + + /** + * + * @return mixed + */ + public function getTransactionId() + { + return $this->transaction_id; + } + + /** + * + * @param mixed $transaction_id + */ + public function setTransactionId($transaction_id) + { + $this->transaction_id = (string) $transaction_id; + + return $this; + } + } \ No newline at end of file diff --git a/src/Getnet/API/TraitEntity.php b/src/Getnet/API/TraitEntity.php index f96c571..c698002 100644 --- a/src/Getnet/API/TraitEntity.php +++ b/src/Getnet/API/TraitEntity.php @@ -4,7 +4,7 @@ trait TraitEntity { - public function jsonSerialize() + public function jsonSerialize(): mixed { $entity = clone $this; @@ -14,12 +14,8 @@ public function jsonSerialize() return $entity->toArray(); } - - /** - * - * @return array - */ - public function toArray() + + public function toArray(): array { $vars = get_object_vars($this); @@ -32,11 +28,7 @@ public function toArray() return $vars; } - /** - * - * @return false|string - */ - public function toJSON($hiddenNull = true) + public function toJSON($hiddenNull = true): string|false { if ($hiddenNull) { return json_encode($this); @@ -52,7 +44,7 @@ public function populateByArray(array $body, array $blockFields = []) $this->{$prop} = $value; } } - + return $this; } diff --git a/tests/AppTest.php b/tests/AppTest.php index d5ac552..4d0c3ab 100644 --- a/tests/AppTest.php +++ b/tests/AppTest.php @@ -1,13 +1,12 @@ assertInstanceOf(\Getnet\API\Getnet::class, $this->getnetService()); diff --git a/tests/AuthorizeDebitTest.php b/tests/AuthorizeDebitTest.php index 012d3cc..b715e87 100644 --- a/tests/AuthorizeDebitTest.php +++ b/tests/AuthorizeDebitTest.php @@ -4,14 +4,12 @@ use Getnet\API\Card; use Getnet\API\AuthorizeResponse; use Getnet\API\Transaction; +use PHPUnit\Framework\Attributes\Group; final class AuthorizeDebitTest extends TestBase { - /** - * - * @group e2e - */ + #[Group('e2e')] public function testAuthorizeDebitCreate(): AuthorizeResponse { $transaction = $this->generateMockTransaction(); diff --git a/tests/AuthorizePosteriorTest.php b/tests/AuthorizePosteriorTest.php index 9653176..a81e05d 100644 --- a/tests/AuthorizePosteriorTest.php +++ b/tests/AuthorizePosteriorTest.php @@ -5,14 +5,13 @@ use Getnet\API\Card; use Getnet\API\AuthorizeResponse; use Getnet\API\Transaction; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Depends; final class AuthorizePosteriorTest extends TestBase { - /** - * - * @group e2e - */ + #[Group('e2e')] public function testAuthorizePosteriorCreate(): AuthorizeResponse { $transaction = $this->generateMockTransaction(); @@ -52,11 +51,8 @@ public function testAuthorizePosteriorCreate(): AuthorizeResponse return $response; } - /** - * - * @group e2e - * @depends testAuthorizePosteriorCreate - */ + #[Group('e2e')] + #[Depends('testAuthorizePosteriorCreate')] public function testAuthorizePosteriorCapture(AuthorizeResponse $response): void { $result = $this->getnetService()->authorizeConfirm($response->getPaymentId(), $response->getAmount()); diff --git a/tests/AuthorizeTest.php b/tests/AuthorizeTest.php index d3dce8e..74d904b 100644 --- a/tests/AuthorizeTest.php +++ b/tests/AuthorizeTest.php @@ -5,15 +5,15 @@ use Getnet\API\Card; use Getnet\API\AuthorizeResponse; use Getnet\API\Transaction; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Depends; final class AuthorizeTest extends TestBase { private static $CARD_TOKEN; - /** - * - * @group e2e - */ + + #[Group('e2e')] public function testAuthorizeCreate(): AuthorizeResponse { $transaction = $this->generateMockTransaction(); @@ -21,7 +21,7 @@ public function testAuthorizeCreate(): AuthorizeResponse // Generate token card $tokenCard = new \Getnet\API\Token("5155901222280001", $transaction->getCustomer()->getCustomerId(), $this->getnetService()); - + self::$CARD_TOKEN = $tokenCard->getNumberToken(); // Add payment @@ -46,7 +46,7 @@ public function testAuthorizeCreate(): AuthorizeResponse if (!($response instanceof AuthorizeResponse)) { throw new \Exception($response->getResponseJSON()); } - + $this->assertSame(Transaction::STATUS_APPROVED, $response->getStatus(), $response->getResponseJSON()); $this->assertSame($transaction->getAmount(), $response->getAmount()); $this->assertSame($transaction->getOrder()->getOrderId(), $response->getOrderId()); @@ -55,33 +55,27 @@ public function testAuthorizeCreate(): AuthorizeResponse return $response; } - /** - * - * @group e2e - * @depends testAuthorizeCreate - */ + #[Group('e2e')] + #[Depends('testAuthorizeCreate')] public function testAuthorizeCancel(AuthorizeResponse $response): void { $result = $this->getnetService()->authorizeCancel($response->getPaymentId(), $response->getAmount()); $this->assertInstanceOf(AuthorizeResponse::class, $result); - $this->assertSame(Transaction::STATUS_CANCELED, $result->getStatus(),$response->getResponseJSON()); + $this->assertSame(Transaction::STATUS_CANCELED, $result->getStatus(), $response->getResponseJSON()); $this->assertSame($response->getAmount(), $result->getAmount()); $this->assertSame($response->getPaymentId(), $result->getPaymentId()); } - - /** - * - * @group e2e - * @depends testAuthorizeCancel - */ + + #[Group('e2e')] + #[Depends('testAuthorizeCancel')] public function testAuthorizeWithCardToken(): AuthorizeResponse { $transaction = $this->generateMockTransaction(); $transaction->setAmount(857.96); - + $cardToken = new \Getnet\API\Entity\CardToken(self::$CARD_TOKEN); - + // Add payment $transaction->credit() ->setAuthenticated(false) @@ -98,18 +92,18 @@ public function testAuthorizeWithCardToken(): AuthorizeResponse ->setExpirationYear(date('y') + 1) ->setCardholderName("Jax Teller") ->setSecurityCode("123"); - + $response = $this->getnetService()->authorize($transaction); - + if (!($response instanceof AuthorizeResponse)) { throw new \Exception($response->getResponseJSON()); } - + $this->assertSame(Transaction::STATUS_APPROVED, $response->getStatus(), $response->getResponseJSON()); $this->assertSame($transaction->getAmount(), $response->getAmount()); $this->assertSame($transaction->getOrder()->getOrderId(), $response->getOrderId()); $this->assertNotEmpty($response->getPaymentId()); - + return $response; } } \ No newline at end of file diff --git a/tests/BoletoTest.php b/tests/BoletoTest.php index 4836a26..5776e98 100644 --- a/tests/BoletoTest.php +++ b/tests/BoletoTest.php @@ -4,14 +4,12 @@ use Getnet\API\Transaction; use Getnet\API\BoletoRespose; use Getnet\API\Boleto; +use PHPUnit\Framework\Attributes\Group; final class BoletoTest extends TestBase { - /** - * - * @group e2e - */ + #[Group('e2e')] public function testBoletoCreate(): BoletoRespose { $transaction = $this->generateMockTransaction(false); diff --git a/tests/CardServiceTest.php b/tests/CardServiceTest.php index 35e4f37..d912e17 100644 --- a/tests/CardServiceTest.php +++ b/tests/CardServiceTest.php @@ -3,14 +3,13 @@ use Getnet\API\Token; use Getnet\API\Card; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\Depends; final class CardServiceTest extends TestBase { - /** - * - * @group e2e - */ + #[Group('e2e')] public function testCardToken(): Token { $cardService = new \Getnet\API\Service\CardService($this->getnetService()); @@ -25,11 +24,8 @@ public function testCardToken(): Token return $cardToken; } - /** - * - * @group e2e - * @depends testCardToken - */ + #[Group('e2e')] + #[Depends('testCardToken')] public function testSaveCard(Token $cardToken): void { $cardService = new \Getnet\API\Service\CardService($this->getnetService()); diff --git a/tests/CustomRequestTest.php b/tests/CustomRequestTest.php index b69ddc8..be72410 100644 --- a/tests/CustomRequestTest.php +++ b/tests/CustomRequestTest.php @@ -1,12 +1,12 @@ getnetService()->customRequest('GET', '/v1/customers?page=1&limit=5'); diff --git a/tests/PixTest.php b/tests/PixTest.php index b706f3e..99bd50a 100644 --- a/tests/PixTest.php +++ b/tests/PixTest.php @@ -2,17 +2,14 @@ namespace Tests; use Getnet\API\Transaction; -use Getnet\API\BoletoRespose; use Getnet\API\PixResponse; use Getnet\API\PixTransaction; +use PHPUnit\Framework\Attributes\Group; final class PixTest extends TestBase { - /** - * - * @group e2e - */ + #[Group('e2e')] public function testPixCreate(): PixResponse { $transaction = new PixTransaction(20597.75);