Skip to content

Commit

Permalink
Sf6 compat php74 compat (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
yivi committed Jan 9, 2022
1 parent c564b08 commit 19d5c11
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 29 deletions.
122 changes: 113 additions & 9 deletions .github/workflows/ci-2.x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,36 @@ on:
- master

jobs:
tests:

code_style_composer_checks:
name: Runs PHP-CS-Fixer to check for CS issues, and validates composer.json
runs-on: ubuntu-latest

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: composer:v2

- name: Install PHP-CS-Fixer
run: composer install --no-progress --ansi --working-dir=tools/php-cs-fixer

- name: Run PHP-CS-Fixer
run: |
sed -i "s/'phpdoc_to_return_type' => true/'phpdoc_to_return_type' => false/g" .php-cs-fixer.php
composer cs-check
- name: Validate composer
run: composer validate --strict --no-check-lock

tests_sf4_sf5:
name: Tests PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ${{ matrix.db }}
runs-on: ubuntu-latest
needs: [ code_style_composer_checks ]

services:
mysql:
Expand Down Expand Up @@ -46,6 +73,7 @@ jobs:
php:
- '7.4'
- '8.0'
- '8.1'
symfony:
- '4.4.*'
- '5.*'
Expand Down Expand Up @@ -91,21 +119,97 @@ jobs:

- name: Update project dependencies (5.*)
if: matrix.symfony == '5.*'
run: composer update --no-progress --ansi --prefer-stable
run: SYMFONY_REQUIRE="^5.4" composer update --no-progress --ansi --prefer-stable

- name: Install PHPStan
run: composer install --no-progress --ansi --working-dir=tools/phpstan

- name: Install PHP-CS-Fixer
run: composer install --no-progress --ansi --working-dir=tools/php-cs-fixer
- name: Run PHPStan
run: composer phpstan

- name: Validate composer
run: composer validate --strict --no-check-lock
- name: Run tests
run: vendor/bin/phpunit -c phpunit.${{ matrix.db }}.xml

- name: Run PHP-CS-Fixer
tests_sf_6:
name: Tests PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, ${{ matrix.db }}
runs-on: ubuntu-latest
needs: [ code_style_composer_checks ]

services:
mysql:
image: mysql:8
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: auditor
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
postgres:
image: postgres
env:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
php:
- '8.0'
- '8.1'
symfony:
- '6.*'
db:
- 'sqlite'
- 'mysql'
- 'pgsql'
fail-fast: false

steps:
- name: Shutdown Ubuntu MySQL (SUDO)
run: sudo service mysql stop # Shutdown the Default MySQL, "sudo" is necessary, please not remove it

- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: composer:v2, flex, pcov
coverage: pcov

- name: Configure Symfony
run: |
sed -i "s/'phpdoc_to_return_type' => true/'phpdoc_to_return_type' => false/g" .php-cs-fixer.php
composer cs-check
composer global require --no-progress --no-scripts --no-plugins symfony/flex
composer config extra.symfony.require "${{ matrix.symfony }}"
- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ matrix.php }}-composer-

- name: Update project dependencies (6.*)
if: matrix.symfony == '6.*'
run: SYMFONY_REQUIRE="^6.0" composer update --no-progress --ansi --prefer-stable

- name: Install PHPStan
run: composer install --no-progress --ansi --working-dir=tools/phpstan

- name: Run PHPStan
run: composer phpstan
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"ext-json": "*",
"doctrine/annotations": "^1.8",
"doctrine/orm": "^2.7",
"symfony/cache": "^4.0|^5.0",
"symfony/event-dispatcher": "^4.0|^5.0",
"symfony/lock": "^4.0|^5.0",
"symfony/options-resolver": "^4.0|^5.0"
"symfony/cache": "^4.0|^5.0|^6.0",
"symfony/event-dispatcher": "^4.0|^5.0|^6.0",
"symfony/lock": "^4.0|^5.0|^6.0",
"symfony/options-resolver": "^4.0|^5.0|^6.0"
},
"suggest": {
"damienharper/auditor-bundle": "Integrate auditor library in your Symfony projects."
Expand All @@ -36,7 +36,7 @@
"require-dev": {
"gedmo/doctrine-extensions": "^2.4|^3.0",
"phpunit/phpunit": "^9.0",
"symfony/var-dumper": "^4.0|^5.0"
"symfony/var-dumper": "^4.0|^5.0|^6.0"
},
"conflict": {
"doctrine/persistence": "<1.3"
Expand Down
24 changes: 17 additions & 7 deletions src/Provider/Doctrine/Auditing/Transaction/AuditTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ trait AuditTrait
/**
* Returns the primary key value of an entity.
*
* @param object $entity
* @throws \DH\Auditor\Exception\MappingException
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\ORM\Mapping\MappingException
*
* @return mixed
*/
private function id(EntityManagerInterface $entityManager, $entity)
private function id(EntityManagerInterface $entityManager, object $entity)
{
$meta = $entityManager->getClassMetadata(DoctrineHelper::getRealClassName($entity));

Expand Down Expand Up @@ -62,12 +64,15 @@ private function id(EntityManagerInterface $entityManager, $entity)
*
* @param mixed $value
*
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\DBAL\Types\ConversionException
*
* @return mixed
*/
private function value(EntityManagerInterface $entityManager, Type $type, $value)
{
if (null === $value) {
return;
return null;
}

$platform = $entityManager->getConnection()->getDatabasePlatform();
Expand Down Expand Up @@ -120,9 +125,12 @@ private function value(EntityManagerInterface $entityManager, Type $type, $value
/**
* Computes a usable diff.
*
* @param object $entity
* @throws \DH\Auditor\Exception\MappingException
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\DBAL\Types\ConversionException
* @throws \Doctrine\ORM\Mapping\MappingException
*/
private function diff(EntityManagerInterface $entityManager, $entity, array $changeset): array
private function diff(EntityManagerInterface $entityManager, object $entity, array $changeset): array
{
$meta = $entityManager->getClassMetadata(DoctrineHelper::getRealClassName($entity));
$diff = [
Expand Down Expand Up @@ -170,9 +178,11 @@ private function diff(EntityManagerInterface $entityManager, $entity, array $cha
/**
* Returns an array describing an entity.
*
* @param null|object $entity
* @throws \DH\Auditor\Exception\MappingException
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\ORM\Mapping\MappingException
*/
private function summarize(EntityManagerInterface $entityManager, $entity = null, array $extra = []): ?array
private function summarize(EntityManagerInterface $entityManager, ?object $entity = null, array $extra = []): ?array
{
if (null === $entity) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class RangeFilter implements FilterInterface
{
/**
* @var string
*/
protected $name;
protected string $name;

/**
* @var mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ public function getId()

/**
* Get the value of name.
*
* @return mixed
*/
public function getLabel()
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Provider/Doctrine/Fixtures/Issue40/DieselCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class DieselCase

/**
* Get the value of name.
*
* @return mixed
*/
public function getName()
{
Expand Down

0 comments on commit 19d5c11

Please sign in to comment.