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 7bbc29b..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 8e4057b..6f15def 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,10 @@ "mockery/mockery": "^1.3.1", "ninjify/qa": "^0.12", "ninjify/nunjuck": "^0.4", - "phpstan/phpstan": "^0.12.64", - "phpstan/phpstan-deprecation-rules": "^0.12.2", - "phpstan/phpstan-nette": "^0.12.3", - "phpstan/phpstan-strict-rules": "^0.12.2" + "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" }, "conflict": { "nette/di": "<3.0.6", @@ -41,9 +41,7 @@ }, "autoload-dev": { "psr-4": { - "Tests\\Cases\\": "tests/cases", - "Tests\\Fixtures\\": "tests/fixtures", - "Tests\\Toolkit\\": "tests/toolkit" + "Tests\\": "tests" } }, "minimum-stability": "dev", diff --git a/phpstan.neon b/phpstan.neon index 1bc33be..727fe61 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,7 +5,11 @@ includes: - vendor/phpstan/phpstan-strict-rules/rules.neon parameters: + level: 9 + phpVersion: 70200 + + paths: + - src + ignoreErrors: - # We will replace it once, for sure - - '#Fetching class constant .+ of deprecated class Doctrine\\ORM\\Tools\\Console\\Command\\(GenerateEntities|GenerateRepositories)Command.+#' - - '#Fetching class constant .+ of deprecated class Doctrine\\ORM\\Proxy\\Proxy.+#' + - '#Fetching class constant .+ of deprecated class Doctrine\\\w+.+#' diff --git a/ruleset.xml b/ruleset.xml index b4ebe0c..5093027 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -3,14 +3,12 @@ - + - - - + @@ -18,3 +16,4 @@ /tests/tmp + diff --git a/src/Mapping/ContainerEntityListenerResolver.php b/src/Mapping/ContainerEntityListenerResolver.php index 6ae1fab..07c5c2b 100644 --- a/src/Mapping/ContainerEntityListenerResolver.php +++ b/src/Mapping/ContainerEntityListenerResolver.php @@ -57,11 +57,20 @@ public function register($object): void */ public function resolve($className) { - if (isset($this->instances[$className = trim($className, '\\')])) { + /** @var class-string $className */ + $className = trim($className, '\\'); + + if (isset($this->instances[$className])) { return $this->instances[$className]; } - $this->instances[$className] = $this->container->getByType($className, false) ?? new $className(); + $service = $this->container->getByType($className, false); + + if ($service) { + $this->instances[$className] = $service; + } else { + $this->instances[$className] = new $className(); + } return $this->instances[$className]; } diff --git a/tests/cases/DI/Configuration/EntityListenerResolver.phpt b/tests/Cases/DI/Configuration/EntityListenerResolver.phpt similarity index 97% rename from tests/cases/DI/Configuration/EntityListenerResolver.phpt rename to tests/Cases/DI/Configuration/EntityListenerResolver.phpt index 2667861..01bacf3 100644 --- a/tests/cases/DI/Configuration/EntityListenerResolver.phpt +++ b/tests/Cases/DI/Configuration/EntityListenerResolver.phpt @@ -1,6 +1,6 @@ = 8.0 */ -namespace Tests\Cases\DI; +namespace Tests\Casesě\DI; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; diff --git a/tests/cases/DI/OrmCacheExtension.phpt b/tests/Cases/DI/OrmCacheExtension.phpt similarity index 98% rename from tests/cases/DI/OrmCacheExtension.phpt rename to tests/Cases/DI/OrmCacheExtension.phpt index dce8a2e..a61d60a 100644 --- a/tests/cases/DI/OrmCacheExtension.phpt +++ b/tests/Cases/DI/OrmCacheExtension.phpt @@ -1,6 +1,6 @@ = 8.0 */ -namespace Tests\Cases\E2E; +namespace Tests\Casesě\E2E; use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; diff --git a/tests/cases/ManagerRegistry.phpt b/tests/Cases/ManagerRegistry.phpt similarity index 95% rename from tests/cases/ManagerRegistry.phpt rename to tests/Cases/ManagerRegistry.phpt index 076841f..768133f 100644 --- a/tests/cases/ManagerRegistry.phpt +++ b/tests/Cases/ManagerRegistry.phpt @@ -1,6 +1,6 @@