diff --git a/.github/workflows/codesniffer.yml b/.github/workflows/codesniffer.yml new file mode 100644 index 0000000..dfc76ff --- /dev/null +++ b/.github/workflows/codesniffer.yml @@ -0,0 +1,15 @@ +name: "Codesniffer" + +on: + pull_request: + + push: + branches: ["*"] + + schedule: + - cron: "0 8 * * 1" + +jobs: + codesniffer: + name: "Codesniffer" + uses: contributte/.github/.github/workflows/codesniffer.yml@v1 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..6db1000 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,17 @@ +name: "Coverage" + +on: + pull_request: + + push: + branches: ["*"] + + schedule: + - cron: "0 8 * * 1" + +jobs: + test80: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1 + with: + php: "8.0" diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index e346c73..0000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,269 +0,0 @@ -name: "build" - -on: - pull_request: - paths-ignore: - - ".docs/**" - push: - branches: - - "*" - schedule: - - cron: "0 8 * * 1" # At 08:00 on Monday - -env: - extensions: "json" - cache-version: "1" - composer-version: "v1" - composer-install: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-stable" - -jobs: - qa: - name: "Quality assurance" - runs-on: "${{ matrix.operating-system }}" - - strategy: - matrix: - php-version: ["7.4"] - operating-system: ["ubuntu-latest"] - fail-fast: false - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Setup PHP cache environment" - id: "extcache" - uses: "shivammathur/cache-extensions@v1" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - key: "${{ env.cache-version }}" - - - name: "Cache PHP extensions" - uses: "actions/cache@v2" - with: - path: "${{ steps.extcache.outputs.dir }}" - key: "${{ steps.extcache.outputs.key }}" - restore-keys: "${{ steps.extcache.outputs.key }}" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - tools: "composer:${{ env.composer-version }} " - - - name: "Setup problem matchers for PHP" - run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"' - - - name: "Get Composer cache directory" - id: "composercache" - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' - - - name: "Cache PHP dependencies" - uses: "actions/cache@v2" - with: - path: "${{ steps.composercache.outputs.dir }}" - key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" - restore-keys: "${{ runner.os }}-composer-" - - - name: "Validate Composer" - run: "composer validate" - - - name: "Install dependencies" - run: "${{ env.composer-install }}" - - - name: "Coding Standard" - run: "make cs" - - static-analysis: - name: "Static analysis" - runs-on: "${{ matrix.operating-system }}" - - strategy: - matrix: - php-version: ["7.4"] - operating-system: ["ubuntu-latest"] - fail-fast: false - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Setup PHP cache environment" - id: "extcache" - uses: "shivammathur/cache-extensions@v1" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - key: "${{ env.cache-version }}" - - - name: "Cache PHP extensions" - uses: "actions/cache@v2" - with: - path: "${{ steps.extcache.outputs.dir }}" - key: "${{ steps.extcache.outputs.key }}" - restore-keys: "${{ steps.extcache.outputs.key }}" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - tools: "composer:${{ env.composer-version }} " - - - name: "Setup problem matchers for PHP" - run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"' - - - name: "Get Composer cache directory" - id: "composercache" - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' - - - name: "Cache PHP dependencies" - uses: "actions/cache@v2" - with: - path: "${{ steps.composercache.outputs.dir }}" - key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" - restore-keys: "${{ runner.os }}-composer-" - - - name: "Install dependencies" - run: "${{ env.composer-install }}" - - - name: "PHPStan" - run: "make phpstan" - - tests: - name: "Tests" - runs-on: "${{ matrix.operating-system }}" - - strategy: - matrix: - php-version: ["7.2", "7.3", "7.4"] - operating-system: ["ubuntu-latest"] - composer-args: [ "" ] - include: - - php-version: "7.4" - operating-system: "ubuntu-latest" - composer-args: "--prefer-lowest" - - php-version: "8.0" - operating-system: "ubuntu-latest" - composer-args: "--ignore-platform-reqs" - fail-fast: false - - continue-on-error: "${{ matrix.php-version == '8.0' }}" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Setup PHP cache environment" - id: "extcache" - uses: "shivammathur/cache-extensions@v1" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - key: "${{ env.cache-version }}" - - - name: "Cache PHP extensions" - uses: "actions/cache@v2" - with: - path: "${{ steps.extcache.outputs.dir }}" - key: "${{ steps.extcache.outputs.key }}" - restore-keys: "${{ steps.extcache.outputs.key }}" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - tools: "composer:${{ env.composer-version }} " - - - name: "Setup problem matchers for PHP" - run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"' - - - name: "Get Composer cache directory" - id: "composercache" - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' - - - name: "Cache PHP dependencies" - uses: "actions/cache@v2" - with: - path: "${{ steps.composercache.outputs.dir }}" - key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" - restore-keys: "${{ runner.os }}-composer-" - - - name: "Install dependencies" - run: "${{ env.composer-install }} ${{ matrix.composer-args }}" - - - name: "Setup problem matchers for PHPUnit" - run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"' - - - name: "Tests" - run: "make tests" - - tests-code-coverage: - name: "Tests with code coverage" - runs-on: "${{ matrix.operating-system }}" - - strategy: - matrix: - php-version: ["7.4"] - operating-system: ["ubuntu-latest"] - fail-fast: false - - if: "github.event_name == 'push'" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Setup PHP cache environment" - id: "extcache" - uses: "shivammathur/cache-extensions@v1" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - key: "${{ env.cache-version }}" - - - name: "Cache PHP extensions" - uses: "actions/cache@v2" - with: - path: "${{ steps.extcache.outputs.dir }}" - key: "${{ steps.extcache.outputs.key }}" - restore-keys: "${{ steps.extcache.outputs.key }}" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - php-version: "${{ matrix.php-version }}" - extensions: "${{ env.extensions }}" - tools: "composer:${{ env.composer-version }} " - - - name: "Setup problem matchers for PHP" - run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"' - - - name: "Get Composer cache directory" - id: "composercache" - run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' - - - name: "Cache PHP dependencies" - uses: "actions/cache@v2" - with: - path: "${{ steps.composercache.outputs.dir }}" - key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}" - restore-keys: "${{ runner.os }}-composer-" - - - name: "Install dependencies" - run: "${{ env.composer-install }}" - - - name: "Tests" - run: "make coverage-clover" - - - name: "Coveralls.io" - env: - CI_NAME: github - CI: true - COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - run: | - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar - php php-coveralls.phar --verbose --config tests/.coveralls.yml diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..db3ad34 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,15 @@ +name: "Phpstan" + +on: + pull_request: + + push: + branches: ["*"] + + schedule: + - cron: "0 8 * * 1" + +jobs: + phpstan: + name: "Phpstan" + uses: contributte/.github/.github/workflows/phpstan.yml@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..0008612 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,43 @@ +name: "Nette Tester" + +on: + pull_request: + + push: + branches: ["*"] + + schedule: + - cron: "0 8 * * 1" + +jobs: + test81: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + with: + php: "8.1" + + test80: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + with: + php: "8.0" + + test74: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + with: + php: "7.4" + + test73: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + with: + php: "7.3" + composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" + + test72: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + with: + php: "7.2" + composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" diff --git a/Makefile b/Makefile index 71f2095..7a0e38f 100644 --- a/Makefile +++ b/Makefile @@ -1,27 +1,29 @@ -.PHONY: install qa lint cs csf phpstan tests coverage-clover coverage-html +.PHONY: install qa cs csf phpstan tests coverage install: composer update -qa: lint phpstan cs - -lint: - vendor/bin/linter src tests +qa: phpstan cs cs: +ifdef GITHUB_ACTION + vendor/bin/codesniffer -q --report=checkstyle src tests | cs2pr +else vendor/bin/codesniffer src tests +endif csf: vendor/bin/codefixer src tests phpstan: - vendor/bin/phpstan analyse -l max -c phpstan.neon src + vendor/bin/phpstan analyse -c phpstan.neon tests: - vendor/bin/tester -s -p php --colors 1 -C tests/cases - -coverage-clover: - vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases - -coverage-html: - vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.html --coverage-src ./src tests/cases + vendor/bin/tester -s -p php --colors 1 -C tests/Cases + +coverage: +ifdef GITHUB_ACTION + vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.xml --coverage-src src tests/Cases +else + vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.html --coverage-src src tests/Cases +endif diff --git a/composer.json b/composer.json index bd2f2ca..48fceca 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ }, "require-dev": { "mockery/mockery": "^1.3.3", - "ninjify/qa": "^0.12", + "ninjify/qa": "^0.13", "ninjify/nunjuck": "^0.4", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-deprecation-rules": "^0.12", - "phpstan/phpstan-nette": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12" + "phpstan/phpstan": "^1.4.0", + "phpstan/phpstan-deprecation-rules": "^1.0.0", + "phpstan/phpstan-nette": "^1.0.0", + "phpstan/phpstan-strict-rules": "^1.0.0" }, "autoload": { "psr-4": { @@ -38,15 +38,16 @@ }, "autoload-dev": { "psr-4": { - "Tests\\Cases\\": "tests/cases", - "Tests\\Fixtures\\": "tests/fixtures", - "Tests\\Toolkit\\": "tests/toolkit" + "Tests\\": "tests" } }, "minimum-stability": "dev", "prefer-stable": true, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "extra": { "branch-alias": { diff --git a/phpstan.neon b/phpstan.neon index 83b3a26..ce4a457 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,6 +5,12 @@ includes: - vendor/phpstan/phpstan-strict-rules/rules.neon parameters: - excludes_analyse: - # Symfony/Console have too magic api - - src/Command/LoadDataFixturesCommand.php + level: 9 + phpVersion: 70200 + + paths: + - src + + reportMaybesInPropertyPhpDocTypes: false + + ignoreErrors: diff --git a/ruleset.xml b/ruleset.xml index df0c0d5..cc9dbb8 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -3,23 +3,19 @@ - - - - + - + + + + /tests/tmp + diff --git a/src/Command/LoadDataFixturesCommand.php b/src/Command/LoadDataFixturesCommand.php index b442931..271d9a0 100644 --- a/src/Command/LoadDataFixturesCommand.php +++ b/src/Command/LoadDataFixturesCommand.php @@ -17,8 +17,6 @@ /** * @see http://symfony.com/doc/2.2/bundles/DoctrineFixturesBundle/index.html - * @author Fabien Potencier - * @author Jonathan H. Wage */ class LoadDataFixturesCommand extends Command { @@ -90,10 +88,14 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { + /** @var string|null $em */ + $em = $input->getOption('em'); + /** @var EntityManager $em */ - $em = $this->managerRegistry->getManager($input->getOption('em')); + $em = $this->managerRegistry->getManager($em); - if ($input->isInteractive() && !$input->getOption('append')) { + $append = $input->getOption('append'); + if ($input->isInteractive() && $append !== null && $append !== '') { if (!$this->askConfirmation( $input, $output, @@ -106,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $dirOrFile = $input->getOption('fixtures'); - if ($dirOrFile) { + if ($dirOrFile !== null && $dirOrFile !== '') { $paths = is_array($dirOrFile) ? $dirOrFile : [$dirOrFile]; $this->loader->loadPaths($paths); } else { @@ -124,14 +126,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + $purgeTruncate = $input->getOption('purge-with-truncate'); $purger = new ORMPurger($em); - $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE); + $purger->setPurgeMode($purgeTruncate !== null && $purgeTruncate !== '' ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE); $executor = new ORMExecutor($em, $purger); $executor->setLogger(function ($message) use ($output): void { $output->writeln(sprintf(' > %s', $message)); }); - $executor->execute($fixtures, $input->getOption('append')); + $executor->execute($fixtures, (bool) $append); //$executor->execute($fixtures, $input->getOption('append'), $input->getOption('multiple-transactions')); return 0; @@ -144,11 +147,17 @@ private function askConfirmation( bool $default ): bool { + $set = $this->getHelperSet(); + + if ($set === null) { + return false; + } + /** @var QuestionHelper $questionHelper */ - $questionHelper = $this->getHelperSet()->get('question'); + $questionHelper = $set->get('question'); $question = new ConfirmationQuestion($question, $default); - return $questionHelper->ask($input, $output, $question); + return (bool) $questionHelper->ask($input, $output, $question); } } diff --git a/tests/cases/Unit/DI/FixturesExtensionTest.php b/tests/Cases/Unit/DI/FixturesExtensionTest.php similarity index 95% rename from tests/cases/Unit/DI/FixturesExtensionTest.php rename to tests/Cases/Unit/DI/FixturesExtensionTest.php index ff9da56..b6a58a9 100644 --- a/tests/cases/Unit/DI/FixturesExtensionTest.php +++ b/tests/Cases/Unit/DI/FixturesExtensionTest.php @@ -36,11 +36,11 @@ public function testLoad(): void ], 'fixtures' => [ 'paths' => [ - '%rootPath%/tests/fixtures', + '%rootPath%/tests/Fixtures', ], ], ]); - }, 'di1'); + }, __METHOD__ . '1'); /** @var Container $container */ $container = new $class(); @@ -74,7 +74,7 @@ public function testLoadPaths(): void ->setType(ManagerRegistry::class); $compiler->addExtension('fixtures', new FixturesExtension()); - }, 'di2'); + }, __FILE__ . '2'); /** @var Container $container */ $container = new $class(); @@ -84,7 +84,7 @@ public function testLoadPaths(): void $loader = $container->getByType(FixturesLoader::class); // Load fixtures manually with given paths - $loader->loadPaths([__DIR__ . '/../../../fixtures']); + $loader->loadPaths([__DIR__ . '/../../../Fixtures']); /** @var ContainerFixture $containerFixture */ $containerFixture = $loader->getFixture(ContainerFixture::class); diff --git a/tests/fixtures/ContainerFixture.php b/tests/Fixtures/ContainerFixture.php similarity index 100% rename from tests/fixtures/ContainerFixture.php rename to tests/Fixtures/ContainerFixture.php