From 59adc573446dbd8ece3ed8264b9ff634711b899e Mon Sep 17 00:00:00 2001 From: bigint Date: Wed, 23 Jun 2021 14:55:09 +0530 Subject: [PATCH 1/5] Update phpunit/phpunit to 9.5.6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c837f98d..2224ac7f 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^7.3 || ^8.0", "nunomaduro/collision": "^5.4.0", "pestphp/pest-plugin": "^1.0.0", - "phpunit/phpunit": ">= 9.3.7 <= 9.5.5" + "phpunit/phpunit": ">= 9.3.7 <= 9.5.6" }, "autoload": { "psr-4": { From ff527baa1d00fa9857985553c480143e0ba42143 Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 24 Jun 2021 21:31:12 +0100 Subject: [PATCH 2/5] Allows `and` in Higher Order Expectations. --- src/HigherOrderExpectation.php | 10 ++++++++++ .../Expect/HigherOrder/methodsAndProperties.php | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/HigherOrderExpectation.php b/src/HigherOrderExpectation.php index 6e2ed23f..4cb6fc49 100644 --- a/src/HigherOrderExpectation.php +++ b/src/HigherOrderExpectation.php @@ -63,6 +63,16 @@ final class HigherOrderExpectation return $this; } + /** + * Creates a new expectation. + * + * @param mixed $value + */ + public function and($value): HigherOrderExpectation + { + return new self($this->expect($value), $value); + } + /** * Dynamically calls methods on the class with the given arguments. * diff --git a/tests/Features/Expect/HigherOrder/methodsAndProperties.php b/tests/Features/Expect/HigherOrder/methodsAndProperties.php index f75f698a..08c4a3bc 100644 --- a/tests/Features/Expect/HigherOrder/methodsAndProperties.php +++ b/tests/Features/Expect/HigherOrder/methodsAndProperties.php @@ -22,6 +22,17 @@ it('can handle nested methods and properties', function () { ->newInstance()->books()->toBeArray(); }); +it('can start a new higher order expectation using the and syntax', function () { + expect(new HasMethodsAndProperties()) + ->toBeInstanceOf(HasMethodsAndProperties::class) + ->meta->toBeArray + ->and(['foo' => 'bar']) + ->toBeArray() + ->foo->toEqual('bar'); + + expect(static::getCount())->toEqual(4); +}); + class HasMethodsAndProperties { public $name = 'Has Methods and Properties'; From 3c2c767e0983aaf3689b1fa46a65b10e2fc3e407 Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 24 Jun 2021 21:35:16 +0100 Subject: [PATCH 3/5] Updates snapshot --- tests/.snapshots/success.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index e7ecc1a0..9b0a5c44 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -116,6 +116,7 @@ PASS Tests\Features\Expect\HigherOrder\methodsAndProperties ✓ it can access methods and properties ✓ it can handle nested methods and properties + ✓ it can start a new higher order expectation using the and syntax PASS Tests\Features\Expect\HigherOrder\properties ✓ it allows properties to be accessed from the value @@ -578,5 +579,5 @@ ✓ it is a test ✓ it uses correct parent class - Tests: 4 incompleted, 7 skipped, 362 passed + Tests: 4 incompleted, 7 skipped, 363 passed \ No newline at end of file From fbcb492c79f68793ca4bfde7713faec8e5a55e05 Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 24 Jun 2021 21:40:24 +0100 Subject: [PATCH 4/5] Simplification --- src/HigherOrderExpectation.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/HigherOrderExpectation.php b/src/HigherOrderExpectation.php index 4cb6fc49..e436da0c 100644 --- a/src/HigherOrderExpectation.php +++ b/src/HigherOrderExpectation.php @@ -66,11 +66,15 @@ final class HigherOrderExpectation /** * Creates a new expectation. * - * @param mixed $value + * @template TValue + * + * @param TValue $value + * + * @return Expectation */ - public function and($value): HigherOrderExpectation + public function and($value): Expectation { - return new self($this->expect($value), $value); + return $this->expect($value); } /** From 11ebe014fbf57e8aa30757ab39c1e1de388720e6 Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 24 Jun 2021 21:44:57 +0100 Subject: [PATCH 5/5] docs: update changelog --- CHANGELOG.md | 4 ++++ src/Pest.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38a673cf..7d8a53e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [v1.7.1 (2021-06-24)](https://github.com/pestphp/pest/compare/v1.7.0...v1.7.1) +### Fixed +- The `and` method not being usable in Higher Order expectations ([#330](https://github.com/pestphp/pest/pull/330)) + ## [v1.7.0 (2021-06-19)](https://github.com/pestphp/pest/compare/v1.6.0...v1.7.0) ### Added - Support for non-callable values in the sequence method, which will be passed as `toEqual` ([#323](https://github.com/pestphp/pest/pull/323)) diff --git a/src/Pest.php b/src/Pest.php index 6fc5894b..d54a4413 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -6,7 +6,7 @@ namespace Pest; function version(): string { - return '1.7.0'; + return '1.7.1'; } function testDirectory(string $file = ''): string