From fac5ba392b744d86876fbc0114f316a3dd68fa64 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Sun, 16 Jul 2023 12:25:35 -0500 Subject: [PATCH 1/5] Update phpunit.xml.dist Signed-off-by: Nathanael Esayeas --- phpunit.xml.dist | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0aae4f831..5576d1e91 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -33,18 +33,25 @@ ./tests/PHP80 ./tests/PHP81 ./tests/PHP82 + ./tests/PHP83 ./tests ./tests/PHP81 ./tests/PHP82 + ./tests/PHP83 ./tests ./tests/PHP82 + ./tests/PHP83 ./tests + ./tests/PHP83 + + + ./tests From 090fcc953fab7cba6c1f99023622aba959c8a920 Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Sun, 16 Jul 2023 12:26:04 -0500 Subject: [PATCH 2/5] Supports typed class constants Signed-off-by: Nathanael Esayeas --- tests/PHP83/Php83LanguageFeaturesTest.php | 72 +++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/PHP83/Php83LanguageFeaturesTest.php diff --git a/tests/PHP83/Php83LanguageFeaturesTest.php b/tests/PHP83/Php83LanguageFeaturesTest.php new file mode 100644 index 000000000..98a47f411 --- /dev/null +++ b/tests/PHP83/Php83LanguageFeaturesTest.php @@ -0,0 +1,72 @@ +expectException(Exception::class); + + mock(Enums::class); + } + + public function testCanMockClassTypedClassConstants(): void + { + $mock = mock(Classes::class); + + self::assertInstanceOf(Classes::class, $mock); + self::assertSame(Enums::FOO, $mock::BAR); + } + + public function testCanMockInterfaceTypedClassConstants(): void + { + $mock = mock(Interfaces::class); + + self::assertInstanceOf(Interfaces::class, $mock); + self::assertSame(Enums::FOO, $mock::BAR); + } + + public function testCanMockTraitTypedClassConstants(): void + { + $mock = mock(Traits::class); + + self::assertSame(Enums::FOO, $mock->foo()); + self::assertSame(Enums::FOO, $mock::BAR); + } +} + +enum Enums { + const string FOO = "bar"; +} + +class Classes implements Interfaces { + use Traits; +} + +interface Interfaces { + const string BAR = Enums::FOO; + + public function foo(): string; +} + +trait Traits { + const string BAR = Enums::FOO; + + public function foo(): string + { + return Interfaces::BAR; + } +} From beb371da2b7d005a9b09f9d89e95def5fa8cdf7b Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Sun, 16 Jul 2023 12:26:29 -0500 Subject: [PATCH 3/5] Supports dynamic class constant fetch Signed-off-by: Nathanael Esayeas --- tests/PHP83/Php83LanguageFeaturesTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/PHP83/Php83LanguageFeaturesTest.php b/tests/PHP83/Php83LanguageFeaturesTest.php index 98a47f411..f5420cdd4 100644 --- a/tests/PHP83/Php83LanguageFeaturesTest.php +++ b/tests/PHP83/Php83LanguageFeaturesTest.php @@ -46,6 +46,18 @@ public function testCanMockTraitTypedClassConstants(): void self::assertSame(Enums::FOO, $mock->foo()); self::assertSame(Enums::FOO, $mock::BAR); } + + public function testCanMockWithDynamicClassConstantFetch(): void + { + $mock = mock(ClassName::class); + + $constant = 'CONSTANT'; + + self::assertSame(ClassName::CONSTANT, $mock::CONSTANT); + self::assertSame(ClassName::CONSTANT, $mock::{$constant}); + self::assertSame(ClassName::{$constant}, $mock::CONSTANT); + self::assertSame(ClassName::{$constant}, $mock::{$constant}); + } } enum Enums { @@ -70,3 +82,7 @@ public function foo(): string return Interfaces::BAR; } } + +class ClassName { + public const CONSTANT = 42; +} From a3402a6ec710c922751ae0e75876f347ee08bebb Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Wed, 19 Jul 2023 13:42:35 -0500 Subject: [PATCH 4/5] Calling `get_parent_class()` without arguments is deprecated Signed-off-by: Nathanael Esayeas --- tests/Mockery/RegExpCompatability.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Mockery/RegExpCompatability.php b/tests/Mockery/RegExpCompatability.php index 6b19f8f5d..dc7b035d5 100644 --- a/tests/Mockery/RegExpCompatability.php +++ b/tests/Mockery/RegExpCompatability.php @@ -6,7 +6,7 @@ trait RegExpCompatability { public function expectExceptionMessageRegEx($regularExpression) { - if (method_exists(get_parent_class(), 'expectExceptionMessageRegExp')) { + if (method_exists(get_parent_class($this), 'expectExceptionMessageRegExp')) { return parent::expectExceptionMessageRegExp($regularExpression); } @@ -15,7 +15,7 @@ public function expectExceptionMessageRegEx($regularExpression) public static function assertMatchesRegEx($pattern, $string, $message = '') { - if (method_exists(get_parent_class(), 'assertMatchesRegularExpression')) { + if (method_exists(get_parent_class(static::class), 'assertMatchesRegularExpression')) { return parent::assertMatchesRegularExpression($pattern, $string, $message); } From 03da3ddbd9160192d6a36561d11379364a8107ce Mon Sep 17 00:00:00 2001 From: Nathanael Esayeas Date: Mon, 24 Jul 2023 11:33:57 -0500 Subject: [PATCH 5/5] Test PHP 8.3 language features Signed-off-by: Nathanael Esayeas --- composer.json | 1 + composer.lock | 12 ++--- phpunit.xml.dist | 10 ++-- tests/Fixture/PHP83/ClassName.php | 7 +++ tests/Fixture/PHP83/Classes.php | 7 +++ tests/Fixture/PHP83/Enums.php | 7 +++ tests/Fixture/PHP83/Interfaces.php | 9 ++++ tests/Fixture/PHP83/Traits.php | 12 +++++ .../PHP83/Php83LanguageFeaturesTest.php | 49 +++++-------------- 9 files changed, 68 insertions(+), 46 deletions(-) create mode 100644 tests/Fixture/PHP83/ClassName.php create mode 100644 tests/Fixture/PHP83/Classes.php create mode 100644 tests/Fixture/PHP83/Enums.php create mode 100644 tests/Fixture/PHP83/Interfaces.php create mode 100644 tests/Fixture/PHP83/Traits.php rename tests/{ => Unit}/PHP83/Php83LanguageFeaturesTest.php (78%) diff --git a/composer.json b/composer.json index 66b95720c..7ef873d08 100644 --- a/composer.json +++ b/composer.json @@ -69,6 +69,7 @@ "autoload-dev": { "psr-4": { "Fixture\\": "tests/Fixture/", + "Mockery\\Tests\\Unit\\": "tests/Unit", "test\\": "tests/" }, "files": [ diff --git a/composer.lock b/composer.lock index 69d4e6cc6..582e84eda 100644 --- a/composer.lock +++ b/composer.lock @@ -1279,16 +1279,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.22.1", + "version": "1.23.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0" + "reference": "a2b24135c35852b348894320d47b3902a94bc494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/65c39594fbd8c67abfc68bb323f86447bab79cc0", - "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/a2b24135c35852b348894320d47b3902a94bc494", + "reference": "a2b24135c35852b348894320d47b3902a94bc494", "shasum": "" }, "require": { @@ -1320,9 +1320,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.0" }, - "time": "2023-06-29T20:46:06+00:00" + "time": "2023-07-23T22:17:56+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5576d1e91..67e3a1668 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -33,22 +33,24 @@ ./tests/PHP80 ./tests/PHP81 ./tests/PHP82 - ./tests/PHP83 + ./tests/Unit/PHP81 + ./tests/Unit/PHP83 ./tests ./tests/PHP81 ./tests/PHP82 - ./tests/PHP83 + ./tests/Unit/PHP81 + ./tests/Unit/PHP83 ./tests ./tests/PHP82 - ./tests/PHP83 + ./tests/Unit/PHP83 ./tests - ./tests/PHP83 + ./tests/Unit/PHP83 ./tests diff --git a/tests/Fixture/PHP83/ClassName.php b/tests/Fixture/PHP83/ClassName.php new file mode 100644 index 000000000..adc7c97db --- /dev/null +++ b/tests/Fixture/PHP83/ClassName.php @@ -0,0 +1,7 @@ +expectException(Exception::class); - - mock(Enums::class); - } - public function testCanMockClassTypedClassConstants(): void { $mock = mock(Classes::class); @@ -58,31 +52,14 @@ public function testCanMockWithDynamicClassConstantFetch(): void self::assertSame(ClassName::{$constant}, $mock::CONSTANT); self::assertSame(ClassName::{$constant}, $mock::{$constant}); } -} - -enum Enums { - const string FOO = "bar"; -} - -class Classes implements Interfaces { - use Traits; -} - -interface Interfaces { - const string BAR = Enums::FOO; - - public function foo(): string; -} -trait Traits { - const string BAR = Enums::FOO; - - public function foo(): string + /** + * Enumerations ( enum ) are final classes and therefore cannot be mocked. + */ + public function testCanNotMockEnumsFinalClasses(): void { - return Interfaces::BAR; - } -} + $this->expectException(Exception::class); -class ClassName { - public const CONSTANT = 42; + mock(Enums::class); + } }