Skip to content

Commit

Permalink
Add conventions tests to CI (#78)
Browse files Browse the repository at this point in the history
* Run conventions tests in CI

* Fixed dependency issue spotted by convention tests

* Fixed typo in packages

* Try better error output in package conventions

* Fixed dev package install during CIs
  • Loading branch information
yann-eugone authored Jun 4, 2023
1 parent 3106d13 commit f50ef23
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ runs:
shell: bash
run: |
composer require --quiet --no-update "symfony/console:${{ inputs.symfony-version }}"
composer require --quiet --no-update "symfony/filesystem:${{ inputs.symfony-version }}"
composer require --quiet --no-update "symfony/framework-bundle:${{ inputs.symfony-version }}"
composer require --quiet --no-update "symfony/messenger:${{ inputs.symfony-version }}"
composer require --quiet --no-update "symfony/process:${{ inputs.symfony-version }}"
composer require --quiet --no-update "symfony/serializer:${{ inputs.symfony-version }}"
composer require --quiet --no-update "symfony/validator:${{ inputs.symfony-version }}"
composer require --quiet --no-update "symfony/filesystem:${{ inputs.symfony-version }}" --dev
composer require --quiet --no-update "symfony/finder:${{ inputs.symfony-version }}" --dev
composer require --quiet --no-update "symfony/process:${{ inputs.symfony-version }}" --dev
composer update --no-interaction --no-progress --no-suggest
18 changes: 16 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
php-version: ${{ matrix.php-version }}
symfony-version: ${{ matrix.symfony-version }}
- name: "Run tests with phpunit/phpunit"
run: vendor/bin/phpunit
run: vendor/bin/phpunit --testsuite=Code

phpstan:
name: "PhpStan"
Expand Down Expand Up @@ -60,6 +60,20 @@ jobs:
- name: "Run checkstyle with squizlabs/php_codesniffer"
run: vendor/bin/phpcs

conventions:
name: "Conventions"
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v2
- name: "Setup env & install dependencies"
uses: ./.github/actions/install
with:
php-version: '8.2'
symfony-version: '6.2.*'
- name: "Run tests with phpunit/phpunit"
run: vendor/bin/phpunit --testsuite=Convention

codecov:
name: "Code coverage"
runs-on: ubuntu-latest
Expand All @@ -76,6 +90,6 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
vendor/bin/phpunit --coverage-clover coverage.xml
vendor/bin/phpunit --testsuite=Code --coverage-clover coverage.xml
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v1
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"yokai/batch-doctrine-dbal": "self.version",
"yokai/batch-doctrine-orm": "self.version",
"yokai/batch-doctrine-persistence": "self.version",
"yokai/batch-flysystem": "self.version",
"yokai/batch-league-flysystem": "self.version",
"yokai/batch-symfony-console": "self.version",
"yokai/batch-symfony-framework": "self.version",
"yokai/batch-symfony-messenger": "self.version",
Expand Down
9 changes: 9 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
<testsuite name="Symfony">
<directory>./tests/symfony/tests</directory>
</testsuite>

<testsuite name="Code">
<directory>./src/*/tests</directory>
<directory>./tests/integration</directory>
<directory>./tests/symfony/tests</directory>
</testsuite>
<testsuite name="Convention">
<directory>./tests/convention</directory>
</testsuite>
</testsuites>

<coverage>
Expand Down
7 changes: 5 additions & 2 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ install () {
container="$1"
symfony="$2"
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/console:${symfony}
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/filesystem:${symfony} --dev
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/framework-bundle:${symfony}
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/messenger:${symfony}
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/process:${symfony}
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/serializer:${symfony}
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/validator:${symfony}
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/filesystem:${symfony} --dev
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/finder:${symfony} --dev
led in -s ${container} -- composer2 --no-interaction --quiet require --no-update symfony/process:${symfony} --dev
led in -s ${container} -- composer2 --no-interaction update --no-progress --with-all-dependencies
}

install "php82" "6.2.*"
led in -s php82 -- vendor/bin/phpcs
led in -s php82 -- vendor/bin/phpstan analyze
led in -s php82 -- vendor/bin/phpunit --testsuite=Convention

matrix=(
"php80/5.4.*"
Expand All @@ -30,7 +33,7 @@ do
symfony=${config[1]}
echo "${entry}"
install "${container}" "${symfony}"
led in -s ${container} -- vendor/bin/phpunit
led in -s ${container} -- vendor/bin/phpunit --testsuite=Code
done

echo "Revert changes made to composer.json"
Expand Down
2 changes: 1 addition & 1 deletion src/batch-doctrine-dbal/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php": "^8.0",
"ext-json": "*",
"doctrine/dbal": "^2.11",
"doctrine/persistence": "^2.0",
"doctrine/persistence": "^2.0|^3.0",
"yokai/batch": "^0.5.0"
},
"autoload": {
Expand Down
12 changes: 8 additions & 4 deletions tests/convention/Dependency/SourcesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function test(): void
$prodDeps = $rootComposer->packages();
$prodDeps[] = 'yokai/batch';
\sort($prodDeps);
self::assertEmpty(
self::assertSame(
[],
\array_diff($expectedProdDeps, $prodDeps),
'Dependencies of all packages are required in root composer.json'
);
Expand All @@ -51,7 +52,8 @@ public function test(): void
\sort($expectedDevDeps);
$devDeps = $rootComposer->packagesDev();
\sort($devDeps);
self::assertEmpty(
self::assertSame(
[],
\array_diff($expectedDevDeps, $devDeps),
'Dev dependencies of all packages are required in root composer.json'
);
Expand All @@ -68,15 +70,17 @@ public function test(): void
$prodAutoload = $rootComposer->autoload();
\ksort($prodAutoload);
\ksort($expectedProdAutoload);
self::assertEmpty(
self::assertSame(
[],
\array_diff($expectedProdAutoload, $prodAutoload),
'All packages autoload rules are duplicated in root composer.json'
);

$devAutoload = $rootComposer->autoloadDev();
\ksort($devAutoload);
\ksort($expectedDevAutoload);
self::assertEmpty(
self::assertSame(
[],
\array_diff($expectedDevAutoload, $devAutoload),
'All packages dev autoload rules are duplicated in root composer.json'
);
Expand Down

0 comments on commit f50ef23

Please sign in to comment.