From a6e635ecf0eef2661f0d78383f189e95d45da4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Guti=C3=A9rrez?= Date: Mon, 6 Jan 2020 18:43:03 +0100 Subject: [PATCH] update tooling --- .editorconfig | 3 - .gitignore | 1 - .php_cs | 23 +++-- .scrutinizer.yml | 24 +++-- .styleci.yml | 1 + .travis.yml | 10 +-- composer.json | 30 ++++--- phpstan.neon | 9 +- src/Annotation/AbstractAnnotation.php | 6 +- src/Driver/AbstractAnnotationDriver.php | 18 ++-- src/Driver/AbstractDriverFactory.php | 16 ++-- src/Driver/AbstractMappingDriver.php | 8 +- src/Driver/DriverFactoryInterface.php | 2 +- src/Driver/Locator/FileLocator.php | 4 +- src/Driver/Traits/PhpMappingTrait.php | 2 +- src/Metadata/MetadataResolver.php | 4 +- .../Annotation/AbstractAnnotationTest.php | 21 +++-- .../Driver/AbstractAnnotationDriverTest.php | 2 +- .../Driver/AbstractDriverFactoryTest.php | 87 +++++++++---------- tests/Mapping/Driver/AbstractDriverTest.php | 2 +- .../Driver/AbstractMappingDriverTest.php | 2 +- .../Driver/Locator/FileLocatorTest.php | 11 ++- .../Driver/Traits/JsonMappingTraitTest.php | 16 ++-- .../Driver/Traits/PhpMappingTraitTest.php | 6 +- .../Driver/Traits/XmlMappingTraitTest.php | 16 ++-- .../Driver/Traits/YamlMappingTraitTest.php | 18 ++-- .../Mapping/Metadata/MetadataResolverTest.php | 4 +- tests/Mapping/Stubs/AnnotationStub.php | 2 +- 28 files changed, 186 insertions(+), 162 deletions(-) diff --git a/.editorconfig b/.editorconfig index c21d79c..3b75808 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,9 +17,6 @@ indent_size = 2 [*.json] indent_size = 2 -[*.neon] -indent_size = 2 - [*.yml] indent_size = 2 diff --git a/.gitignore b/.gitignore index c1dc421..3cef788 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ composer.lock cghooks.lock vendor/ -.yo-rc.json *.cache infection-log.* build/ diff --git a/.php_cs b/.php_cs index 96f9123..1800626 100644 --- a/.php_cs +++ b/.php_cs @@ -33,19 +33,18 @@ return Config::create() 'array_syntax' => [ 'syntax' => 'short', ], - 'binary_operator_spaces' => [ - 'align_double_arrow' => false, - 'align_equals' => false, - ], + 'binary_operator_spaces' => true, 'blank_line_after_opening_tag' => true, 'cast_spaces' => true, 'class_attributes_separation' => true, 'combine_consecutive_unsets' => true, + 'compact_nullable_typehint' => true, 'concat_space' => [ 'spacing' => 'one' ], 'declare_equal_normalize' => true, 'declare_strict_types' => true, + 'dir_constant' => true, 'function_typehint_space' => true, 'hash_to_slash_comment' => true, 'header_comment' => [ @@ -55,8 +54,14 @@ return Config::create() 'heredoc_to_nowdoc' => true, 'include' => true, 'linebreak_after_opening_tag' => true, + 'list_syntax' => [ + 'syntax' => 'short', + ], 'lowercase_cast' => true, + 'lowercase_static_reference' => true, + 'magic_constant_casing' => true, 'modernize_types_casting' => true, + 'native_constant_invocation' => true, 'native_function_casing' => true, 'native_function_invocation' => true, 'new_with_braces' => true, @@ -80,13 +85,17 @@ return Config::create() 'no_trailing_comma_in_singleline_array' => true, 'no_unneeded_control_parentheses' => true, 'no_unreachable_default_argument_value' => true, + 'no_unneeded_final_method' => true, + 'no_unset_on_property' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'normalize_index_brace' => true, - 'ordered_imports' => true, + 'ordered_imports' => [ + 'imports_order' => ['const', 'class', 'function'], + ], 'php_unit_construct' => true, 'php_unit_dedicate_assert' => true, 'phpdoc_add_missing_param_annotation' => true, @@ -115,16 +124,20 @@ return Config::create() 'space_before' => 'none', ], 'self_accessor' => true, + 'set_type_to_cast' => true, 'short_scalar_cast' => true, 'single_blank_line_before_namespace' => true, 'single_quote' => true, 'space_after_semicolon' => true, + 'standardize_increment' => true, 'standardize_not_equals' => true, 'ternary_operator_spaces' => true, 'ternary_to_null_coalescing' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, + 'void_return' => true, 'whitespace_after_comma_in_array' => true, + 'yoda_style' => false, ]) ->setFinder($finder); diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 9a9bb96..328415c 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,13 +1,24 @@ # language: php +build: + dependencies: + before: + - 'composer self-update' + - 'composer update --prefer-stable --prefer-source --no-interaction --no-progress --no-suggest' + cache: + directories: + - vendor/ + nodes: + analysis: + project_setup: + override: true + tests: + override: [php-scrutinizer-run] + filter: paths: [src/*] excluded_paths: [tests/*, vendor/*] -before_commands: - - 'composer self-update' - - 'composer update --prefer-stable --prefer-source --no-interaction --no-scripts --no-progress --no-suggest' - coding_style: php: upper_lower_casing: @@ -17,8 +28,8 @@ coding_style: true_false_null: lower spaces: around_operators: - concatenation: true - negation: false + concatenation: true + negation: false other: after_type_cast: true @@ -34,7 +45,6 @@ tools: enabled: true config: ruleset: 'unusedcode,naming,design,controversial,codesize' - php_cpd: true php_loc: true php_pdepend: true diff --git a/.styleci.yml b/.styleci.yml index d505aef..e643fbb 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -11,6 +11,7 @@ enabled: - blank_line_after_opening_tag - cast_spaces - combine_consecutive_unsets + - compact_nullable_typehint - concat_with_spaces - declare_equal_normalize - declare_strict_types diff --git a/.travis.yml b/.travis.yml index a306b0e..3ba6d2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,17 +13,18 @@ env: - COMPOSER_FLAGS="--prefer-stable --prefer-dist" php: - - 7.1 - 7.2 + - 7.3 + - 7.4 - nightly matrix: fast_finish: true include: - - php: 7 + - php: 7.1 env: - COMPOSER_FLAGS="--prefer-lowest --prefer-stable --prefer-dist" - - php: 7 + - php: 7.1 env: - TEST_VERSION=true - COMPOSER_FLAGS="--prefer-stable --prefer-dist" @@ -36,12 +37,11 @@ before_install: - composer self-update --stable --no-progress install: - - travis_retry composer update $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress + - travis_retry composer update $COMPOSER_FLAGS --no-interaction --no-progress - if [[ $TEST_VERSION ]]; then travis_retry composer require php-coveralls/php-coveralls $COMPOSER_FLAGS --no-interaction --no-scripts --no-progress ; fi script: - if [[ $TEST_VERSION ]]; then composer qa && composer report-phpunit-clover ; fi - - if [[ -z $TEST_VERSION ]]; then composer test-phpunit ; fi after_script: diff --git a/composer.json b/composer.json index 9126426..2b63f19 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": "^7.0", + "php": "^7.1", "ext-json": "*", "ext-simplexml": "*", "ext-libxml": "*", @@ -37,15 +37,18 @@ "brainmaestro/composer-git-hooks": "^2.1", "doctrine/annotations": "^1.4", "friendsofphp/php-cs-fixer": "^2.0", - "infection/infection": "^0.7.0", + "infection/infection": "^0.9", "phpmd/phpmd": "^2.0", - "phpmetrics/phpmetrics": "^2.0", - "phpstan/phpstan": "^0.9", - "phpstan/phpstan-strict-rules": "^0.9", - "phpunit/phpunit": "^5.7|^6.0", - "povils/phpmnd": "^1.1", - "sebastian/phpcpd": "^2.0", - "squizlabs/php_codesniffer": "^2.0", + "phpstan/extension-installer": "^1.0.1", + "phpstan/phpstan": "~0.12", + "phpstan/phpstan-deprecation-rules": "~0.12", + "phpstan/phpstan-strict-rules": "~0.12", + "phpunit/phpunit": "^7.1|^8.0", + "povils/phpmnd": "^2.0", + "roave/security-advisories": "dev-master", + "sebastian/phpcpd": "^4.0", + "squizlabs/php_codesniffer": "^3.0", + "thecodingmachine/phpstan-strict-rules": "~0.12", "symfony/yaml": "^3.1" }, "suggest": { @@ -82,7 +85,6 @@ "qa-phpstan": "phpstan analyse --level max --configuration=phpstan.neon --memory-limit=2G --no-progress src", "test-phpunit": "phpunit", "test-infection": "infection", - "report-phpmetrics": "phpmetrics --report-html=build/metrics --offline .", "report-phpunit-coverage": "phpunit --coverage-html build/coverage", "report-phpunit-clover": "phpunit --coverage-clover build/logs/clover.xml", "lint": [ @@ -99,14 +101,14 @@ "@qa-phpmnd", "@qa-phpstan" ], - "report": [ - "@report-phpmetrics", - "@report-phpunit-coverage" - ], "security": "composer outdated", "test": [ "@test-phpunit", "@test-infection" + ], + "report": [ + "@report-phpunit-coverage", + "@report-phpunit-clover" ] }, "extra": { diff --git a/phpstan.neon b/phpstan.neon index 63331a6..2d83d32 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,10 @@ -includes: - - vendor/phpstan/phpstan-strict-rules/rules.neon - parameters: level: max paths: - src + checkGenericClassInNonGenericObjectType: false ignoreErrors: - - '/^Call to function is_array\(\) will always evaluate to false\.$/' + - message: '/^Call to deprecated method registerLoader\(\) of class Doctrine\\Common\\Annotations\\AnnotationRegistry:\nthis method is deprecated and will be removed in doctrine\/annotations 2\.0\nautoloading should be deferred to the globally registered autoloader by then\. For now,\nuse @example AnnotationRegistry::registerLoader\(.+\)$/' + path: src/Driver/AbstractAnnotationDriver.php + - message: '/^Parameter #1 \$argument of class ReflectionClass constructor expects class-string\|T of object, string given\.$/' + path: src/Driver/AbstractAnnotationDriver.php diff --git a/src/Annotation/AbstractAnnotation.php b/src/Annotation/AbstractAnnotation.php index 95ad2ba..d2f4e2a 100644 --- a/src/Annotation/AbstractAnnotation.php +++ b/src/Annotation/AbstractAnnotation.php @@ -23,7 +23,7 @@ abstract class AbstractAnnotation /** * Abstract annotation constructor. * - * @param mixed[]|\Traversable $parameters + * @param mixed[]|\Traversable|mixed $parameters * * @throws AnnotationException */ @@ -32,6 +32,9 @@ public function __construct($parameters) if (!\is_array($parameters) && !$parameters instanceof \Traversable) { throw new AnnotationException('Parameters must be an iterable'); } + if ($parameters instanceof \Traversable) { + $parameters = \iterator_to_array($parameters); + } $configs = \array_keys(\get_object_vars($this)); @@ -47,6 +50,7 @@ public function __construct($parameters) foreach ($configs as $config) { if (isset($parameters[$config])) { + /** @var callable $callback */ $callback = [$this, 'set' . \ucfirst($config)]; \call_user_func($callback, $parameters[$config]); diff --git a/src/Driver/AbstractAnnotationDriver.php b/src/Driver/AbstractAnnotationDriver.php index 08b4b3e..2a616cb 100644 --- a/src/Driver/AbstractAnnotationDriver.php +++ b/src/Driver/AbstractAnnotationDriver.php @@ -60,6 +60,7 @@ protected function getMappingClasses(): array { AnnotationRegistry::registerLoader('class_exists'); + /** @var class-string[] $mappingClasses */ $mappingClasses = []; foreach ($this->locator->getMappingFiles() as $annotationFile) { @@ -67,7 +68,7 @@ protected function getMappingClasses(): array } return \array_map( - function (string $sourceClass) { + function (string $sourceClass): \ReflectionClass { return new \ReflectionClass($sourceClass); }, \array_filter(\array_unique($mappingClasses)) @@ -86,7 +87,8 @@ function (string $sourceClass) { */ protected function loadClassFromFile(string $annotationFile): string { - $tokens = \token_get_all(\file_get_contents($annotationFile)); + $content = \file_get_contents($annotationFile); + $tokens = \token_get_all($content !== false ? $content : ''); $hasClass = false; $class = null; $hasNamespace = false; @@ -99,32 +101,32 @@ protected function loadClassFromFile(string $annotationFile): string continue; } - if ($hasClass && $token[0] === T_STRING) { + if ($hasClass && $token[0] === \T_STRING) { $class = $namespace . '\\' . $token[1]; break; } - if ($hasNamespace && $token[0] === T_STRING) { + if ($hasNamespace && $token[0] === \T_STRING) { $namespace = ''; do { $namespace .= $token[1]; $token = $tokens[++$i]; - } while ($i < $length && \is_array($token) && \in_array($token[0], [T_NS_SEPARATOR, T_STRING], true)); + } while ($i < $length && \is_array($token) && \in_array($token[0], [\T_NS_SEPARATOR, \T_STRING], true)); $hasNamespace = false; } - if ($token[0] === T_CLASS) { + if ($token[0] === \T_CLASS) { $hasClass = true; } - if ($token[0] === T_NAMESPACE) { + if ($token[0] === \T_NAMESPACE) { $hasNamespace = true; } } - return $class ?: ''; + return $class ?? ''; } } diff --git a/src/Driver/AbstractDriverFactory.php b/src/Driver/AbstractDriverFactory.php index 54f02b0..5df4992 100644 --- a/src/Driver/AbstractDriverFactory.php +++ b/src/Driver/AbstractDriverFactory.php @@ -23,7 +23,7 @@ abstract class AbstractDriverFactory implements DriverFactoryInterface /** * Get mapping driver. * - * @param array $mappingSource + * @param mixed[] $mappingSource * * @throws DriverException * @@ -58,8 +58,8 @@ public function getDriver(array $mappingSource): DriverInterface /** * Get mapping driver implementation. * - * @param string $type - * @param array $paths + * @param string $type + * @param string[] $paths * * @throws DriverException * @@ -92,7 +92,7 @@ protected function getDriverImplementation(string $type, array $paths): DriverIn /** * Get annotation based mapping driver. * - * @param array $paths + * @param string[] $paths * * @throws DriverException * @@ -108,7 +108,7 @@ protected function getAnnotationDriver(array $paths): DriverInterface /** * Get native PHP file based mapping driver. * - * @param array $paths + * @param string[] $paths * * @throws DriverException * @@ -124,7 +124,7 @@ protected function getPhpDriver(array $paths): DriverInterface /** * Get XML file based mapping driver. * - * @param array $paths + * @param string[] $paths * * @throws DriverException * @@ -140,7 +140,7 @@ protected function getXmlDriver(array $paths): DriverInterface /** * Get JSON file based mapping driver. * - * @param array $paths + * @param string[] $paths * * @throws DriverException * @@ -156,7 +156,7 @@ protected function getJsonDriver(array $paths): DriverInterface /** * Get YAML file based mapping driver. * - * @param array $paths + * @param string[] $paths * * @throws DriverException * diff --git a/src/Driver/AbstractMappingDriver.php b/src/Driver/AbstractMappingDriver.php index 5150b78..b3e2f2c 100644 --- a/src/Driver/AbstractMappingDriver.php +++ b/src/Driver/AbstractMappingDriver.php @@ -46,17 +46,17 @@ protected function getMappingData(): array * * @param string $mappingFile * - * @return array + * @return mixed[] */ abstract protected function loadMappingFile(string $mappingFile): array; /** * Merge mapping data. * - * @param array $mappingsA - * @param array $mappingsB + * @param mixed[] $mappingsA + * @param mixed[] $mappingsB * - * @return array + * @return mixed[] */ final protected function mergeMappings(array $mappingsA, array $mappingsB): array { diff --git a/src/Driver/DriverFactoryInterface.php b/src/Driver/DriverFactoryInterface.php index 267c1bb..aaeb3af 100644 --- a/src/Driver/DriverFactoryInterface.php +++ b/src/Driver/DriverFactoryInterface.php @@ -31,7 +31,7 @@ interface DriverFactoryInterface /** * Get mapping driver. * - * @param array $mappingSource + * @param string[] $mappingSource * * @return DriverInterface */ diff --git a/src/Driver/Locator/FileLocator.php b/src/Driver/Locator/FileLocator.php index 6e2c2af..3f70f0b 100644 --- a/src/Driver/Locator/FileLocator.php +++ b/src/Driver/Locator/FileLocator.php @@ -70,6 +70,8 @@ public function getExtensions(): array * Get mapping files. * * @throws DriverException + * + * @return string[] */ public function getMappingFiles(): array { @@ -93,7 +95,7 @@ public function getMappingFiles(): array * * @param string $mappingDirectory * - * @return array + * @return string[] */ protected function getFilesFromDirectory(string $mappingDirectory): array { diff --git a/src/Driver/Traits/PhpMappingTrait.php b/src/Driver/Traits/PhpMappingTrait.php index 6de58f2..51ec760 100644 --- a/src/Driver/Traits/PhpMappingTrait.php +++ b/src/Driver/Traits/PhpMappingTrait.php @@ -33,7 +33,7 @@ protected function getExtensions(): array * * @param string $mappingFile * - * @return array + * @return mixed[] */ protected function loadMappingFile(string $mappingFile): array { diff --git a/src/Metadata/MetadataResolver.php b/src/Metadata/MetadataResolver.php index f280659..decc547 100644 --- a/src/Metadata/MetadataResolver.php +++ b/src/Metadata/MetadataResolver.php @@ -65,7 +65,7 @@ public function getMetadata(array $mappingSources): array } $metadata = \array_map( - function (array $mappingSource) { + function (array $mappingSource): array { return $this->driverFactory->getDriver($mappingSource)->getMetadata(); }, $mappingSources @@ -82,7 +82,7 @@ function (array $mappingSource) { /** * Get cache key. * - * @param array $mappingSources + * @param mixed[] $mappingSources * * @return string */ diff --git a/tests/Mapping/Annotation/AbstractAnnotationTest.php b/tests/Mapping/Annotation/AbstractAnnotationTest.php index a430491..b05b3ad 100644 --- a/tests/Mapping/Annotation/AbstractAnnotationTest.php +++ b/tests/Mapping/Annotation/AbstractAnnotationTest.php @@ -13,6 +13,7 @@ namespace Jgut\Mapping\Tests\Annotation; +use Jgut\Mapping\Exception\AnnotationException; use Jgut\Mapping\Tests\Stubs\AnnotationStub; use PHPUnit\Framework\TestCase; @@ -21,25 +22,23 @@ */ class AbstractAnnotationTest extends TestCase { - /** - * @expectedException \Jgut\Mapping\Exception\AnnotationException - * @expectedExceptionMessage Parameters must be an iterable - */ - public function testInvalidParameters() + public function testInvalidParameters(): void { + $this->expectException(AnnotationException::class); + $this->expectExceptionMessage('Parameters must be an iterable'); + new AnnotationStub('invalid'); } - /** - * @expectedException \Jgut\Mapping\Exception\AnnotationException - * @expectedExceptionMessage The following annotation parameters are not recognized: unknown - */ - public function testUnknownParameter() + public function testUnknownParameter(): void { + $this->expectException(AnnotationException::class); + $this->expectExceptionMessage('The following annotation parameters are not recognized: unknown'); + new AnnotationStub(['unknown' => '']); } - public function testParameters() + public function testParameters(): void { $annotation = new AnnotationStub(['known' => 'Text']); diff --git a/tests/Mapping/Driver/AbstractAnnotationDriverTest.php b/tests/Mapping/Driver/AbstractAnnotationDriverTest.php index 4b69ce0..0161cdb 100644 --- a/tests/Mapping/Driver/AbstractAnnotationDriverTest.php +++ b/tests/Mapping/Driver/AbstractAnnotationDriverTest.php @@ -24,7 +24,7 @@ */ class AbstractAnnotationDriverTest extends TestCase { - public function testMappings() + public function testMappings(): void { $annotationReader = $this->getMockBuilder(AnnotationReader::class) ->disableOriginalConstructor() diff --git a/tests/Mapping/Driver/AbstractDriverFactoryTest.php b/tests/Mapping/Driver/AbstractDriverFactoryTest.php index b3a3655..6613c9d 100644 --- a/tests/Mapping/Driver/AbstractDriverFactoryTest.php +++ b/tests/Mapping/Driver/AbstractDriverFactoryTest.php @@ -16,6 +16,7 @@ use Jgut\Mapping\Driver\AbstractAnnotationDriver; use Jgut\Mapping\Driver\AbstractMappingDriver; use Jgut\Mapping\Driver\DriverFactoryInterface; +use Jgut\Mapping\Exception\DriverException; use Jgut\Mapping\Tests\Stubs\AbstractDriverFactoryStub; use Jgut\Mapping\Tests\Stubs\AbstractMappingDriverStub; use Jgut\Mapping\Tests\Stubs\EmptyDriverFactoryStub; @@ -34,91 +35,83 @@ class AbstractDriverFactoryTest extends TestCase /** * {@inheritdoc} */ - public function setUp() + protected function setUp(): void { $this->factory = new AbstractDriverFactoryStub(); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessage Annotation metadata mapping driver is not supported - */ - public function testAnnotationDriverNotImplemented() + public function testAnnotationDriverNotImplemented(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessage('Annotation metadata mapping driver is not supported'); + (new EmptyDriverFactoryStub())->getDriver(['type' => DriverFactoryInterface::DRIVER_ANNOTATION, 'path' => []]); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessage PHP metadata mapping driver is not supported - */ - public function testPhpDriverNotImplemented() + public function testPhpDriverNotImplemented(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessage('PHP metadata mapping driver is not supported'); + (new EmptyDriverFactoryStub())->getDriver(['type' => DriverFactoryInterface::DRIVER_PHP, 'path' => []]); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessage XML metadata mapping driver is not supported - */ - public function testXmlDriverNotImplemented() + public function testXmlDriverNotImplemented(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessage('XML metadata mapping driver is not supported'); + (new EmptyDriverFactoryStub())->getDriver(['type' => DriverFactoryInterface::DRIVER_XML, 'path' => []]); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessage JSON metadata mapping driver is not supported - */ - public function testJsonDriverNotImplemented() + public function testJsonDriverNotImplemented(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessage('JSON metadata mapping driver is not supported'); + (new EmptyDriverFactoryStub())->getDriver(['type' => DriverFactoryInterface::DRIVER_JSON, 'path' => []]); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessage YAML metadata mapping driver is not supported - */ - public function testYamlDriverNotImplemented() + public function testYamlDriverNotImplemented(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessage('YAML metadata mapping driver is not supported'); + (new EmptyDriverFactoryStub())->getDriver(['type' => DriverFactoryInterface::DRIVER_YAML, 'path' => []]); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessage Mapping must be array with "driver" key or "type" and "path" keys - */ - public function testInvalidData() + public function testInvalidData(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessage('Mapping must be array with "driver" key or "type" and "path" keys'); + $this->factory->getDriver([]); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessage "unknown" is not a valid metadata mapping driver - */ - public function testInvalidType() + public function testInvalidType(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessage('"unknown" is not a valid metadata mapping driver'); + $this->factory->getDriver(['type' => 'unknown', 'path' => []]); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessageRegExp /^Metadata mapping driver should be of the type .+, string given/ - */ - public function testInvalidDriver() + public function testInvalidDriver(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessageRegExp('/^Metadata mapping driver should be of the type .+, string given/'); + $this->factory->getDriver(['driver' => 'invalid']); } - public function testDriver() + public function testDriver(): void { $driver = new AbstractMappingDriverStub([]); self::assertEquals($driver, $this->factory->getDriver(['driver' => $driver])); } - public function testAnnotationDriver() + public function testAnnotationDriver(): void { self::assertInstanceOf( AbstractAnnotationDriver::class, @@ -126,7 +119,7 @@ public function testAnnotationDriver() ); } - public function testPhpDriver() + public function testPhpDriver(): void { self::assertInstanceOf( AbstractMappingDriver::class, @@ -134,7 +127,7 @@ public function testPhpDriver() ); } - public function testJsonDriver() + public function testJsonDriver(): void { self::assertInstanceOf( AbstractMappingDriver::class, @@ -142,7 +135,7 @@ public function testJsonDriver() ); } - public function testXmlDriver() + public function testXmlDriver(): void { self::assertInstanceOf( AbstractMappingDriver::class, @@ -150,7 +143,7 @@ public function testXmlDriver() ); } - public function testYamlDriver() + public function testYamlDriver(): void { self::assertInstanceOf( AbstractMappingDriver::class, diff --git a/tests/Mapping/Driver/AbstractDriverTest.php b/tests/Mapping/Driver/AbstractDriverTest.php index 60549b4..d8e3b4a 100644 --- a/tests/Mapping/Driver/AbstractDriverTest.php +++ b/tests/Mapping/Driver/AbstractDriverTest.php @@ -22,7 +22,7 @@ */ class AbstractDriverTest extends TestCase { - public function testLocator() + public function testLocator(): void { self::assertInstanceOf(FileLocator::class, (new AbstractDriverStub([]))->getLocator()); } diff --git a/tests/Mapping/Driver/AbstractMappingDriverTest.php b/tests/Mapping/Driver/AbstractMappingDriverTest.php index 5b60744..4f4fbd9 100644 --- a/tests/Mapping/Driver/AbstractMappingDriverTest.php +++ b/tests/Mapping/Driver/AbstractMappingDriverTest.php @@ -21,7 +21,7 @@ */ class AbstractMappingDriverTest extends TestCase { - public function testMappings() + public function testMappings(): void { $driver = new AbstractMappingDriverStub([\dirname(__DIR__) . '/Files/files/valid']); diff --git a/tests/Mapping/Driver/Locator/FileLocatorTest.php b/tests/Mapping/Driver/Locator/FileLocatorTest.php index 974b1b1..feaf592 100644 --- a/tests/Mapping/Driver/Locator/FileLocatorTest.php +++ b/tests/Mapping/Driver/Locator/FileLocatorTest.php @@ -21,16 +21,15 @@ */ class FileLocatorTest extends TestCase { - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage Path "non/existing/path" does not exist - */ - public function testInvalidPath() + public function testInvalidPath(): void { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Path "non/existing/path" does not exist'); + (new FileLocator(['non/existing/path'], ['php']))->getMappingFiles(); } - public function testValidPath() + public function testValidPath(): void { $paths = [\dirname(__DIR__, 2) . '/Files/Classes', \dirname(__DIR__, 2) . '/Stubs/AnnotationStub.php']; $extensions = ['php']; diff --git a/tests/Mapping/Driver/Traits/JsonMappingTraitTest.php b/tests/Mapping/Driver/Traits/JsonMappingTraitTest.php index 00c965e..eb13813 100644 --- a/tests/Mapping/Driver/Traits/JsonMappingTraitTest.php +++ b/tests/Mapping/Driver/Traits/JsonMappingTraitTest.php @@ -13,6 +13,7 @@ namespace Jgut\Mapping\Tests\Driver\Traits; +use Jgut\Mapping\Exception\DriverException; use Jgut\Mapping\Tests\Stubs\JsonMappingDriverStub; use PHPUnit\Framework\TestCase; @@ -29,26 +30,25 @@ class JsonMappingTraitTest extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->mapping = new JsonMappingDriverStub(); } - public function testExtensions() + public function testExtensions(): void { self::assertEquals(['json'], $this->mapping->getExtensions()); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessageRegExp /JSON mapping file .+ parsing error: Syntax error/ - */ - public function testLoadError() + public function testLoadError(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessageRegExp('/JSON mapping file .+ parsing error: Syntax error/'); + $this->mapping->loadMappingFile(\dirname(__DIR__, 2) . '/Files/files/invalid/invalid.json'); } - public function testLoad() + public function testLoad(): void { self::assertEquals( [ diff --git a/tests/Mapping/Driver/Traits/PhpMappingTraitTest.php b/tests/Mapping/Driver/Traits/PhpMappingTraitTest.php index 3419781..cc629c0 100644 --- a/tests/Mapping/Driver/Traits/PhpMappingTraitTest.php +++ b/tests/Mapping/Driver/Traits/PhpMappingTraitTest.php @@ -29,17 +29,17 @@ class PhpMappingTraitTest extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->mapping = new PhpMappingDriverStub(); } - public function testExtensions() + public function testExtensions(): void { self::assertEquals(['php'], $this->mapping->getExtensions()); } - public function testLoad() + public function testLoad(): void { self::assertEquals( [ diff --git a/tests/Mapping/Driver/Traits/XmlMappingTraitTest.php b/tests/Mapping/Driver/Traits/XmlMappingTraitTest.php index 5d407c0..b165215 100644 --- a/tests/Mapping/Driver/Traits/XmlMappingTraitTest.php +++ b/tests/Mapping/Driver/Traits/XmlMappingTraitTest.php @@ -13,6 +13,7 @@ namespace Jgut\Mapping\Tests\Driver\Traits; +use Jgut\Mapping\Exception\DriverException; use Jgut\Mapping\Tests\Stubs\XmlMappingDriverStub; use PHPUnit\Framework\TestCase; @@ -29,26 +30,25 @@ class XmlMappingTraitTest extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->mapping = new XmlMappingDriverStub(); } - public function testExtensions() + public function testExtensions(): void { self::assertEquals(['xml'], $this->mapping->getExtensions()); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessageRegExp /XML mapping file .+ parsing error: ""/ - */ - public function testLoadError() + public function testLoadError(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessageRegExp('/XML mapping file .+ parsing error: ""/'); + $this->mapping->loadMappingFile(\dirname(__DIR__, 2) . '/Files/files/invalid/invalid.xml'); } - public function testLoad() + public function testLoad(): void { self::assertEquals( [ diff --git a/tests/Mapping/Driver/Traits/YamlMappingTraitTest.php b/tests/Mapping/Driver/Traits/YamlMappingTraitTest.php index 7d84f03..296f953 100644 --- a/tests/Mapping/Driver/Traits/YamlMappingTraitTest.php +++ b/tests/Mapping/Driver/Traits/YamlMappingTraitTest.php @@ -13,6 +13,7 @@ namespace Jgut\Mapping\Tests\Driver\Traits; +use Jgut\Mapping\Exception\DriverException; use Jgut\Mapping\Tests\Stubs\YamlMappingDriverStub; use PHPUnit\Framework\TestCase; @@ -29,26 +30,27 @@ class YamlMappingTraitTest extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { $this->mapping = new YamlMappingDriverStub(); } - public function testExtensions() + public function testExtensions(): void { self::assertEquals(['yml', 'yaml'], $this->mapping->getExtensions()); } - /** - * @expectedException \Jgut\Mapping\Exception\DriverException - * @expectedExceptionMessageRegExp /YAML mapping file .+ parsing error: A colon cannot be used in an unquoted .+/ - */ - public function testLoadError() + public function testLoadError(): void { + $this->expectException(DriverException::class); + $this->expectExceptionMessageRegExp( + '/YAML mapping file .+ parsing error: A colon cannot be used in an unquoted .+/' + ); + $this->mapping->loadMappingFile(\dirname(__DIR__, 2) . '/Files/files/invalid/invalid.yml'); } - public function testLoad() + public function testLoad(): void { self::assertEquals( [ diff --git a/tests/Mapping/Metadata/MetadataResolverTest.php b/tests/Mapping/Metadata/MetadataResolverTest.php index a746cd7..1152b21 100644 --- a/tests/Mapping/Metadata/MetadataResolverTest.php +++ b/tests/Mapping/Metadata/MetadataResolverTest.php @@ -25,7 +25,7 @@ */ class MetadataResolverTest extends TestCase { - public function testResolver() + public function testResolver(): void { $factory = $this->getMockBuilder(DriverFactoryInterface::class) ->getMock(); @@ -55,7 +55,7 @@ public function testResolver() self::assertInstanceOf(MetadataStub::class, $metadata[1]); } - public function testCachedResolver() + public function testCachedResolver(): void { $factory = $this->getMockBuilder(DriverFactoryInterface::class) ->getMock(); diff --git a/tests/Mapping/Stubs/AnnotationStub.php b/tests/Mapping/Stubs/AnnotationStub.php index c25bd1a..154815f 100644 --- a/tests/Mapping/Stubs/AnnotationStub.php +++ b/tests/Mapping/Stubs/AnnotationStub.php @@ -36,7 +36,7 @@ public function getKnown(): string /** * @param string $known */ - public function setKnown(string $known) + public function setKnown(string $known): void { $this->known = $known; }