From b4dff4104809e0c8eb629b0d3e98319532329609 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 11 Aug 2020 12:20:56 +0100 Subject: [PATCH 1/3] Release 1.3.3 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 594387eaa..4a59333e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 1.3.3 (2020-08-11) +* Fix array to string conversion in ConstantsPass (#1086) +* Fixed nullable PHP 8.0 union types (#1088) +* Fixed support for PHP 8.0 parent type (#1088) +* Fixed PHP 8.0 mixed type support (#1088) +* Fixed PHP 8.0 union return types (#1088) + ## 1.3.2 (2020-07-09) * Fix mocking with anonymous classes (#1039) * Fix andAnyOthers() to properly match earlier expectations (#1051) From 289474ab896b6d797395cc7d2001b616ddec2e37 Mon Sep 17 00:00:00 2001 From: Thomas Gerbet Date: Tue, 8 Dec 2020 10:32:52 +0100 Subject: [PATCH 2/3] Stop testing with '--prefer-lowest' This solve issues with PHPUnit and Xdebug 3.0 for PHP 7.3 and 7.4. mockery has basically no dependencies so the part of the matrix testing with '--prefer-lowest' brings little/no value. --- .travis.yml | 48 +++--------------------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index 18bdb88de..361e19e6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,49 +3,12 @@ language: php matrix: include: - php: 5.6 - env: - - DEPS=lowest - - php: 5.6 - env: - - DEPS=latest - - php: 7.0 - env: - - DEPS=lowest - php: 7.0 - env: - - DEPS=latest - php: 7.1 - env: - - DEPS=lowest - - php: 7.1 - env: - - DEPS=latest - - php: 7.2 - env: - - DEPS=lowest - php: 7.2 - env: - - DEPS=latest - php: 7.3 - env: - - DEPS=lowest - - php: 7.3 - env: - - DEPS=latest - - php: 7.4 - env: - - DEPS=lowest - php: 7.4 - env: - - DEPS=latest - - php: nightly - env: - - DEPS=lowest - - COMPOSER_FLAGS="--ignore-platform-reqs" - - php: nightly - env: - - DEPS=latest - - COMPOSER_FLAGS="--ignore-platform-reqs" + - php: 8.0 before_install: # Install extensions for PHP 5.x series. 7.x includes them by default. @@ -57,19 +20,15 @@ before_install: extension=redis.so ' >> ~/.phpenv/versions/"$(phpenv version-name)"/etc/conf.d/travis.ini fi - if [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then - composer require --dev --no-update "phpunit/phpunit:^9.3.2" - fi install: - - if [[ $DEPS == 'latest' ]]; then travis_retry composer update --no-interaction $COMPOSER_FLAGS ; fi - - if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable --no-interaction $COMPOSER_FLAGS ; fi + - travis_retry composer update --no-interaction script: - | if [[ $TRAVIS_PHP_VERSION == 5.6 ]]; then ./vendor/bin/phpunit --coverage-text --coverage-clover="build/logs/clover.xml" --testsuite="Mockery Test Suite PHP5"; - elif [[ $TRAVIS_PHP_VERSION == 'nightly' ]]; then + elif [[ $TRAVIS_PHP_VERSION == '8.0' ]]; then ./vendor/bin/phpunit --coverage-text --coverage-clover="build/logs/clover.xml" --testsuite="Mockery Test Suite PHP8"; else ./vendor/bin/phpunit --coverage-text --coverage-clover="build/logs/clover.xml" --testsuite="Mockery Test Suite PHP7"; @@ -99,4 +58,3 @@ deploy: on: branch: master php: '7.1' - condition: $DEPS = latest From 849a681ba4b71508ac7b0bc76a7249dd31887301 Mon Sep 17 00:00:00 2001 From: Thomas Gerbet Date: Tue, 1 Dec 2020 19:46:16 +0100 Subject: [PATCH 3/3] Fix crash on a union type including null This change prevents the generation of type hints with 2 "null". For example, "string|array|null" should generate the code "string|array|null" instead of "string|array|null|null" to avoid a PHP fatal error "Duplicate type null is redundant". Closes #1105. --- library/Mockery/Reflector.php | 8 +++++--- tests/PHP80/Php80LanguageFeaturesTest.php | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/library/Mockery/Reflector.php b/library/Mockery/Reflector.php index 524d20cd2..bb145de93 100644 --- a/library/Mockery/Reflector.php +++ b/library/Mockery/Reflector.php @@ -192,9 +192,11 @@ private static function typeToString(\ReflectionType $type, \ReflectionClass $de { // PHP 8 union types can be recursively processed if ($type instanceof \ReflectionUnionType) { - return \implode('|', \array_map(function (\ReflectionType $type) use ($declaringClass) { - return self::typeToString($type, $declaringClass); - }, $type->getTypes())); + return \implode('|', \array_filter(\array_map(function (\ReflectionType $type) use ($declaringClass) { + $typeHint = self::typeToString($type, $declaringClass); + + return $typeHint === 'null' ? null : $typeHint; + }, $type->getTypes()))); } // PHP 7.0 doesn't have named types, but 7.1+ does diff --git a/tests/PHP80/Php80LanguageFeaturesTest.php b/tests/PHP80/Php80LanguageFeaturesTest.php index fbecee555..11ffa232e 100644 --- a/tests/PHP80/Php80LanguageFeaturesTest.php +++ b/tests/PHP80/Php80LanguageFeaturesTest.php @@ -29,6 +29,15 @@ public function it_can_mock_a_class_with_a_union_argument_type_hint() $mock->foo($object); } + /** @test */ + public function it_can_mock_a_class_with_a_union_argument_type_hint_including_null() + { + $mock = mock(ArgumentUnionTypeHintWithNull::class); + $mock->allows()->foo(null); + + $mock->foo(null); + } + /** @test */ public function it_can_mock_a_class_with_a_parent_argument_type_hint() { @@ -78,6 +87,13 @@ public function foo(string|array|self $foo) } } +class ArgumentUnionTypeHintWithNull +{ + public function foo(string|array|null $foo) + { + } +} + class ArgumentParentTypeHint extends \stdClass { public function foo(parent $foo)