Skip to content

Commit

Permalink
Merge pull request #31 from b24io/feature/27-downgrade-v3-to-php-74
Browse files Browse the repository at this point in the history
Feature/27 downgrade v3 to php 74
  • Loading branch information
b24io-sdk authored May 23, 2024
2 parents e1d01f3 + 8815442 commit f0d0d2b
Show file tree
Hide file tree
Showing 120 changed files with 3,282 additions and 376 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/integration-v3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "Integration tests"

on:
pull_request:
branches:
- v3
push:
branches:
- v3

env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
LOYALTY_API_ENDPOINT_URL: ${{ vars.LOYALTY_API_ENDPOINT_URL }}
LOYALTY_API_CLIENT_ID: ${{ secrets.LOYALTY_API_CLIENT_ID }}
LOYALTY_API_ADMIN_KEY: ${{ secrets.LOYALTY_API_ADMIN_KEY }}

jobs:
tests:
name: "Integration tests"
runs-on: ${{ matrix.operating-system }}
environment: integration-tests
strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
dependencies: [ highest ]
operating-system: [ ubuntu-latest, windows-latest ]

steps:

- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: shivammathur/setup-php@2.30.4
with:
coverage: xdebug
extensions: mbstring, intl, json, bcmath, curl
php-version: "${{ matrix.php-version }}"
ini-values: variables_order=EGPCS

- name: "Install dependencies"
run: |
composer update ${{ env.COMPOSER_FLAGS }}
- name: "Debug ENV variables"
run: |
printenv
- name: "Run integration tests"
run: |
php vendor/bin/phpunit --colors=always --testsuite integration-tests
- name: "integration tests succeeded"
if: ${{ success() }}
run: |
echo '✅ integration tests pass, congratulations!'
- name: "integration tests failed"
if: ${{ failure() }}
run: |
echo '::error:: ❗integration tests failed (╯°益°)╯彡┻━┻ '
62 changes: 62 additions & 0 deletions .github/workflows/integration-v4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Integration tests"

on:
push:
branches:
- v4
- master

env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --prefer-dist"
LOYALTY_API_ENDPOINT_URL: ${{ vars.LOYALTY_API_ENDPOINT_URL }}
LOYALTY_API_CLIENT_ID: ${{ secrets.LOYALTY_API_CLIENT_ID }}
LOYALTY_API_ADMIN_KEY: ${{ secrets.LOYALTY_API_ADMIN_KEY }}

jobs:
tests:
name: "Integration tests"
runs-on: ${{ matrix.operating-system }}
environment: integration-tests
strategy:
fail-fast: false
matrix:
php-version:
- "8.2"
- "8.3"
dependencies: [ highest ]
operating-system: [ ubuntu-latest, windows-latest ]

steps:

- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: shivammathur/setup-php@2.30.4
with:
coverage: xdebug
extensions: mbstring, intl, json, bcmath, curl
php-version: "${{ matrix.php-version }}"
ini-values: variables_order=EGPCS

- name: "Install dependencies"
run: |
composer update ${{ env.COMPOSER_FLAGS }}
- name: "Debug ENV variables"
run: |
printenv
- name: "Run integration tests"
run: |
php vendor/bin/phpunit --colors=always --testsuite integration-tests
- name: "integration tests succeeded"
if: ${{ success() }}
run: |
echo '✅ integration tests pass, congratulations!'
- name: "integration tests failed"
if: ${{ failure() }}
run: |
echo '::error:: ❗integration tests failed (╯°益°)╯彡┻━┻ '
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
php-version:
- "8.3"
- "7.4"
dependencies: [ highest ]

steps:
Expand All @@ -37,7 +37,7 @@ jobs:
run: "composer update --no-interaction --no-progress --no-suggest"

- name: "PHPStan"
run: "make phpstan"
run: "make lint-phpstan"

- name: "is PHPStan check succeeded"
if: ${{ success() }}
Expand Down
31 changes: 25 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@ default:
@echo "make needs target:"
@egrep -e '^\S+' ./Makefile | grep -v default | sed -r 's/://' | sed -r 's/^/ - /'

phpstan:
vendor/bin/phpstan analyse
phpinsights:
vendor/bin/phpinsights analyse ./src

test-integration:
php vendor/bin/phpunit --colors=always --testsuite integration-tests
init:
docker-compose down --remove-orphans
docker-compose build
docker-compose run --rm php-cli composer install
docker-compose run --rm php-cli chown -R www-data:www-data /var/www/html/var/
docker-compose up -d

cli-bash:
docker-compose run --rm php-cli sh $(filter-out $@,$(MAKECMDGOALS))
integration-tests:
docker-compose run --rm php-cli vendor/bin/phpunit --colors=always --testsuite=integration-tests
lint-phpstan:
docker-compose run --rm php-cli vendor/bin/phpstan analyse --memory-limit 1G
lint-rector:
docker-compose run --rm php-cli vendor/bin/rector process --dry-run
lint-rector-fix:
docker-compose run --rm php-cli vendor/bin/rector process

composer-install:
@echo "install dependencies"
docker-compose run --rm php-cli composer install
composer-update:
@echo "update dependencies"
docker-compose run --rm php-cli composer update

27 changes: 14 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@
}
],
"require": {
"php": "8.2.* || 8.3.*",
"php": "7.4.* || 8.2.* || 8.3.*",
"ext-json": "*",
"ext-bcmath": "*",
"ext-curl": "*",
"ext-intl": "*",
"psr/log": "^1.1.4 || ^2.0 || ^3.0",
"fig/http-message-util": "1.1.*",
"symfony/console": "7.*",
"symfony/dotenv": "7.*",
"symfony/http-client": "7.*",
"symfony/http-client-contracts": "^3.1",
"symfony/http-foundation": "7.*",
"symfony/uid": "7.*",
"symfony/filesystem": "7.*",
"moneyphp/money": "4.*",
"symfony/console": "^5.4 || 7.*",
"symfony/dotenv": "^5.4 || 7.*",
"symfony/http-client": "^5.4 || 7.*",
"symfony/http-client-contracts": "^2.4 ||^3.1",
"symfony/http-foundation": "^5.4 || 7.*",
"symfony/uid": "^5.4 || 7.*",
"symfony/filesystem": "^5.4 || 7.*",
"moneyphp/money": "^3.3 || 4.*",
"giggsey/libphonenumber-for-php": "8.1.*",
"league/csv": "^9.0",
"mesilov/moneyphp-percentage": "0.2.0"
"mesilov/moneyphp-percentage": "0.1.0 || 0.2.0"
},
"require-dev": {
"monolog/monolog": "2.1.*",
"symfony/debug-bundle": "7.*",
"rector/rector": "*",
"monolog/monolog": "^2.5 || ^3.0",
"symfony/debug-bundle": "^5.4 || 7.*",
"phpstan/phpstan": "1.*",
"phpunit/phpunit": "*",
"symfony/stopwatch": "7.*",
"symfony/stopwatch": "^5.4 || 7.*",
"roave/security-advisories": "dev-master",
"nunomaduro/phpinsights": "2.*",
"fakerphp/faker": "1.23.*"
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3'

services:
php-cli:
build:
context: ./docker/php-cli
volumes:
- .:/var/www/html
working_dir: /var/www/html
10 changes: 10 additions & 0 deletions docker/php-cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM php:7.4-cli-alpine

RUN apk add unzip libpq-dev git icu-dev \
&& docker-php-ext-install bcmath intl \
&& docker-php-ext-enable bcmath intl

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --quiet

ENV COMPOSER_ALLOW_SUPERUSER 1
WORKDIR /var/www/html
8 changes: 4 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<directory>tests/Integration/</directory>
</testsuite>
</testsuites>
<source>
<include>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</include>
</source>
</whitelist>
</filter>
</phpunit>
26 changes: 26 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSets(
[DowngradeLevelSetList::DOWN_TO_PHP_74]
)
->withPhpSets(
false, // 8.3
false, // 8.2
false, // 8.1
false, // 8.0
true // 7.4
)
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
]);
26 changes: 16 additions & 10 deletions src/Commands/Cards/ExportCards.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,28 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

#[AsCommand(
name: 'cards:export',
description: 'Export loyalty cards to csv file')]

class ExportCards extends Command
{
protected CardItemFormatter $cardItemFormatter;
protected CardLevelItemFormatter $cardLevelItemFormatter;
protected ContactItemFormatter $contactItemFormatter;
protected LoggerInterface $logger;
protected static $defaultName = 'cards:export';
protected static $defaultDescription = 'Export loyalty cards to csv file';
public function __construct(
protected CardItemFormatter $cardItemFormatter,
protected CardLevelItemFormatter $cardLevelItemFormatter,
protected ContactItemFormatter $contactItemFormatter,
protected LoggerInterface $logger
CardItemFormatter $cardItemFormatter,
CardLevelItemFormatter $cardLevelItemFormatter,
ContactItemFormatter $contactItemFormatter,
LoggerInterface $logger
)
{
$this->cardItemFormatter = $cardItemFormatter;
$this->cardLevelItemFormatter = $cardLevelItemFormatter;
$this->contactItemFormatter = $contactItemFormatter;
$this->logger = $logger;
parent::__construct();
}

protected function configure(): void
{
$this->addOption(
Expand All @@ -63,7 +70,6 @@ protected function configure(): void
InputOption::VALUE_REQUIRED,
'file to store cards');
}

/**
* @throws UnavailableStream
* @throws CannotInsertRecord
Expand Down Expand Up @@ -133,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);

foreach ($admSb->cardsScope()->fetcher()->list(new ItemsOrder('created', OrderDirection::desc)) as $card) {
foreach ($admSb->cardsScope()->fetcher()->list(new ItemsOrder('created', OrderDirection::desc())) as $card) {
$contact = array_fill(0, count($this->contactItemFormatter->fields()), null);
if ($card->contact !== null) {
//todo add external_id_key to cli arguments
Expand Down
Loading

0 comments on commit f0d0d2b

Please sign in to comment.