diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 080bc9d..e83d042 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -41,5 +41,8 @@ jobs: php tests/app/bin/console cache:clear composer phpstan + - name: Check Deptrac + run: composer deptrac:analyse + - name: Check Symfony YAML Config run: composer yaml:lint diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 287d037..bf50f41 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -43,4 +43,6 @@ jobs: dependency-versions: ${{ matrix.dependencies }} - name: Execute tests - run: composer tests + run: | + composer tests:coverage:ci-pipeline + php check_coverage.php diff --git a/check_coverage.php b/check_coverage.php new file mode 100755 index 0000000..2bc0329 --- /dev/null +++ b/check_coverage.php @@ -0,0 +1,17 @@ + php-cs-fixer.json", + "cs:check:ci-pipeline": "php-cs-fixer fix --dry-run --ansi --verbose --diff --format=json > php-cs-fixer.json", "cs:fix": "php-cs-fixer fix --ansi --verbose --diff", "deptrac:analyse": "deptrac --config-file=depfile.yaml", "deptrac:analyse:visual": "deptrac --formatter=graphviz-html --output=deptrac.analyse-result.html --config-file=depfile.yaml", "phpstan": "phpstan analyse --ansi", - "phpstan:gitlab-ci": "phpstan analyse --ansi --no-interaction --no-progress --error-format=gitlab > phpstan-report.json", + "phpstan:ci-pipeline": "phpstan analyse --ansi --no-interaction --no-progress --error-format=github > phpstan-report.json", "tests": "phpunit", - "tests:coverage:gitlab-ci": "phpunit --colors=never --coverage-text --coverage-cobertura .coverage/cobertura.xml --log-junit .coverage/junit.xml", + "tests:coverage:ci-pipeline": "phpunit --colors=never --coverage-text --coverage-cobertura .coverage/cobertura.xml --log-junit .coverage/junit.xml", "yaml:lint": "yaml-lint config tests/Fixtures/Config" }, "scripts-descriptions": { "cs:check": "Checks code style (but doesn't fix anything)", - "cs:check:gitlab-ci": "Checks code style and redirects the output into a GitLab readable file", + "cs:check:ci-pipeline": "Checks code style and redirects the output into a readable file for CI pipelining", "cs:fix": "Checks and fixes code style", "deptrac:analyse": "Analyse your dependencies and follow the pre-defined rules and layers", "deptrac:analyse:visual": "Visualize your dependencies and follow the pre-defined rules and layers", "phpstan": "Checks for code smells", - "phpstan:gitlab-ci": "Checks for code smells and redirects the output into a GitLab readable file", + "phpstan:ci-pipeline": "Checks for code smells and redirects the output into a Github readable file", "tests": "Run all phpunit tests", - "tests:coverage:gitlab-ci": "Run all phpunit tests and create coverage reports", + "tests:coverage:ci-pipeline": "Run all phpunit tests and create coverage reports", "yaml:lint": "Lints Symfony YAML config files" } } diff --git a/phpstan.neon b/phpstan.neon index 689b0bc..d477785 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,4 +5,6 @@ parameters: paths: - src - checkGenericClassInNonGenericObjectType: false + ignoreErrors: + - + identifier: missingType.generics diff --git a/tests/Target/GenericTargetFactoryTest.php b/tests/Target/GenericTargetFactoryTest.php new file mode 100644 index 0000000..602c492 --- /dev/null +++ b/tests/Target/GenericTargetFactoryTest.php @@ -0,0 +1,75 @@ +factory = new GenericTargetFactory(TestTarget::class); + $result = $this->factory->create(); + + self::assertSame(1, $result->getValue()); + } + + /** + * @test + */ + public function create_with_non_instnatiable_case(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Neusta\\ConverterBundle\\Tests\\Target\\TestNonInstantiableTarget" is not instantiable.'); + $this->factory = new GenericTargetFactory(TestNonInstantiableTarget::class); + } + + /** + * @test + */ + public function create_with_constructor_params_case(): void + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Neusta\\ConverterBundle\\Tests\\Target\\TestWithConstructorParamsTarget" has required constructor parameters'); + $this->factory = new GenericTargetFactory(TestWithConstructorParamsTarget::class); + } +} + +class TestTarget +{ + private int $value; + + public function __construct() + { + $this->value = 1; + } + + public function getValue(): int + { + return $this->value; + } +} + +class TestNonInstantiableTarget +{ + private int $value; + + private function __construct() + { + $this->value = 1; + } +} + +class TestWithConstructorParamsTarget +{ + public function __construct( + private int $value, + ) { + } +}