diff --git a/.gitattributes b/.gitattributes index 7234e11..12910b6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,7 +5,6 @@ tests export-ignore .gitattributes export-ignore .gitignore export-ignore .travis.yml export-ignore -codeception.yml export-ignore Makefile export-ignore phpstan.neon export-ignore README.md export-ignore 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..02c5394 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,17 @@ +name: "Coverage" + +on: + pull_request: + + push: + branches: ["*"] + + schedule: + - cron: "0 8 * * 1" + +jobs: + coverage: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1 + with: + php: "8.1" diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index 1dd0c02..0000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,289 +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: "v2" - composer-install: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable" - coverage: "none" - -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 }}, cs2pr" - coverage: "${{ env.coverage }}" - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - 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 }}" - coverage: "${{ env.coverage }}" - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - 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.2" - operating-system: "ubuntu-latest" - composer-args: "--prefer-lowest" - - php-version: "8.0" - operating-system: "ubuntu-latest" - composer-args: "" - 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 }}" - coverage: "${{ env.coverage }}" - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - 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: "Tests" - run: "make tests" - - - name: "Upload test output" - if: ${{ failure() }} - uses: actions/upload-artifact@v2 - with: - name: output - path: tests/**/output - - 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 }}" - coverage: "${{ env.coverage }}" - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - 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: "Upload test output" - if: ${{ failure() }} - uses: actions/upload-artifact@v2 - with: - name: output - path: tests/**/output - - - name: "Coveralls.io" - env: - COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - composer global require php-coveralls/php-coveralls - php-coveralls --coverage_clover=tests/_output/coverage.xml --json_path=coveralls-upload.json -v diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..43545cf --- /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..809a3e1 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,30 @@ +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" + + test-lowest: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + with: + php: "8.0" + composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" diff --git a/.gitignore b/.gitignore index b1b6f4d..9f0e148 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ # Tests /temp +/coverage.html /coverage.xml diff --git a/Makefile b/Makefile index 72d5aea..a3dd4c6 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: install qa cs csf phpstan tests coverage-clover coverage-html +.PHONY: install qa cs csf phpstan tests coverage install: composer update @@ -7,7 +7,7 @@ qa: phpstan cs cs: ifdef GITHUB_ACTION - vendor/bin/codesniffer -q --report=checkstyle src tests | cs2pr + vendor/bin/codesniffer -q --report=checkstyle src tests | cs2pr else vendor/bin/codesniffer src tests endif @@ -16,16 +16,17 @@ csf: vendor/bin/codefixer src tests phpstan: - vendor/bin/phpstan analyse -l 8 -c phpstan.neon src + vendor/bin/phpstan analyse -c phpstan.neon tests: vendor/bin/codecept build vendor/bin/codecept run --debug -coverage-clover: +coverage: +ifdef GITHUB_ACTION vendor/bin/codecept build phpdbg -qrr vendor/bin/codecept run --coverage-xml - -coverage-html: +else vendor/bin/codecept build phpdbg -qrr vendor/bin/codecept run --coverage-html +endif diff --git a/README.md b/README.md index 2e63d54..10b0e7a 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ For details on how to use this package, check out our [documentation](.docs). | State | Version | Branch | PHP | |-------------|----------|----------|---------| -| dev | `^1.4.0` | `master` | `>=7.2` | -| stable | `^1.3.1` | `master` | `>=7.2` | +| dev | `^1.5.0` | `master` | `>=8.0` | +| stable | `^1.4.0` | `master` | `>=8.0` | ## Development diff --git a/composer.json b/composer.json index ec009ae..4966112 100644 --- a/composer.json +++ b/composer.json @@ -19,27 +19,24 @@ } ], "require": { - "php": ">=7.2", - "codeception/codeception": "^4.0.2", - "codeception/lib-innerbrowser": "^1.3 || ^2.0", - "nette/di": "^3.0", - "nette/bootstrap": "^3.0", - "nette/http": "^3.0.3", - "nette/utils": "^3.0" + "php": ">= 8.0", + "codeception/codeception": "^5.0.0", + "codeception/lib-innerbrowser": "^3.0", + "nette/di": "^3.0.13", + "nette/bootstrap": "^3.1.2", + "nette/http": "^3.1.6", + "nette/utils": "^3.2.8" }, "require-dev": { - "latte/latte": "^2.5.1", - "nette/application": "^3.0", - "nette/caching": "~2.5.8 || ^3.0", + "latte/latte": "^2.11.5", + "nette/application": "^3.1.7", + "nette/caching": "^3.1.4", "ninjify/qa": "^0.12", - "phpstan/phpstan": "^1.0", + "phpstan/phpstan": "^1.8.11", "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-nette": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", - "tracy/tracy": "~2.6.1 || ~2.7.0" - }, - "conflict": { - "symfony/browser-kit": "<4.0.0" + "phpstan/phpstan-nette": "^1.1.0", + "phpstan/phpstan-strict-rules": "^1.4.4", + "tracy/tracy": "^2.7.9" }, "autoload": { "psr-4": { @@ -48,20 +45,20 @@ }, "autoload-dev": { "psr-4": { - "Tests\\Functional\\": "tests/functional/src" - }, - "files": [ - "vendor/codeception/codeception/shim.php" - ] + "Tests\\Functional\\": "tests/Functional/src" + } }, "minimum-stability": "dev", "prefer-stable": true, "config": { - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } }, "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "1.5.x-dev" } } } diff --git a/phpstan.neon b/phpstan.neon index 69a693b..5ccda88 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,6 +6,10 @@ includes: - extension.neon parameters: + level: 9 + paths: + - src + excludePaths: - %currentWorkingDirectory%/tests/_* diff --git a/ruleset.xml b/ruleset.xml index 2664749..811b5d2 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,24 +1,25 @@ - + - + - - - - - + + + + + + + + - - /tests/functional - + + /tests/functional + - + /tests/_output /tests/_support /tests/_temp diff --git a/src/Module/NetteApplicationModule.php b/src/Module/NetteApplicationModule.php index 407701a..e0de5ec 100644 --- a/src/Module/NetteApplicationModule.php +++ b/src/Module/NetteApplicationModule.php @@ -15,20 +15,21 @@ class NetteApplicationModule extends Framework { - /** @var mixed[] */ - protected $config = [ + /** @var array */ + protected array $config = [ 'followRedirects' => true, ]; - /** @var string */ - private $path; + private string $path; /** - * @param mixed[] $settings + * @param array{path?: string} $settings * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint */ public function _beforeSuite($settings = []): void { + assert(isset($settings['path'])); + $this->path = $settings['path']; } @@ -43,7 +44,7 @@ function (): Container { return $diModule->getContainer(); } ); - $this->client->followRedirects($this->config['followRedirects']); + $this->client->followRedirects((bool) $this->config['followRedirects']); parent::_before($test); } diff --git a/src/Module/NetteDIModule.php b/src/Module/NetteDIModule.php index d73d351..e81a2cf 100644 --- a/src/Module/NetteDIModule.php +++ b/src/Module/NetteDIModule.php @@ -4,7 +4,7 @@ use Codeception\Module; use Codeception\TestInterface; -use Nette\Caching\Storages\IJournal; +use Nette\Caching\Storages\Journal; use Nette\Caching\Storages\SQLiteJournal; use Nette\Configurator; use Nette\DI\Container; @@ -23,8 +23,8 @@ class NetteDIModule extends Module /** @var callable[] function(Container $container): void; */ public $onCreateContainer = []; - /** @var mixed[] */ - protected $config = [ + /** @var array */ + protected array $config = [ 'configFiles' => [], 'appDir' => null, 'logDir' => null, @@ -34,8 +34,8 @@ class NetteDIModule extends Module 'newContainerForEachTest' => false, ]; - /** @var string[] */ - protected $requiredFields = [ + /** @var string[] */ + protected array $requiredFields = [ 'tempDir', ]; @@ -49,11 +49,13 @@ class NetteDIModule extends Module private $container; /** - * @param mixed[] $settings + * @param array{path?: string} $settings * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint */ - public function _beforeSuite($settings = []): void + public function _beforeSuite(array $settings = []): void { + assert(isset($settings['path'])); + $this->path = rtrim($settings['path'], '/'); $this->clearTempDir(); } @@ -143,9 +145,10 @@ private function createContainer(): void $configurator->setTempDirectory($tempDir); if ($this->config['debugMode'] !== null) { - $configurator->setDebugMode($this->config['debugMode']); + $configurator->setDebugMode((bool) $this->config['debugMode']); } + /** @var iterable $configFiles */ $configFiles = $this->configFiles !== [] ? $this->configFiles : $this->config['configFiles']; foreach ($configFiles as $file) { $configurator->addConfig(FileSystem::isAbsolute($file) ? $file : $this->path . '/' . $file); @@ -200,7 +203,7 @@ private function stopContainer(): void } try { - $journal = $this->container->getByType(IJournal::class); + $journal = $this->container->getByType(Journal::class); if ($journal instanceof SQLiteJournal) { $property = new ReflectionProperty(SQLiteJournal::class, 'pdo'); $property->setAccessible(true); diff --git a/tests/functional.suite.yml b/tests/Functional.suite.yml similarity index 90% rename from tests/functional.suite.yml rename to tests/Functional.suite.yml index f3e1371..1741934 100644 --- a/tests/functional.suite.yml +++ b/tests/Functional.suite.yml @@ -1,6 +1,6 @@ error_level: "E_ALL" -class_name: FunctionalSuiteTester +actor: FunctionalTester modules: enabled: diff --git a/tests/functional/config/config.neon b/tests/Functional/config/config.neon similarity index 100% rename from tests/functional/config/config.neon rename to tests/Functional/config/config.neon diff --git a/tests/functional/src/ApplicationTest.php b/tests/Functional/src/ApplicationTest.php similarity index 100% rename from tests/functional/src/ApplicationTest.php rename to tests/Functional/src/ApplicationTest.php diff --git a/tests/functional/src/DITest.php b/tests/Functional/src/DITest.php similarity index 100% rename from tests/functional/src/DITest.php rename to tests/Functional/src/DITest.php diff --git a/tests/functional/src/Fixtures/ArticlePresenter.php b/tests/Functional/src/Fixtures/ArticlePresenter.php similarity index 100% rename from tests/functional/src/Fixtures/ArticlePresenter.php rename to tests/Functional/src/Fixtures/ArticlePresenter.php diff --git a/tests/functional/src/Fixtures/RouterFactory.php b/tests/Functional/src/Fixtures/RouterFactory.php similarity index 82% rename from tests/functional/src/Fixtures/RouterFactory.php rename to tests/Functional/src/Fixtures/RouterFactory.php index 8007d2c..7e31b96 100644 --- a/tests/functional/src/Fixtures/RouterFactory.php +++ b/tests/Functional/src/Fixtures/RouterFactory.php @@ -2,14 +2,13 @@ namespace Tests\Functional\Fixtures; -use Nette\Application\IRouter; use Nette\Application\Routers\Route; use Nette\Application\Routers\RouteList; class RouterFactory { - public function create(): IRouter + public function create(): RouteList { $router = new RouteList(); $router[] = new Route('[/[/]]', 'Homepage:default'); diff --git a/tests/functional/templates/Article.link.latte b/tests/Functional/templates/Article.link.latte similarity index 100% rename from tests/functional/templates/Article.link.latte rename to tests/Functional/templates/Article.link.latte diff --git a/tests/functional/templates/Article.page.latte b/tests/Functional/templates/Article.page.latte similarity index 100% rename from tests/functional/templates/Article.page.latte rename to tests/Functional/templates/Article.page.latte diff --git a/tests/functional/_bootstrap.php b/tests/functional/_bootstrap.php deleted file mode 100644 index 3c6b265..0000000 --- a/tests/functional/_bootstrap.php +++ /dev/null @@ -1 +0,0 @@ -