Skip to content

Commit

Permalink
Merge pull request #19 from edson-nascimento/feature/add-suporte-php8
Browse files Browse the repository at this point in the history
feat: atualizar projeto para PHP ^8.2
  • Loading branch information
edson-nascimento authored May 2, 2024
2 parents 4ec19a4 + c50a681 commit 4b8b761
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 112 deletions.
41 changes: 20 additions & 21 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":{
Expand All @@ -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"
},
Expand Down
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 14 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
bootstrap="config/bootstrap.test.php"
colors="true"
backupGlobals="false"
cacheResult="false"
backupStaticAttributes="false">
colors="true"
backupGlobals="false"
cacheResult="false"
cacheDirectory="cache/phpunit"
backupStaticProperties="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">tests</directory>
Expand Down
4 changes: 2 additions & 2 deletions src/Getnet/API/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BaseResponse implements \JsonSerializable
*
* @return array
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return get_object_vars($this);
}
Expand Down Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions src/Getnet/API/Credit.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Getnet\API;

use Getnet\API\Exception\GetnetException;

/**
* Class Credit
*
Expand All @@ -19,6 +21,14 @@ class Credit implements \JsonSerializable
// Pagamento parcelado com juros
const TRANSACTION_TYPE_INSTALL_WITH_INTEREST = "INSTALL_WITH_INTEREST";

const COF_ONE_CLICK = 'ONE_CLICK';

const COF_ONE_CLICK_PAYMENT = 'ONE_CLICK_PAYMENT';

const COF_RECURRING = 'RECURRING';

const COF_RECURRING_PAYMENT = 'RECURRING_PAYMENT';

private $authenticated;

private $delayed;
Expand All @@ -39,6 +49,11 @@ class Credit implements \JsonSerializable

private $cardholder_mobile;

// Tipo do COF (Credential On File).
private $credentials_on_file_type;

private $transaction_id;

/**
*
* @return mixed
Expand Down Expand Up @@ -252,4 +267,50 @@ public function setCardholderMobile($cardholder_mobile)

return $this;
}

/**
*
* @return mixed
*/
public function getCredentialsOnFileType()
{
return $this->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;
}

}
18 changes: 5 additions & 13 deletions src/Getnet/API/TraitEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
trait TraitEntity
{

public function jsonSerialize()
public function jsonSerialize(): mixed
{
$entity = clone $this;

Expand All @@ -14,12 +14,8 @@ public function jsonSerialize()

return $entity->toArray();
}

/**
*
* @return array
*/
public function toArray()

public function toArray(): array
{
$vars = get_object_vars($this);

Expand All @@ -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);
Expand All @@ -52,7 +44,7 @@ public function populateByArray(array $body, array $blockFields = [])
$this->{$prop} = $value;
}
}

return $this;
}

Expand Down
7 changes: 3 additions & 4 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
namespace Tests;

use PHPUnit\Framework\Attributes\Group;

final class AppTest extends TestBase
{

/**
*
* @group e2e
*/
#[Group('e2e')]
public function testCredentials(): void
{
$this->assertInstanceOf(\Getnet\API\Getnet::class, $this->getnetService());
Expand Down
6 changes: 2 additions & 4 deletions tests/AuthorizeDebitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 5 additions & 9 deletions tests/AuthorizePosteriorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 4b8b761

Please sign in to comment.