From 01b9bab55f36c834ec62e9534b1e5c752b8891dd Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 6 Jul 2020 00:32:12 +0200 Subject: [PATCH 01/19] feat(expect): adds toBe --- src/Expectation.php | 65 ++++++++++++++++++++++++++++++++++++ src/OppositeExpectation.php | 45 +++++++++++++++++++++++++ src/globals.php | 9 +++++ tests/.snapshots/success.txt | 9 +++-- tests/Expect/ToBe.php | 19 +++++++++++ 5 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 src/Expectation.php create mode 100644 src/OppositeExpectation.php create mode 100644 tests/Expect/ToBe.php diff --git a/src/Expectation.php b/src/Expectation.php new file mode 100644 index 00000000..2afe4088 --- /dev/null +++ b/src/Expectation.php @@ -0,0 +1,65 @@ +value = $value; + } + + /** + * Creates the opposite expectation for the value. + */ + public function not(): OppositeExpectation + { + return new OppositeExpectation($this); + } + + /** + * Asserts that two variables have the same type and + * value. Used on objects, it asserts that two + * variables reference the same object. + * + * @param mixed $value + */ + public function toBe($value): Expectation + { + Assert::assertSame($value, $this->value); + + return $this; + } + + /** + * Dynamically calls methods on the class without any arguments. + * + * @return Expectation + */ + public function __get(string $name) + { + /* @phpstan-ignore-next-line */ + return $this->{$name}(); + } +} diff --git a/src/OppositeExpectation.php b/src/OppositeExpectation.php new file mode 100644 index 00000000..08a7ebc6 --- /dev/null +++ b/src/OppositeExpectation.php @@ -0,0 +1,45 @@ +original = $original; + } + + /** + * Handle dynamic method calls into the original expectation. + * + * @param array $arguments + */ + public function __call(string $name, array $arguments): Expectation + { + try { + /* @phpstan-ignore-next-line */ + $this->original->{$name}(...$arguments); + } catch (ExpectationFailedException $e) { + return $this->original; + } + + throw new ExpectationFailedException(sprintf('@todo')); + } +} diff --git a/src/globals.php b/src/globals.php index a15f6bea..07ec9d6e 100644 --- a/src/globals.php +++ b/src/globals.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Pest\Datasets; +use Pest\Expectation; use Pest\PendingObjects\AfterEachCall; use Pest\PendingObjects\BeforeEachCall; use Pest\PendingObjects\TestCall; @@ -104,3 +105,11 @@ function afterAll(Closure $closure = null): void { TestSuite::getInstance()->afterAll->set($closure); } + +/** + * Creates a new expectation. + */ +function expect($value): Expectation +{ + return new Expectation($value); +} diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 09e41270..bcff1d84 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2,6 +2,11 @@ PASS Tests\CustomTestCase\ExecutedTest ✓ that gets executed + PASS Tests\Expect\ToBe + ✓ strict comparisons + ✓ failures + ✓ not failures + PASS Tests\Features\AfterAll ✓ deletes file after all @@ -167,5 +172,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 96 passed - Time: 3.43s + Tests: 6 skipped, 99 passed + Time: 3.62s diff --git a/tests/Expect/ToBe.php b/tests/Expect/ToBe.php new file mode 100644 index 00000000..f3f84608 --- /dev/null +++ b/tests/Expect/ToBe.php @@ -0,0 +1,19 @@ +toBe($nuno); + expect($nuno)->not->toBe($dries); +}); + +test('failures', function () { + expect(1)->toBe(2); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(1)->not->toBe(1); +})->throws(ExpectationFailedException::class); From 42f0bd052e190d63b6a967de46285fe1ce4b475e Mon Sep 17 00:00:00 2001 From: ceceppa Date: Fri, 10 Jul 2020 07:47:34 +0100 Subject: [PATCH 02/19] feat(expect): add more methods --- src/Expectation.php | 95 ++++++++++++++++++++ tests/Expect/toBeFalse.php | 15 ++++ tests/Expect/toBeGreatherThan.php | 16 ++++ tests/Expect/toBeGreatherThanOrEqual.php | 16 ++++ tests/Expect/toBeLessThan.php | 16 ++++ tests/Expect/toBeLessThanOrEqual.php | 16 ++++ tests/Expect/toContain.php | 15 ++++ tests/Expect/toContainString.php | 16 ++++ tests/Expect/toContainStringIgnoringCase.php | 17 ++++ 9 files changed, 222 insertions(+) create mode 100644 tests/Expect/toBeFalse.php create mode 100644 tests/Expect/toBeGreatherThan.php create mode 100644 tests/Expect/toBeGreatherThanOrEqual.php create mode 100644 tests/Expect/toBeLessThan.php create mode 100644 tests/Expect/toBeLessThanOrEqual.php create mode 100644 tests/Expect/toContain.php create mode 100644 tests/Expect/toContainString.php create mode 100644 tests/Expect/toContainStringIgnoringCase.php diff --git a/src/Expectation.php b/src/Expectation.php index 2afe4088..7da35974 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -52,6 +52,101 @@ final class Expectation return $this; } + /** + * Assert that value is false. + */ + public function toBeFalse() + { + Assert::assertFalse($this->value); + + return $this; + } + + /** + * Assert that value is greater than expected one. + * + * @param int|float $value + */ + public function toBeGreaterThan($value) + { + Assert::assertGreaterThan($value, $this->value); + + return $this; + } + + /** + * Assert that value is greater than or equal to the expected one. + * + * @param int|float $value + */ + public function toBeGreaterThanOrEqual($value) + { + Assert::assertGreaterThanOrEqual($value, $this->value); + + return $this; + } + + /** + * Assert that value is less than or equal to the expected one. + * + * @param int|float $value + */ + public function toBeLessThan($value) + { + Assert::assertLessThan($value, $this->value); + + return $this; + } + + /** + * Assert that value is less than the expected one. + * + * @param int|float $value + */ + public function toBeLessThanOrEqual($value) + { + Assert::assertLessThanOrEqual($value, $this->value); + + return $this; + } + + /** + * Assert that needles is an element of value. + * + * @param mixed $needle + */ + public function toContain($needle) + { + Assert::assertContains($needle, $this->value); + + return $this; + } + + /** + * Assert that needles is a substring of value. + * + * @param string $needle + */ + public function toContainString($needle) + { + Assert::assertStringContainsString($needle, $this->value); + + return $this; + } + + /** + * Assert that needles is a substring of value, ignoring the + * difference in casing. + * + * @param string $needle + */ + public function toContainStringIgnoringCase($needle) + { + Assert::assertStringContainsStringIgnoringCase($needle, $this->value); + + return $this; + } + /** * Dynamically calls methods on the class without any arguments. * diff --git a/tests/Expect/toBeFalse.php b/tests/Expect/toBeFalse.php new file mode 100644 index 00000000..1371c86e --- /dev/null +++ b/tests/Expect/toBeFalse.php @@ -0,0 +1,15 @@ +toBeFalse(); +}); + +test('failures', function () { + expect('')->toBeFalse(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(false)->not->toBe(false); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeGreatherThan.php b/tests/Expect/toBeGreatherThan.php new file mode 100644 index 00000000..ed840ed6 --- /dev/null +++ b/tests/Expect/toBeGreatherThan.php @@ -0,0 +1,16 @@ +toBeGreaterThan(41); + expect(4)->toBeGreaterThan(3.9); +}); + +test('failures', function () { + expect(4)->toBeGreaterThan(4); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(5)->not->toBeGreaterThan(4); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeGreatherThanOrEqual.php b/tests/Expect/toBeGreatherThanOrEqual.php new file mode 100644 index 00000000..3b1cd029 --- /dev/null +++ b/tests/Expect/toBeGreatherThanOrEqual.php @@ -0,0 +1,16 @@ +toBeGreaterThanOrEqual(41); + expect(4)->toBeGreaterThanOrEqual(4); +}); + +test('failures', function () { + expect(4)->toBeGreaterThanOrEqual(4.1); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(5)->not->toBeGreaterThanOrEqual(5); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeLessThan.php b/tests/Expect/toBeLessThan.php new file mode 100644 index 00000000..08db8545 --- /dev/null +++ b/tests/Expect/toBeLessThan.php @@ -0,0 +1,16 @@ +toBeLessThan(42); + expect(4)->toBeLessThan(5); +}); + +test('failures', function () { + expect(4)->toBeLessThan(4); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(5)->not->toBeLessThan(6); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeLessThanOrEqual.php b/tests/Expect/toBeLessThanOrEqual.php new file mode 100644 index 00000000..c9f00577 --- /dev/null +++ b/tests/Expect/toBeLessThanOrEqual.php @@ -0,0 +1,16 @@ +toBeLessThanOrEqual(42); + expect(4)->toBeLessThanOrEqual(4); +}); + +test('failures', function () { + expect(4)->toBeLessThanOrEqual(3.9); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(5)->not->toBeLessThanOrEqual(5); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContain.php b/tests/Expect/toContain.php new file mode 100644 index 00000000..ce477fbf --- /dev/null +++ b/tests/Expect/toContain.php @@ -0,0 +1,15 @@ +toContain(42); +}); + +test('failures', function () { + expect([1, 2, 42])->toContain(3); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect([1, 2, 42])->not->toContain(42); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainString.php b/tests/Expect/toContainString.php new file mode 100644 index 00000000..03f55b69 --- /dev/null +++ b/tests/Expect/toContainString.php @@ -0,0 +1,16 @@ +toContainString('world'); + expect('hello world')->not->toContainString('World'); +}); + +test('failures', function () { + expect('hello world')->toContainString('Hello'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('hello world')->not->toContainString('hello'); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainStringIgnoringCase.php b/tests/Expect/toContainStringIgnoringCase.php new file mode 100644 index 00000000..fc5e1081 --- /dev/null +++ b/tests/Expect/toContainStringIgnoringCase.php @@ -0,0 +1,17 @@ +toContainStringIgnoringCase('world'); + expect('hello world')->toContainStringIgnoringCase('World'); +}); + +test('failures', function () { + expect('hello world')->toContainStringIgnoringCase('hi'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('hello world')->not->toContainStringIgnoringCase('Hello'); + expect('hello world')->not->toContainStringIgnoringCase('hello'); +})->throws(ExpectationFailedException::class); From 679082e805c6a8502daf6b010b20c043dd6438ad Mon Sep 17 00:00:00 2001 From: ceceppa Date: Fri, 10 Jul 2020 07:53:45 +0100 Subject: [PATCH 03/19] feat(expect): add more methods --- src/Expectation.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 7da35974..44357b9b 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -127,7 +127,7 @@ final class Expectation * * @param string $needle */ - public function toContainString($needle) + public function toContainString(string $needle) { Assert::assertStringContainsString($needle, $this->value); @@ -140,7 +140,7 @@ final class Expectation * * @param string $needle */ - public function toContainStringIgnoringCase($needle) + public function toContainStringIgnoringCase(string $needle) { Assert::assertStringContainsStringIgnoringCase($needle, $this->value); From 9f62f2d483c3fca407ae75b5ebcc26b63a7342af Mon Sep 17 00:00:00 2001 From: ceceppa Date: Mon, 13 Jul 2020 17:27:55 +0100 Subject: [PATCH 04/19] feat(expect): add more methods --- src/Expectation.php | 136 +++++++++++++++++++++- tests/.snapshots/success.txt | 94 ++++++++++++++- tests/Expect/thatDirectoryExists.php | 17 +++ tests/Expect/thatDirectoryIsReadable.php | 15 +++ tests/Expect/toBeEmpty.php | 18 +++ tests/Expect/toContainOnly.php | 17 +++ tests/Expect/toContainOnlyInstancesOf.php | 23 ++++ tests/Expect/toCount.php | 15 +++ tests/Expect/toEqual.php | 15 +++ tests/Expect/toEqualCanonicalizing.php | 16 +++ tests/Expect/toEqualIgnoringCase.php | 15 +++ tests/Expect/toEqualWithDelta.php | 15 +++ 12 files changed, 388 insertions(+), 8 deletions(-) create mode 100644 tests/Expect/thatDirectoryExists.php create mode 100644 tests/Expect/thatDirectoryIsReadable.php create mode 100644 tests/Expect/toBeEmpty.php create mode 100644 tests/Expect/toContainOnly.php create mode 100644 tests/Expect/toContainOnlyInstancesOf.php create mode 100644 tests/Expect/toCount.php create mode 100644 tests/Expect/toEqual.php create mode 100644 tests/Expect/toEqualCanonicalizing.php create mode 100644 tests/Expect/toEqualIgnoringCase.php create mode 100644 tests/Expect/toEqualWithDelta.php diff --git a/src/Expectation.php b/src/Expectation.php index 44357b9b..ae4b0ad5 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -53,7 +53,17 @@ final class Expectation } /** - * Assert that value is false. + * Assert the value is empty. + */ + public function toBeEmpty() + { + Assert::assertEmpty($this->value); + + return $this; + } + + /** + * Assert the value is false. */ public function toBeFalse() { @@ -63,7 +73,7 @@ final class Expectation } /** - * Assert that value is greater than expected one. + * Assert the value is greater than expected one. * * @param int|float $value */ @@ -123,9 +133,29 @@ final class Expectation } /** - * Assert that needles is a substring of value. + * Assert the value contains only variables of type. * - * @param string $needle + * @param string|mixed $type + */ + public function toContainOnly($type) + { + Assert::assertContainsOnly($type, $this->value); + + return $this; + } + + /** + * Assert the value contains only instances of $instance. + */ + public function toContainOnlyInstancesOf(string $instance) + { + Assert::assertContainsOnlyInstancesOf($instance, $this->value); + + return $this; + } + + /** + * Assert that needles is a substring of value. */ public function toContainString(string $needle) { @@ -137,8 +167,6 @@ final class Expectation /** * Assert that needles is a substring of value, ignoring the * difference in casing. - * - * @param string $needle */ public function toContainStringIgnoringCase(string $needle) { @@ -147,6 +175,102 @@ final class Expectation return $this; } + /** + * Assert that $count matches the number of elements of $value. + */ + public function toCount(int $count) + { + Assert::assertCount($count, $this->value); + + return $this; + } + + /** + * Asserts that two variables have the same value. + * + * @param mixed $value + */ + public function toEqual($value) + { + Assert::assertEquals($value, $this->value); + + return $this; + } + + /** + * Asserts that two variables are equals, ignoring the casing + * for the comparison. + * + * @param mixed $value + */ + public function toEqualIgnoringCase($value) + { + Assert::assertEqualsIgnoringCase($value, $this->value); + + return $this; + } + + /** + * Asserts that two variables have the same value. + * The contents of $expected and $actual are canonicalized before + * they are compared. For instance, when the two variables $value and + * $this->value are arrays, then these arrays are sorted before they are + * compared. When $value and $this->value are objects, + * each object is converted to an array containing all private, + * protected and public attributes. + * + * @param mixed $value + */ + public function toEqualCanonicalizing($value) + { + Assert::assertEqualsCanonicalizing($value, $this->value); + + return $this; + } + + /** + * Assert that the absolute difference between $value and $this->value + * is greather thatn $delta. + * + * @param mixed $value + */ + public function toEqualWithDelta($value, float $delta) + { + Assert::assertEqualsWithDelta($value, $this->value, $delta); + + return $this; + } + + /** + * Assert that the value is a directory. + */ + public function toBeExistingDirectory() + { + Assert::assertDirectoryExists($this->value); + + return $this; + } + + /** + * Assert that the value is a directory and is readable. + */ + public function toBeReadableDirectory() + { + Assert::assertDirectoryIsReadable($this->value); + + return $this; + } + + /** + * Assert that the value is a directory and is writable. + */ + public function toBeWritableDirectory() + { + Assert::assertDirectoryIsWritable($this->value); + + return $this; + } + /** * Dynamically calls methods on the class without any arguments. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index bcff1d84..aa0a5df6 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -5,6 +5,96 @@ PASS Tests\Expect\ToBe ✓ strict comparisons ✓ failures + ✓ not failures + + PASS Tests\Expect\thatDirectoryExists + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\thatDirectoryIsReadable + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeEmpty + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeFalse + ✓ strict comparisons + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeGreatherThan + ✓ passes + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeGreatherThanOrEqual + ✓ passes + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeLessThan + ✓ passes + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeLessThanOrEqual + ✓ passes + ✓ failures + ✓ not failures + + PASS Tests\Expect\toContain + ✓ passes + ✓ failures + ✓ not failures + + PASS Tests\Expect\toContainOnly + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toContainOnlyInstancesOf + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toContainString + ✓ is case sensitive + ✓ failures + ✓ not failures + + PASS Tests\Expect\toContainStringIgnoringCase + ✓ ignore difference in casing + ✓ failures + ✓ not failures + + PASS Tests\Expect\toCount + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toEqual + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toEqualCanonicalizing + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toEqualIgnoringCase + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toEqualWithDelta + ✓ pass + ✓ failures ✓ not failures PASS Tests\Features\AfterAll @@ -172,5 +262,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 99 passed - Time: 3.62s + Tests: 6 skipped, 153 passed + Time: 4.35s diff --git a/tests/Expect/thatDirectoryExists.php b/tests/Expect/thatDirectoryExists.php new file mode 100644 index 00000000..6f2eb5f9 --- /dev/null +++ b/tests/Expect/thatDirectoryExists.php @@ -0,0 +1,17 @@ +toBeExistingDirectory(); +}); + +test('failures', function () { + expect('/random/path/whatever')->toBeExistingDirectory(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('.')->not->toBeExistingDirectory(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/thatDirectoryIsReadable.php b/tests/Expect/thatDirectoryIsReadable.php new file mode 100644 index 00000000..88f96019 --- /dev/null +++ b/tests/Expect/thatDirectoryIsReadable.php @@ -0,0 +1,15 @@ +toBeWritableDirectory(); +}); + +test('failures', function () { + expect('/random/path/whatever')->toBeWritableDirectory(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(sys_get_temp_dir())->not->toBeWritableDirectory(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeEmpty.php b/tests/Expect/toBeEmpty.php new file mode 100644 index 00000000..05e5180a --- /dev/null +++ b/tests/Expect/toBeEmpty.php @@ -0,0 +1,18 @@ +toBeEmpty(); + expect(null)->toBeEmpty(); +}); + +test('failures', function () { + expect([1, 2])->toBeEmpty(); + expect(' ')->toBeEmpty(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect([])->not->toBeEmpty(); + expect(null)->not->toBeEmpty(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainOnly.php b/tests/Expect/toContainOnly.php new file mode 100644 index 00000000..2e9fecfe --- /dev/null +++ b/tests/Expect/toContainOnly.php @@ -0,0 +1,17 @@ +toContainOnly('int'); + expect(['hello', 'world'])->toContainOnly('string'); +}); + +test('failures', function () { + expect([1, 2, '3'])->toContainOnly('string'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect([1, 2, 3])->not->toContainOnly('int'); + expect(['hello', 'world'])->not->toContainOnly('string'); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainOnlyInstancesOf.php b/tests/Expect/toContainOnlyInstancesOf.php new file mode 100644 index 00000000..fdda161b --- /dev/null +++ b/tests/Expect/toContainOnlyInstancesOf.php @@ -0,0 +1,23 @@ +toContainOnlyInstancesOf(Expectation::class); +}); + +test('failures', function () { + $expected = [new Expectation('whatever')]; + + expect($expected)->toContainOnlyInstancesOf(AddsTests::class); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + $expected = [new Expectation('whatever')]; + + expect($expected)->not->toContainOnlyInstancesOf(Expectation::class); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toCount.php b/tests/Expect/toCount.php new file mode 100644 index 00000000..6e8d5fcd --- /dev/null +++ b/tests/Expect/toCount.php @@ -0,0 +1,15 @@ +toCount(3); +}); + +test('failures', function () { + expect([1, 2, 3])->toCount(4); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect([1, 2, 3])->not->toCount(3); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqual.php b/tests/Expect/toEqual.php new file mode 100644 index 00000000..de0b7e50 --- /dev/null +++ b/tests/Expect/toEqual.php @@ -0,0 +1,15 @@ +toEqual(123); +}); + +test('failures', function () { + expect(['a', 'b', 'c'])->toEqual(['a', 'b']); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('042')->not->toEqual(42); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqualCanonicalizing.php b/tests/Expect/toEqualCanonicalizing.php new file mode 100644 index 00000000..2d6c299f --- /dev/null +++ b/tests/Expect/toEqualCanonicalizing.php @@ -0,0 +1,16 @@ +toEqualCanonicalizing(123); + expect(['a', 'b', 'c'])->toEqualCanonicalizing(['c', 'a', 'b']); +}); + +test('failures', function () { + expect(['a', 'b', 'c'])->toEqualCanonicalizing(['a', 'b']); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('042')->not->toEqualCanonicalizing(42); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqualIgnoringCase.php b/tests/Expect/toEqualIgnoringCase.php new file mode 100644 index 00000000..2016fa4d --- /dev/null +++ b/tests/Expect/toEqualIgnoringCase.php @@ -0,0 +1,15 @@ +toEqualIgnoringCase('HELLO'); +}); + +test('failures', function () { + expect('hello')->toEqualIgnoringCase('BAR'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('HELLO')->not->toEqualIgnoringCase('HelLo'); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqualWithDelta.php b/tests/Expect/toEqualWithDelta.php new file mode 100644 index 00000000..bb78b86d --- /dev/null +++ b/tests/Expect/toEqualWithDelta.php @@ -0,0 +1,15 @@ +toEqualWithDelta(1.3, .4); +}); + +test('failures', function () { + expect(1.0)->toEqualWithDelta(1.5, .1); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(1.0)->not->toEqualWithDelta(1.6, .7); +})->throws(ExpectationFailedException::class); From b4bf799d7568735e87875bf4c79b4b07c0bc8d39 Mon Sep 17 00:00:00 2001 From: ceceppa Date: Mon, 13 Jul 2020 17:38:09 +0100 Subject: [PATCH 05/19] feat(expect): add more methods --- src/Expectation.php | 44 +++++++++---------- ...ryExists.php => toBeExistingDirectory.php} | 0 tests/Expect/toBeReadableDirectory.php | 15 +++++++ ...Readable.php => toBeWritableDirectory.php} | 0 4 files changed, 36 insertions(+), 23 deletions(-) rename tests/Expect/{thatDirectoryExists.php => toBeExistingDirectory.php} (100%) create mode 100644 tests/Expect/toBeReadableDirectory.php rename tests/Expect/{thatDirectoryIsReadable.php => toBeWritableDirectory.php} (100%) diff --git a/src/Expectation.php b/src/Expectation.php index ae4b0ad5..750f875a 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -55,7 +55,7 @@ final class Expectation /** * Assert the value is empty. */ - public function toBeEmpty() + public function toBeEmpty(): Expectation { Assert::assertEmpty($this->value); @@ -65,7 +65,7 @@ final class Expectation /** * Assert the value is false. */ - public function toBeFalse() + public function toBeFalse(): Expectation { Assert::assertFalse($this->value); @@ -77,7 +77,7 @@ final class Expectation * * @param int|float $value */ - public function toBeGreaterThan($value) + public function toBeGreaterThan($value): Expectation { Assert::assertGreaterThan($value, $this->value); @@ -89,7 +89,7 @@ final class Expectation * * @param int|float $value */ - public function toBeGreaterThanOrEqual($value) + public function toBeGreaterThanOrEqual($value): Expectation { Assert::assertGreaterThanOrEqual($value, $this->value); @@ -101,7 +101,7 @@ final class Expectation * * @param int|float $value */ - public function toBeLessThan($value) + public function toBeLessThan($value): Expectation { Assert::assertLessThan($value, $this->value); @@ -113,7 +113,7 @@ final class Expectation * * @param int|float $value */ - public function toBeLessThanOrEqual($value) + public function toBeLessThanOrEqual($value): Expectation { Assert::assertLessThanOrEqual($value, $this->value); @@ -125,7 +125,7 @@ final class Expectation * * @param mixed $needle */ - public function toContain($needle) + public function toContain($needle): Expectation { Assert::assertContains($needle, $this->value); @@ -135,9 +135,9 @@ final class Expectation /** * Assert the value contains only variables of type. * - * @param string|mixed $type + * @param mixed $type */ - public function toContainOnly($type) + public function toContainOnly($type): Expectation { Assert::assertContainsOnly($type, $this->value); @@ -147,7 +147,7 @@ final class Expectation /** * Assert the value contains only instances of $instance. */ - public function toContainOnlyInstancesOf(string $instance) + public function toContainOnlyInstancesOf(string $instance): Expectation { Assert::assertContainsOnlyInstancesOf($instance, $this->value); @@ -157,7 +157,7 @@ final class Expectation /** * Assert that needles is a substring of value. */ - public function toContainString(string $needle) + public function toContainString(string $needle): Expectation { Assert::assertStringContainsString($needle, $this->value); @@ -168,7 +168,7 @@ final class Expectation * Assert that needles is a substring of value, ignoring the * difference in casing. */ - public function toContainStringIgnoringCase(string $needle) + public function toContainStringIgnoringCase(string $needle): Expectation { Assert::assertStringContainsStringIgnoringCase($needle, $this->value); @@ -178,7 +178,7 @@ final class Expectation /** * Assert that $count matches the number of elements of $value. */ - public function toCount(int $count) + public function toCount(int $count): Expectation { Assert::assertCount($count, $this->value); @@ -190,7 +190,7 @@ final class Expectation * * @param mixed $value */ - public function toEqual($value) + public function toEqual($value): Expectation { Assert::assertEquals($value, $this->value); @@ -203,7 +203,7 @@ final class Expectation * * @param mixed $value */ - public function toEqualIgnoringCase($value) + public function toEqualIgnoringCase($value): Expectation { Assert::assertEqualsIgnoringCase($value, $this->value); @@ -221,7 +221,7 @@ final class Expectation * * @param mixed $value */ - public function toEqualCanonicalizing($value) + public function toEqualCanonicalizing($value): Expectation { Assert::assertEqualsCanonicalizing($value, $this->value); @@ -234,7 +234,7 @@ final class Expectation * * @param mixed $value */ - public function toEqualWithDelta($value, float $delta) + public function toEqualWithDelta($value, float $delta): Expectation { Assert::assertEqualsWithDelta($value, $this->value, $delta); @@ -244,7 +244,7 @@ final class Expectation /** * Assert that the value is a directory. */ - public function toBeExistingDirectory() + public function toBeExistingDirectory(): Expectation { Assert::assertDirectoryExists($this->value); @@ -254,7 +254,7 @@ final class Expectation /** * Assert that the value is a directory and is readable. */ - public function toBeReadableDirectory() + public function toBeReadableDirectory(): Expectation { Assert::assertDirectoryIsReadable($this->value); @@ -264,7 +264,7 @@ final class Expectation /** * Assert that the value is a directory and is writable. */ - public function toBeWritableDirectory() + public function toBeWritableDirectory(): Expectation { Assert::assertDirectoryIsWritable($this->value); @@ -273,10 +273,8 @@ final class Expectation /** * Dynamically calls methods on the class without any arguments. - * - * @return Expectation */ - public function __get(string $name) + public function __get(string $name): Expectation { /* @phpstan-ignore-next-line */ return $this->{$name}(); diff --git a/tests/Expect/thatDirectoryExists.php b/tests/Expect/toBeExistingDirectory.php similarity index 100% rename from tests/Expect/thatDirectoryExists.php rename to tests/Expect/toBeExistingDirectory.php diff --git a/tests/Expect/toBeReadableDirectory.php b/tests/Expect/toBeReadableDirectory.php new file mode 100644 index 00000000..704109b5 --- /dev/null +++ b/tests/Expect/toBeReadableDirectory.php @@ -0,0 +1,15 @@ +toBeReadableDirectory(); +}); + +test('failures', function () { + expect('/random/path/whatever')->toBeReadableDirectory(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(sys_get_temp_dir())->not->toBeReadableDirectory(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/thatDirectoryIsReadable.php b/tests/Expect/toBeWritableDirectory.php similarity index 100% rename from tests/Expect/thatDirectoryIsReadable.php rename to tests/Expect/toBeWritableDirectory.php From b4c45af785fb41cf431ca4fef981adf5f0360c21 Mon Sep 17 00:00:00 2001 From: ceceppa Date: Mon, 13 Jul 2020 17:49:19 +0100 Subject: [PATCH 06/19] feat(expect): add more methods --- src/Expectation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Expectation.php b/src/Expectation.php index 750f875a..de21f198 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -274,7 +274,7 @@ final class Expectation /** * Dynamically calls methods on the class without any arguments. */ - public function __get(string $name): Expectation + public function __get(string $name) { /* @phpstan-ignore-next-line */ return $this->{$name}(); From d29c7897883206b4e5ae8fe53892452f6fe092d8 Mon Sep 17 00:00:00 2001 From: ceceppa Date: Mon, 13 Jul 2020 17:57:18 +0100 Subject: [PATCH 07/19] feat(expect): add more methods --- src/Expectation.php | 2 ++ tests/.snapshots/success.txt | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index de21f198..d8f36164 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -273,6 +273,8 @@ final class Expectation /** * Dynamically calls methods on the class without any arguments. + * + * @return Expectation */ public function __get(string $name) { diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index aa0a5df6..fe3b6350 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -5,21 +5,16 @@ PASS Tests\Expect\ToBe ✓ strict comparisons ✓ failures - ✓ not failures - - PASS Tests\Expect\thatDirectoryExists - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\thatDirectoryIsReadable - ✓ pass - ✓ failures ✓ not failures PASS Tests\Expect\toBeEmpty ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeExistingDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeFalse @@ -45,6 +40,16 @@ PASS Tests\Expect\toBeLessThanOrEqual ✓ passes ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeReadableDirectory + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeWritableDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toContain @@ -262,5 +267,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 153 passed - Time: 4.35s + Tests: 6 skipped, 156 passed + Time: 4.42s From 819825bdd244e9dff73bb17207c0d8a9c257729f Mon Sep 17 00:00:00 2001 From: ceceppa Date: Tue, 14 Jul 2020 08:08:13 +0100 Subject: [PATCH 08/19] feat(expect): add more methods --- src/Expectation.php | 142 ++++++++++++++++-- tests/.snapshots/success.txt | 78 ++++++++-- tests/Expect/{ToBe.php => toBe.php} | 0 ...oBeReadableDirectory.php => toBeArray.php} | 7 +- ...toBeWritableDirectory.php => toBeBool.php} | 7 +- tests/Expect/toBeCallable.php | 18 +++ ...oBeExistingDirectory.php => toBeFloat.php} | 9 +- tests/Expect/toBeInfinite.php | 16 ++ tests/Expect/toBeInstanceOf.php | 16 ++ tests/Expect/toBeInt.php | 16 ++ tests/Expect/toBeIterable.php | 23 +++ tests/Expect/toBeNAN.php | 16 ++ tests/Expect/toBeNull.php | 16 ++ tests/Expect/toBeNumeric.php | 16 ++ tests/Expect/toBeObject.php | 16 ++ tests/Expect/toBeResource.php | 22 +++ tests/Expect/toBeScalar.php | 15 ++ tests/Expect/toBeString.php | 16 ++ 18 files changed, 419 insertions(+), 30 deletions(-) rename tests/Expect/{ToBe.php => toBe.php} (100%) rename tests/Expect/{toBeReadableDirectory.php => toBeArray.php} (58%) rename tests/Expect/{toBeWritableDirectory.php => toBeBool.php} (58%) create mode 100644 tests/Expect/toBeCallable.php rename tests/Expect/{toBeExistingDirectory.php => toBeFloat.php} (57%) create mode 100644 tests/Expect/toBeInfinite.php create mode 100644 tests/Expect/toBeInstanceOf.php create mode 100644 tests/Expect/toBeInt.php create mode 100644 tests/Expect/toBeIterable.php create mode 100644 tests/Expect/toBeNAN.php create mode 100644 tests/Expect/toBeNull.php create mode 100644 tests/Expect/toBeNumeric.php create mode 100644 tests/Expect/toBeObject.php create mode 100644 tests/Expect/toBeResource.php create mode 100644 tests/Expect/toBeScalar.php create mode 100644 tests/Expect/toBeString.php diff --git a/src/Expectation.php b/src/Expectation.php index d8f36164..db123468 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -230,7 +230,7 @@ final class Expectation /** * Assert that the absolute difference between $value and $this->value - * is greather thatn $delta. + * is greater than $delta. * * @param mixed $value */ @@ -242,31 +242,153 @@ final class Expectation } /** - * Assert that the value is a directory. + * Assert that the value infinite. */ - public function toBeExistingDirectory(): Expectation + public function toBeInfinite(): Expectation { - Assert::assertDirectoryExists($this->value); + Assert::assertInfinite($this->value); return $this; } /** - * Assert that the value is a directory and is readable. + * Assert that the value is an instance of $value. + * + * @param mixed $value */ - public function toBeReadableDirectory(): Expectation + public function toBeInstanceOf($value): Expectation { - Assert::assertDirectoryIsReadable($this->value); + Assert::assertInstanceOf($value, $this->value); return $this; } /** - * Assert that the value is a directory and is writable. + * Assert that the value is an array. */ - public function toBeWritableDirectory(): Expectation + public function toBeArray(): Expectation { - Assert::assertDirectoryIsWritable($this->value); + Assert::assertIsArray($this->value); + + return $this; + } + + /** + * Assert that the value is of type bool. + */ + public function toBeBool(): Expectation + { + Assert::assertIsBool($this->value); + + return $this; + } + + /** + * Assert that the value is of type callable. + */ + public function toBeCallable(): Expectation + { + Assert::assertIsCallable($this->value); + + return $this; + } + + /** + * Assert that the value is type of float. + */ + public function toBeFloat(): Expectation + { + Assert::assertIsFloat($this->value); + + return $this; + } + + /** + * Assert that the value is type of int. + */ + public function toBeInt(): Expectation + { + Assert::assertIsInt($this->value); + + return $this; + } + + /** + * Assert that the value is type of iterable. + */ + public function toBeIterable(): Expectation + { + Assert::assertIsIterable($this->value); + + return $this; + } + + /** + * Assert that the value is type of numeric. + */ + public function toBeNumeric(): Expectation + { + Assert::assertIsNumeric($this->value); + + return $this; + } + + /** + * Assert that the value is type of object. + */ + public function toBeObject(): Expectation + { + Assert::assertIsObject($this->value); + + return $this; + } + + /** + * Assert that the value is type of resource. + */ + public function toBeResource(): Expectation + { + Assert::assertIsResource($this->value); + + return $this; + } + + /** + * Assert that the value is type of scalar. + */ + public function toBeScalar(): Expectation + { + Assert::assertIsScalar($this->value); + + return $this; + } + + /** + * Assert that the value is type of string. + */ + public function toBeString(): Expectation + { + Assert::assertIsString($this->value); + + return $this; + } + + /** + * Assert that the value is NAN. + */ + public function toBeNan(): Expectation + { + Assert::assertNan($this->value); + + return $this; + } + + /** + * Assert that the value is NAN. + */ + public function toBeNull(): Expectation + { + Assert::assertNull($this->value); return $this; } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index fe3b6350..916c0d6c 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2,9 +2,24 @@ PASS Tests\CustomTestCase\ExecutedTest ✓ that gets executed - PASS Tests\Expect\ToBe + PASS Tests\Expect\toBe ✓ strict comparisons ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeArray + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeBool + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeCallable + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeEmpty @@ -12,13 +27,13 @@ ✓ failures ✓ not failures - PASS Tests\Expect\toBeExistingDirectory - ✓ pass + PASS Tests\Expect\toBeFalse + ✓ strict comparisons ✓ failures ✓ not failures - PASS Tests\Expect\toBeFalse - ✓ strict comparisons + PASS Tests\Expect\toBeFloat + ✓ pass ✓ failures ✓ not failures @@ -30,6 +45,26 @@ PASS Tests\Expect\toBeGreatherThanOrEqual ✓ passes ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeInfinite + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeInstanceOf + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeInt + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeIterable + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeLessThan @@ -42,12 +77,37 @@ ✓ failures ✓ not failures - PASS Tests\Expect\toBeReadableDirectory + PASS Tests\Expect\toBeNAN ✓ pass ✓ failures ✓ not failures - PASS Tests\Expect\toBeWritableDirectory + PASS Tests\Expect\toBeNull + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeNumeric + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeObject + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeResource + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeScalar + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeString ✓ pass ✓ failures ✓ not failures @@ -267,5 +327,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 156 passed - Time: 4.42s + Tests: 6 skipped, 192 passed + Time: 5.20s diff --git a/tests/Expect/ToBe.php b/tests/Expect/toBe.php similarity index 100% rename from tests/Expect/ToBe.php rename to tests/Expect/toBe.php diff --git a/tests/Expect/toBeReadableDirectory.php b/tests/Expect/toBeArray.php similarity index 58% rename from tests/Expect/toBeReadableDirectory.php rename to tests/Expect/toBeArray.php index 704109b5..3fcec231 100644 --- a/tests/Expect/toBeReadableDirectory.php +++ b/tests/Expect/toBeArray.php @@ -3,13 +3,14 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect(sys_get_temp_dir())->toBeReadableDirectory(); + expect([1, 2, 3])->toBeArray(); + expect('1, 2, 3')->not->toBeArray(); }); test('failures', function () { - expect('/random/path/whatever')->toBeReadableDirectory(); + expect(null)->toBeArray(); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect(sys_get_temp_dir())->not->toBeReadableDirectory(); + expect(['a', 'b', 'c'])->not->toBeArray(); })->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeWritableDirectory.php b/tests/Expect/toBeBool.php similarity index 58% rename from tests/Expect/toBeWritableDirectory.php rename to tests/Expect/toBeBool.php index 88f96019..5dc37b21 100644 --- a/tests/Expect/toBeWritableDirectory.php +++ b/tests/Expect/toBeBool.php @@ -3,13 +3,14 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect(sys_get_temp_dir())->toBeWritableDirectory(); + expect(true)->toBeBool(); + expect(0)->not->toBeBool(); }); test('failures', function () { - expect('/random/path/whatever')->toBeWritableDirectory(); + expect(null)->toBeBool(); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect(sys_get_temp_dir())->not->toBeWritableDirectory(); + expect(false)->not->toBeBool(); })->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeCallable.php b/tests/Expect/toBeCallable.php new file mode 100644 index 00000000..2bd8f139 --- /dev/null +++ b/tests/Expect/toBeCallable.php @@ -0,0 +1,18 @@ +toBeCallable(); + expect(null)->not->toBeCallable(); +}); + +test('failures', function () { + $hello = 5; + + expect($hello)->toBeCallable(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(function () { return 42; })->not->toBeCallable(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeExistingDirectory.php b/tests/Expect/toBeFloat.php similarity index 57% rename from tests/Expect/toBeExistingDirectory.php rename to tests/Expect/toBeFloat.php index 6f2eb5f9..69aa2306 100644 --- a/tests/Expect/toBeExistingDirectory.php +++ b/tests/Expect/toBeFloat.php @@ -3,15 +3,14 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - $temp = sys_get_temp_dir(); - - expect($temp)->toBeExistingDirectory(); + expect(1.0)->toBeFloat(); + expect(1)->not->toBeFloat(); }); test('failures', function () { - expect('/random/path/whatever')->toBeExistingDirectory(); + expect(42)->toBeFloat(); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect('.')->not->toBeExistingDirectory(); + expect(log(3))->not->toBeFloat(); })->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeInfinite.php b/tests/Expect/toBeInfinite.php new file mode 100644 index 00000000..ebcb0a36 --- /dev/null +++ b/tests/Expect/toBeInfinite.php @@ -0,0 +1,16 @@ +toBeInfinite(); + expect(log(1))->not->toBeInfinite(); +}); + +test('failures', function () { + expect(asin(2))->toBeInfinite(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(INF)->not->toBeInfinite(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeInstanceOf.php b/tests/Expect/toBeInstanceOf.php new file mode 100644 index 00000000..03b3e881 --- /dev/null +++ b/tests/Expect/toBeInstanceOf.php @@ -0,0 +1,16 @@ +toBeInstanceOf(Exception::class); + expect(new Exception())->not->toBeInstanceOf(RuntimeException::class); +}); + +test('failures', function () { + expect(new Exception())->toBeInstanceOf(RuntimeException::class); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(new Exception())->not->toBeInstanceOf(Exception::class); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeInt.php b/tests/Expect/toBeInt.php new file mode 100644 index 00000000..9eb1b3db --- /dev/null +++ b/tests/Expect/toBeInt.php @@ -0,0 +1,16 @@ +toBeInt(); + expect(42.0)->not->toBeInt(); +}); + +test('failures', function () { + expect(42.0)->toBeInt(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(6 * 7)->not->toBeInt(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeIterable.php b/tests/Expect/toBeIterable.php new file mode 100644 index 00000000..fca23688 --- /dev/null +++ b/tests/Expect/toBeIterable.php @@ -0,0 +1,23 @@ +toBeIterable(); + expect(null)->not->toBeIterable(); +}); + +test('failures', function () { + expect(42)->toBeIterable(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + function gen(): iterable + { + yield 1; + yield 2; + yield 3; + } + + expect(gen())->not->toBeIterable(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeNAN.php b/tests/Expect/toBeNAN.php new file mode 100644 index 00000000..0767f1ad --- /dev/null +++ b/tests/Expect/toBeNAN.php @@ -0,0 +1,16 @@ +toBeNan(); + expect(log(0))->not->toBeNan(); +}); + +test('failures', function () { + expect(1)->toBeNan(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(acos(1.5))->not->toBeNan(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeNull.php b/tests/Expect/toBeNull.php new file mode 100644 index 00000000..2bd7d987 --- /dev/null +++ b/tests/Expect/toBeNull.php @@ -0,0 +1,16 @@ +toBeNull(); + expect('')->not->toBeNull(); +}); + +test('failures', function () { + expect('hello')->toBeNull(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(null)->not->toBeNull(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeNumeric.php b/tests/Expect/toBeNumeric.php new file mode 100644 index 00000000..710ca236 --- /dev/null +++ b/tests/Expect/toBeNumeric.php @@ -0,0 +1,16 @@ +toBeNumeric(); + expect('A')->not->toBeNumeric(); +}); + +test('failures', function () { + expect(null)->toBeNumeric(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(6 * 7)->not->toBeNumeric(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeObject.php b/tests/Expect/toBeObject.php new file mode 100644 index 00000000..e227b4cb --- /dev/null +++ b/tests/Expect/toBeObject.php @@ -0,0 +1,16 @@ + 1])->toBeObject(); + expect(['a' => 1])->not->toBeObject(); +}); + +test('failures', function () { + expect(null)->toBeObject(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect((object) 'ciao')->not->toBeObject(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeResource.php b/tests/Expect/toBeResource.php new file mode 100644 index 00000000..575fabe3 --- /dev/null +++ b/tests/Expect/toBeResource.php @@ -0,0 +1,22 @@ +toBeResource(); + expect(null)->not->toBeResource(); +}); + +test('failures', function () { + expect(null)->toBeResource(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () use ($resource) { + expect($resource)->not->toBeResource(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeScalar.php b/tests/Expect/toBeScalar.php new file mode 100644 index 00000000..236c0e0b --- /dev/null +++ b/tests/Expect/toBeScalar.php @@ -0,0 +1,15 @@ +toBeScalar(); +}); + +test('failures', function () { + expect(null)->toBeScalar(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(42)->not->toBeScalar(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeString.php b/tests/Expect/toBeString.php new file mode 100644 index 00000000..91c31881 --- /dev/null +++ b/tests/Expect/toBeString.php @@ -0,0 +1,16 @@ +toBeString(); + expect(1.1)->not->toBeString(); +}); + +test('failures', function () { + expect(null)->toBeString(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('42')->not->toBeString(); +})->throws(ExpectationFailedException::class); From 832882160fff9a63f95a74004f3be2d41e4932ec Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 14 Jul 2020 23:15:14 +0200 Subject: [PATCH 09/19] feat(expect): updates test suite to use expectation api --- .php_cs | 1 - src/Expectation.php | 76 ++++++------------- src/PendingObjects/TestCall.php | 11 +++ src/globals.php | 2 + tests/.snapshots/success.txt | 41 ++++------ tests/Autoload.php | 4 +- tests/Expect/toBeTrue.php | 15 ++++ tests/Expect/toContainOnly.php | 17 ----- tests/Expect/toContainOnlyInstancesOf.php | 23 ------ tests/Expect/toContainString.php | 16 ---- tests/Expect/toContainStringIgnoringCase.php | 17 ----- tests/Expect/toCount.php | 6 +- tests/Expect/toEqualWithDelta.php | 6 +- tests/Features/AfterAll.php | 4 +- tests/Features/AfterEach.php | 6 +- tests/Features/BeforeAll.php | 4 +- tests/Features/BeforeEach.php | 4 +- tests/Features/Datasets.php | 32 ++++---- tests/Features/Depends.php | 20 ++--- tests/Features/Helpers.php | 7 +- tests/Features/It.php | 4 +- tests/Features/Macro.php | 2 +- tests/Features/PendingHigherOrderTests.php | 11 +-- tests/Features/Test.php | 4 +- tests/Features/TestCycle.php | 8 +- .../SubFolder/CustomTestCaseInSubFolder.php | 2 +- .../SubFolder2/UsesPerFile.php | 2 +- tests/Playground.php | 2 +- tests/Unit/Actions/AddsDefaults.php | 6 +- tests/Unit/Actions/AddsTests.php | 6 +- tests/Unit/Actions/ValidatesConfiguration.php | 2 +- tests/Unit/Plugins/Version.php | 4 +- tests/Unit/Support/Backtrace.php | 2 +- tests/Unit/Support/Container.php | 10 +-- tests/Unit/Support/Reflection.php | 7 +- tests/Visual/SingleTestOrDirectory.php | 22 ++---- tests/Visual/Success.php | 2 +- 37 files changed, 151 insertions(+), 257 deletions(-) create mode 100644 tests/Expect/toBeTrue.php delete mode 100644 tests/Expect/toContainOnly.php delete mode 100644 tests/Expect/toContainOnlyInstancesOf.php delete mode 100644 tests/Expect/toContainString.php delete mode 100644 tests/Expect/toContainStringIgnoringCase.php diff --git a/.php_cs b/.php_cs index 725a3035..d163e603 100644 --- a/.php_cs +++ b/.php_cs @@ -3,7 +3,6 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'bin') - ->in(__DIR__ . DIRECTORY_SEPARATOR . 'compiled') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'scripts') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'stubs') ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') diff --git a/src/Expectation.php b/src/Expectation.php index db123468..0aaf2159 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -62,6 +62,16 @@ final class Expectation return $this; } + /** + * Assert the value is true. + */ + public function toBeTrue(): Expectation + { + Assert::assertTrue($this->value); + + return $this; + } + /** * Assert the value is false. */ @@ -123,54 +133,15 @@ final class Expectation /** * Assert that needles is an element of value. * - * @param mixed $needle + * @param mixed $value */ - public function toContain($needle): Expectation + public function toContain($value): Expectation { - Assert::assertContains($needle, $this->value); - - return $this; - } - - /** - * Assert the value contains only variables of type. - * - * @param mixed $type - */ - public function toContainOnly($type): Expectation - { - Assert::assertContainsOnly($type, $this->value); - - return $this; - } - - /** - * Assert the value contains only instances of $instance. - */ - public function toContainOnlyInstancesOf(string $instance): Expectation - { - Assert::assertContainsOnlyInstancesOf($instance, $this->value); - - return $this; - } - - /** - * Assert that needles is a substring of value. - */ - public function toContainString(string $needle): Expectation - { - Assert::assertStringContainsString($needle, $this->value); - - return $this; - } - - /** - * Assert that needles is a substring of value, ignoring the - * difference in casing. - */ - public function toContainStringIgnoringCase(string $needle): Expectation - { - Assert::assertStringContainsStringIgnoringCase($needle, $this->value); + if (is_string($value)) { + Assert::assertStringContainsString($value, $this->value); + } else { + Assert::assertContains($value, $this->value); + } return $this; } @@ -178,7 +149,7 @@ final class Expectation /** * Assert that $count matches the number of elements of $value. */ - public function toCount(int $count): Expectation + public function toHaveCount(int $count): Expectation { Assert::assertCount($count, $this->value); @@ -234,7 +205,7 @@ final class Expectation * * @param mixed $value */ - public function toEqualWithDelta($value, float $delta): Expectation + public function toBeEqualWithDelta($value, float $delta): Expectation { Assert::assertEqualsWithDelta($value, $this->value, $delta); @@ -254,11 +225,12 @@ final class Expectation /** * Assert that the value is an instance of $value. * - * @param mixed $value + * @param string $class */ - public function toBeInstanceOf($value): Expectation + public function toBeInstanceOf($class): Expectation { - Assert::assertInstanceOf($value, $this->value); + /* @phpstan-ignore-next-line */ + Assert::assertInstanceOf($class, $this->value); return $this; } @@ -384,7 +356,7 @@ final class Expectation } /** - * Assert that the value is NAN. + * Assert that the value is null. */ public function toBeNull(): Expectation { diff --git a/src/PendingObjects/TestCall.php b/src/PendingObjects/TestCall.php index e0b7f1c4..a6c9b499 100644 --- a/src/PendingObjects/TestCall.php +++ b/src/PendingObjects/TestCall.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest\PendingObjects; use Closure; +use Pest\Expectation; use Pest\Factories\TestCaseFactory; use Pest\Support\Backtrace; use Pest\Support\NullClosure; @@ -84,6 +85,16 @@ final class TestCall return $this; } + /** + * Creates a new expectation. + * + * @param mixed $value the Value + */ + public function expect($value): Expectation + { + return expect($value); + } + /** * Sets the test depends. */ diff --git a/src/globals.php b/src/globals.php index 07ec9d6e..59e5e784 100644 --- a/src/globals.php +++ b/src/globals.php @@ -108,6 +108,8 @@ function afterAll(Closure $closure = null): void /** * Creates a new expectation. + * + * @param mixed $value the Value */ function expect($value): Expectation { diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 916c0d6c..6f9ce702 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -110,31 +110,16 @@ PASS Tests\Expect\toBeString ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeTrue + ✓ strict comparisons + ✓ failures ✓ not failures PASS Tests\Expect\toContain ✓ passes ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainOnly - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainOnlyInstancesOf - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainString - ✓ is case sensitive - ✓ failures - ✓ not failures - - PASS Tests\Expect\toContainStringIgnoringCase - ✓ ignore difference in casing - ✓ failures ✓ not failures PASS Tests\Expect\toCount @@ -231,9 +216,9 @@ PASS Tests\Features\HigherOrderTests ✓ it proxies calls to object - PASS Tests\Features\It + WARN Tests\Features\It ✓ it is a test - ✓ it is a higher order message test + ! it is a higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4 PASS Tests\Features\Macro ✓ it can call chained macro method @@ -243,8 +228,8 @@ ✓ it has bar PASS Tests\Features\PendingHigherOrderTests - ✓ get 'foo' → get 'bar' → assertTrue true - ✓ get 'foo' → assertTrue true + ✓ get 'foo' → get 'bar' + ✓ get 'foo' WARN Tests\Features\Skip ✓ it do not skips @@ -255,9 +240,9 @@ ✓ it do not skips with falsy closure condition - it skips with condition and message → skipped because foo - PASS Tests\Features\Test + WARN Tests\Features\Test ✓ a test - ✓ higher order message test + ! higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4 PASS Tests\Fixtures\DirectoryWithTests\ExampleTest ✓ it example 1 @@ -327,5 +312,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 192 passed - Time: 5.20s + Tests: 2 risked, 6 skipped, 181 passed + Time: 5.72s diff --git a/tests/Autoload.php b/tests/Autoload.php index 9283dbad..1e181ad2 100644 --- a/tests/Autoload.php +++ b/tests/Autoload.php @@ -8,7 +8,7 @@ trait PluginTrait { public function assertPluginTraitGotRegistered(): void { - assertTrue(true); + $this->assertTrue(true); } } @@ -16,7 +16,7 @@ trait SecondPluginTrait { public function assertSecondPluginTraitGotRegistered(): void { - assertTrue(true); + $this->assertTrue(true); } } diff --git a/tests/Expect/toBeTrue.php b/tests/Expect/toBeTrue.php new file mode 100644 index 00000000..8e998f9b --- /dev/null +++ b/tests/Expect/toBeTrue.php @@ -0,0 +1,15 @@ +toBeTrue(); +}); + +test('failures', function () { + expect('')->toBeTrue(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(false)->not->toBe(false); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainOnly.php b/tests/Expect/toContainOnly.php deleted file mode 100644 index 2e9fecfe..00000000 --- a/tests/Expect/toContainOnly.php +++ /dev/null @@ -1,17 +0,0 @@ -toContainOnly('int'); - expect(['hello', 'world'])->toContainOnly('string'); -}); - -test('failures', function () { - expect([1, 2, '3'])->toContainOnly('string'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect([1, 2, 3])->not->toContainOnly('int'); - expect(['hello', 'world'])->not->toContainOnly('string'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainOnlyInstancesOf.php b/tests/Expect/toContainOnlyInstancesOf.php deleted file mode 100644 index fdda161b..00000000 --- a/tests/Expect/toContainOnlyInstancesOf.php +++ /dev/null @@ -1,23 +0,0 @@ -toContainOnlyInstancesOf(Expectation::class); -}); - -test('failures', function () { - $expected = [new Expectation('whatever')]; - - expect($expected)->toContainOnlyInstancesOf(AddsTests::class); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - $expected = [new Expectation('whatever')]; - - expect($expected)->not->toContainOnlyInstancesOf(Expectation::class); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainString.php b/tests/Expect/toContainString.php deleted file mode 100644 index 03f55b69..00000000 --- a/tests/Expect/toContainString.php +++ /dev/null @@ -1,16 +0,0 @@ -toContainString('world'); - expect('hello world')->not->toContainString('World'); -}); - -test('failures', function () { - expect('hello world')->toContainString('Hello'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('hello world')->not->toContainString('hello'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContainStringIgnoringCase.php b/tests/Expect/toContainStringIgnoringCase.php deleted file mode 100644 index fc5e1081..00000000 --- a/tests/Expect/toContainStringIgnoringCase.php +++ /dev/null @@ -1,17 +0,0 @@ -toContainStringIgnoringCase('world'); - expect('hello world')->toContainStringIgnoringCase('World'); -}); - -test('failures', function () { - expect('hello world')->toContainStringIgnoringCase('hi'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('hello world')->not->toContainStringIgnoringCase('Hello'); - expect('hello world')->not->toContainStringIgnoringCase('hello'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toCount.php b/tests/Expect/toCount.php index 6e8d5fcd..a1948260 100644 --- a/tests/Expect/toCount.php +++ b/tests/Expect/toCount.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect([1, 2, 3])->toCount(3); + expect([1, 2, 3])->toHaveCount(3); }); test('failures', function () { - expect([1, 2, 3])->toCount(4); + expect([1, 2, 3])->toHaveCount(4); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect([1, 2, 3])->not->toCount(3); + expect([1, 2, 3])->not->toHaveCount(3); })->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqualWithDelta.php b/tests/Expect/toEqualWithDelta.php index bb78b86d..3faab6e2 100644 --- a/tests/Expect/toEqualWithDelta.php +++ b/tests/Expect/toEqualWithDelta.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect(1.0)->toEqualWithDelta(1.3, .4); + expect(1.0)->toBeEqualWithDelta(1.3, .4); }); test('failures', function () { - expect(1.0)->toEqualWithDelta(1.5, .1); + expect(1.0)->toBeEqualWithDelta(1.5, .1); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect(1.0)->not->toEqualWithDelta(1.6, .7); + expect(1.0)->not->toBeEqualWithDelta(1.6, .7); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/AfterAll.php b/tests/Features/AfterAll.php index e78e12a5..1b66792e 100644 --- a/tests/Features/AfterAll.php +++ b/tests/Features/AfterAll.php @@ -8,8 +8,8 @@ afterAll(function () use ($file) { test('deletes file after all', function () use ($file) { file_put_contents($file, 'foo'); - assertFileExists($file); + $this->assertFileExists($file); register_shutdown_function(function () use ($file) { - assertFileNotExists($file); + $this->assertFileNotExists($file); }); }); diff --git a/tests/Features/AfterEach.php b/tests/Features/AfterEach.php index 4563e717..5c223833 100644 --- a/tests/Features/AfterEach.php +++ b/tests/Features/AfterEach.php @@ -11,10 +11,10 @@ afterEach(function () use ($state) { }); it('does not get executed before the test', function () { - assertFalse(property_exists($this->state, 'bar')); + expect(property_exists($this->state, 'bar'))->toBeFalse(); }); it('gets executed after the test', function () { - assertTrue(property_exists($this->state, 'bar')); - assertEquals(2, $this->state->bar); + expect(property_exists($this->state, 'bar'))->toBeTrue(); + expect($this->state->bar)->toBe(2); }); diff --git a/tests/Features/BeforeAll.php b/tests/Features/BeforeAll.php index 4095e68a..e8e458bc 100644 --- a/tests/Features/BeforeAll.php +++ b/tests/Features/BeforeAll.php @@ -8,11 +8,11 @@ beforeAll(function () use ($foo) { }); it('gets executed before tests', function () use ($foo) { - assertEquals($foo->bar, 1); + expect($foo->bar)->toBe(1); $foo->bar = 'changed'; }); it('do not get executed before each test', function () use ($foo) { - assertEquals($foo->bar, 'changed'); + expect($foo->bar)->toBe('changed'); }); diff --git a/tests/Features/BeforeEach.php b/tests/Features/BeforeEach.php index 94c5adc3..a2e70d61 100644 --- a/tests/Features/BeforeEach.php +++ b/tests/Features/BeforeEach.php @@ -5,11 +5,11 @@ beforeEach(function () { }); it('gets executed before each test', function () { - assertEquals($this->bar, 2); + expect($this->bar)->toBe(2); $this->bar = 'changed'; }); it('gets executed before each test once again', function () { - assertEquals($this->bar, 2); + expect($this->bar)->toBe(2); }); diff --git a/tests/Features/Datasets.php b/tests/Features/Datasets.php index 35764433..81f41b34 100644 --- a/tests/Features/Datasets.php +++ b/tests/Features/Datasets.php @@ -23,13 +23,13 @@ it('sets closures', function () { yield [1]; }); - assertEquals([[1]], iterator_to_array(Datasets::get('foo')())); + expect(iterator_to_array(Datasets::get('foo')()))->toBe([[1]]); }); it('sets arrays', function () { Datasets::set('bar', [[2]]); - assertEquals([[2]], Datasets::get('bar')); + expect(Datasets::get('bar'))->toBe([[2]]); }); it('gets bound to test case object', function () { @@ -37,7 +37,7 @@ it('gets bound to test case object', function () { })->with([['a'], ['b']]); test('it truncates the description', function () { - assertTrue(true); + expect(true)->toBe(true); // it gets tested by the integration test })->with([str_repeat('Fooo', 10000000)]); @@ -48,51 +48,51 @@ $datasets = [[1], [2]]; test('lazy datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect(in_array([$text], $datasets))->toBe(true); })->with($datasets); test('lazy datasets did the job right', function () use ($state) { - assertEquals('12', $state->text); + expect($state->text)->toBe('12'); }); $state->text = ''; test('eager datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with(function () use ($datasets) { return $datasets; }); test('eager datasets did the job right', function () use ($state) { - assertEquals('1212', $state->text); + expect($state->text)->toBe('1212'); }); test('lazy registered datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with('numbers.array'); test('lazy registered datasets did the job right', function () use ($state) { - assertEquals('121212', $state->text); + expect($state->text)->toBe('121212'); }); test('eager registered datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with('numbers.closure'); test('eager registered datasets did the job right', function () use ($state) { - assertEquals('12121212', $state->text); + expect($state->text)->toBe('12121212'); }); test('eager wrapped registered datasets', function ($text) use ($state, $datasets) { $state->text .= $text; - assertTrue(in_array([$text], $datasets)); + expect($datasets)->toContain([$text]); })->with('numbers.closure.wrapped'); test('eager registered wrapped datasets did the job right', function () use ($state) { - assertEquals('1212121212', $state->text); + expect($state->text)->toBe('1212121212'); }); class Bar @@ -105,13 +105,13 @@ $namedDatasets = [ ]; test('lazy named datasets', function ($text) use ($state, $datasets) { - assertTrue(true); + expect(true)->toBeTrue(); })->with($namedDatasets); $counter = 0; it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter) { - assertTrue(true); + expect(true)->toBeTrue(); $counter++; })->with([ ['Name 1', new Plugin(), true], @@ -123,5 +123,5 @@ it('creates unique test case names', function (string $name, Plugin $plugin, boo ]); it('creates unique test case names - count', function () use (&$counter) { - assertEquals(6, $counter); + expect($counter)->toBe(6); }); diff --git a/tests/Features/Depends.php b/tests/Features/Depends.php index 0e7ed5ea..edab5956 100644 --- a/tests/Features/Depends.php +++ b/tests/Features/Depends.php @@ -3,38 +3,32 @@ $runCounter = 0; test('first', function () use (&$runCounter) { - assertTrue(true); + expect(true)->toBeTrue(); $runCounter++; return 'first'; }); test('second', function () use (&$runCounter) { - assertTrue(true); + expect(true)->toBeTrue(); $runCounter++; return 'second'; }); test('depends', function () { - assertEquals( - ['first', 'second'], - func_get_args() - ); + expect(func_get_args())->toBe(['first', 'second']); })->depends('first', 'second'); test('depends with ...params', function (string ...$params) { - assertEquals( - ['first', 'second'], - $params - ); + expect(func_get_args())->toBe($params); })->depends('first', 'second'); test('depends with defined arguments', function (string $first, string $second) { - assertEquals('first', $first); - assertEquals('second', $second); + expect($first)->toBe('first'); + expect($second)->toBe('second'); })->depends('first', 'second'); test('depends run test only once', function () use (&$runCounter) { - assertEquals(2, $runCounter); + expect($runCounter)->toBe(2); })->depends('first', 'second'); diff --git a/tests/Features/Helpers.php b/tests/Features/Helpers.php index 24377e00..163ede9d 100644 --- a/tests/Features/Helpers.php +++ b/tests/Features/Helpers.php @@ -7,7 +7,7 @@ function addUser() it('can set/get properties on $this', function () { addUser(); - assertEquals('nuno', $this->user); + expect($this->user)->toBe('nuno'); }); it('throws error if property do not exist', function () { @@ -27,15 +27,14 @@ function mockUser() $mock = test()->createMock(User::class); $mock->method('getName') - ->willReturn('maduro'); + ->willReturn('maduro'); return $mock; } it('allows to call underlying protected/private methods', function () { $user = mockUser(); - - assertEquals('maduro', $user->getName()); + expect($user->getName())->toBe('maduro'); }); it('throws error if method do not exist', function () { diff --git a/tests/Features/It.php b/tests/Features/It.php index 9ab6e384..384e12bd 100644 --- a/tests/Features/It.php +++ b/tests/Features/It.php @@ -1,7 +1,7 @@ 'foo']); + $this->assertArrayHasKey('key', ['key' => 'foo']); }); -it('is a higher order message test')->assertTrue(true); +it('is a higher order message test')->expect(true)->toBeTrue(); diff --git a/tests/Features/Macro.php b/tests/Features/Macro.php index fa9f63ee..c0893355 100644 --- a/tests/Features/Macro.php +++ b/tests/Features/Macro.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; uses(Macroable::class); beforeEach()->macro('bar', function () { - assertInstanceOf(TestCase::class, $this); + expect($this)->toBeInstanceOf(TestCase::class); }); it('can call chained macro method')->bar(); diff --git a/tests/Features/PendingHigherOrderTests.php b/tests/Features/PendingHigherOrderTests.php index de178c51..cf68dcc6 100644 --- a/tests/Features/PendingHigherOrderTests.php +++ b/tests/Features/PendingHigherOrderTests.php @@ -1,11 +1,12 @@ not->toBeEmpty(); return $this; } } -get('foo')->get('bar')->assertTrue(true); -get('foo')->assertTrue(true); +get('foo')->get('bar')->expect(true)->toBeTrue(); +get('foo')->expect(true)->toBeTrue(); diff --git a/tests/Features/Test.php b/tests/Features/Test.php index d2e53ed0..e3334305 100644 --- a/tests/Features/Test.php +++ b/tests/Features/Test.php @@ -1,7 +1,7 @@ 'foo']); + $this->assertArrayHasKey('key', ['key' => 'foo']); }); -test('higher order message test')->assertTrue(true); +test('higher order message test')->expect(true)->toBeTrue(); diff --git a/tests/Features/TestCycle.php b/tests/Features/TestCycle.php index d941dcf2..efca9588 100644 --- a/tests/Features/TestCycle.php +++ b/tests/Features/TestCycle.php @@ -20,8 +20,8 @@ afterAll(function () { }); register_shutdown_function(function () use ($foo) { - assertFalse($foo->beforeAll); - assertFalse($foo->beforeEach); - assertFalse($foo->afterEach); - assertFalse($foo->afterAll); + expect($foo->beforeAll)->toBeFalse(); + expect($foo->beforeEach)->toBeFalse(); + expect($foo->afterEach)->toBeFalse(); + expect($foo->afterAll)->toBeFalse(); }); diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php index 2cd2999d..ee6b1489 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php @@ -10,6 +10,6 @@ class CustomTestCaseInSubFolder extends TestCase { public function assertCustomInSubFolderTrue() { - assertTrue(true); + $this->assertTrue(true); } } diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php index e0673174..8e582bcf 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php @@ -12,7 +12,7 @@ class MyCustomClass extends PHPUnit\Framework\TestCase { public function assertTrueIsTrue() { - assertTrue(true); + $this->assertTrue(true); } } diff --git a/tests/Playground.php b/tests/Playground.php index e24277b1..be30ae7d 100644 --- a/tests/Playground.php +++ b/tests/Playground.php @@ -1,5 +1,5 @@ toBeTrue(); }); diff --git a/tests/Unit/Actions/AddsDefaults.php b/tests/Unit/Actions/AddsDefaults.php index 7a55adc5..eef7b027 100644 --- a/tests/Unit/Actions/AddsDefaults.php +++ b/tests/Unit/Actions/AddsDefaults.php @@ -7,14 +7,14 @@ use PHPUnit\TextUI\DefaultResultPrinter; it('sets defaults', function () { $arguments = AddsDefaults::to(['bar' => 'foo']); - assertInstanceOf(Printer::class, $arguments['printer']); - assertEquals($arguments['bar'], 'foo'); + expect($arguments['printer'])->toBeInstanceOf(Printer::class); + expect($arguments['bar'])->toBe('foo'); }); it('does not override options', function () { $defaultResultPrinter = new DefaultResultPrinter(); - assertEquals(AddsDefaults::to(['printer' => $defaultResultPrinter]), [ + expect(AddsDefaults::to(['printer' => $defaultResultPrinter]))->tobe([ 'printer' => $defaultResultPrinter, ]); }); diff --git a/tests/Unit/Actions/AddsTests.php b/tests/Unit/Actions/AddsTests.php index 925e3574..9f1beec0 100644 --- a/tests/Unit/Actions/AddsTests.php +++ b/tests/Unit/Actions/AddsTests.php @@ -16,10 +16,10 @@ test('default php unit tests', function () { $phpUnitTestCase = new class() extends PhpUnitTestCase { }; $testSuite->addTest($phpUnitTestCase); - assertCount(1, $testSuite->tests()); + expect($testSuite->tests())->toHaveCount(1); AddsTests::to($testSuite, new \Pest\TestSuite(getcwd())); - assertCount(1, $testSuite->tests()); + expect($testSuite->tests())->toHaveCount(1); }); it('removes warnings', function () use ($pestTestCase) { @@ -28,5 +28,5 @@ it('removes warnings', function () use ($pestTestCase) { $testSuite->addTest($warningTestCase); AddsTests::to($testSuite, new \Pest\TestSuite(getcwd())); - assertCount(0, $testSuite->tests()); + expect($testSuite->tests())->toHaveCount(0); }); diff --git a/tests/Unit/Actions/ValidatesConfiguration.php b/tests/Unit/Actions/ValidatesConfiguration.php index 24edc4f0..a26a4105 100644 --- a/tests/Unit/Actions/ValidatesConfiguration.php +++ b/tests/Unit/Actions/ValidatesConfiguration.php @@ -38,5 +38,5 @@ it('do not throws exception when `process isolation` is false', function () { 'configuration' => $filename, ]); - assertTrue(true); + expect(true)->toBeTrue(); }); diff --git a/tests/Unit/Plugins/Version.php b/tests/Unit/Plugins/Version.php index 0bd19052..0bd5feb7 100644 --- a/tests/Unit/Plugins/Version.php +++ b/tests/Unit/Plugins/Version.php @@ -8,7 +8,7 @@ it('outputs the version when --version is used', function () { $plugin = new Version($output); $plugin->handleArguments(['foo', '--version']); - assertStringContainsString('Pest 0.2.2', $output->fetch()); + expect($output->fetch())->toContain('Pest 0.2.2'); }); it('do not outputs version when --version is not used', function () { @@ -16,5 +16,5 @@ it('do not outputs version when --version is not used', function () { $plugin = new Version($output); $plugin->handleArguments(['foo', 'bar']); - assertEquals('', $output->fetch()); + expect($output->fetch())->toBe(''); }); diff --git a/tests/Unit/Support/Backtrace.php b/tests/Unit/Support/Backtrace.php index 55886512..6dba0ed5 100644 --- a/tests/Unit/Support/Backtrace.php +++ b/tests/Unit/Support/Backtrace.php @@ -7,5 +7,5 @@ it('gets file name from called file', function () { return Backtrace::file(); }; - assertEquals(__FILE__, $a()); + expect($a())->toBe(__FILE__); }); diff --git a/tests/Unit/Support/Container.php b/tests/Unit/Support/Container.php index 13a369ff..f42ba030 100644 --- a/tests/Unit/Support/Container.php +++ b/tests/Unit/Support/Container.php @@ -15,32 +15,32 @@ it('exists') it('gets an instance', function () { $this->container->add(Container::class, $this->container); - assertSame($this->container, $this->container->get(Container::class)); + expect($this->container->get(Container::class))->toBe($this->container); }); test('autowire', function () { - assertInstanceOf(Container::class, $this->container->get(Container::class)); + expect($this->container->get(Container::class))->toBeInstanceOf(Container::class); }); it('creates an instance and resolves parameters', function () { $this->container->add(Container::class, $this->container); $instance = $this->container->get(ClassWithDependency::class); - assertInstanceOf(ClassWithDependency::class, $instance); + expect($instance)->toBeInstanceOf(ClassWithDependency::class); }); it('creates an instance and resolves also sub parameters', function () { $this->container->add(Container::class, $this->container); $instance = $this->container->get(ClassWithSubDependency::class); - assertInstanceOf(ClassWithSubDependency::class, $instance); + expect($instance)->toBeInstanceOf(ClassWithSubDependency::class); }); it('can resolve builtin value types', function () { $this->container->add('rootPath', getcwd()); $instance = $this->container->get(TestSuite::class); - assertInstanceOf(TestSuite::class, $instance); + expect($instance)->toBeInstanceOf(TestSuite::class); }); it('cannot resolve a parameter without type', function () { diff --git a/tests/Unit/Support/Reflection.php b/tests/Unit/Support/Reflection.php index 56d5515a..7ad76b0d 100644 --- a/tests/Unit/Support/Reflection.php +++ b/tests/Unit/Support/Reflection.php @@ -3,9 +3,10 @@ use Pest\Support\Reflection; it('gets file name from closure', function () { - $fileName = Reflection::getFileNameFromClosure(function () {}); + $fileName = Reflection::getFileNameFromClosure(function () { + }); - assertEquals(__FILE__, $fileName); + expect($fileName)->toBe(__FILE__); }); it('gets property values', function () { @@ -15,5 +16,5 @@ it('gets property values', function () { $value = Reflection::getPropertyValue($class, 'foo'); - assertEquals('bar', $value); + expect($value)->toBe('bar'); }); diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 893caf3a..ef5ab6fa 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -10,7 +10,7 @@ $run = function (string $target, $decorated = false) { return $decorated ? $process->getOutput() : preg_replace('#\\x1b[[][^A-Za-z]*[A-Za-z]#', '', $process->getOutput()); }; -$snapshot = function ($name) { +$snapshot = function ($name) { $testsPath = dirname(__DIR__); return file_get_contents(implode(DIRECTORY_SEPARATOR, [ @@ -21,23 +21,15 @@ $snapshot = function ($name) { }; test('allows to run a single test', function () use ($run, $snapshot) { - assertStringContainsString( - $snapshot('allows-to-run-a-single-test'), - $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php')); + expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'))->toContain($snapshot('allows-to-run-a-single-test')); })->skip(PHP_OS_FAMILY === 'Windows'); test('allows to run a directory', function () use ($run, $snapshot) { - assertStringContainsString( - $snapshot('allows-to-run-a-directory'), - $run('tests/Fixtures') - ); + expect($run('tests/Fixtures'))->toContain($snapshot('allows-to-run-a-directory')); })->skip(PHP_OS_FAMILY === 'Windows'); it('has ascii chars', function () use ($run, $snapshot) { - assertStringContainsString( - $snapshot('has-ascii-chars'), - $run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true) - ); + expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php', true))->toContain($snapshot('has-ascii-chars')); })->skip(PHP_OS_FAMILY === 'Windows'); it('disable decorating printer when colors is set to never', function () use ($snapshot) { @@ -49,9 +41,5 @@ it('disable decorating printer when colors is set to never', function () use ($s ], dirname(__DIR__, 2)); $process->run(); $output = $process->getOutput(); - - assertStringContainsString( - $snapshot('disable-decorating-printer'), - $output - ); + expect($output)->toContain($snapshot('disable-decorating-printer')); })->skip(PHP_OS_FAMILY === 'Windows'); diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index 97cbee6a..a4f5fae6 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -22,7 +22,7 @@ test('visual snapshot of test suite on success', function () { $output = explode("\n", $output()); array_pop($output); array_pop($output); - assertStringContainsString(implode("\n", $output), file_get_contents($snapshot)); + expect(file_get_contents($snapshot))->toContain(implode("\n", $output)); } })->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')) ->skip(PHP_OS_FAMILY === 'Windows'); From ab017e17e2c12a995fadf8e17000439795dacf4b Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 14 Jul 2020 23:15:29 +0200 Subject: [PATCH 10/19] feat(expect): removes assertions api --- compiled/.gitkeep | 0 compiled/globals.php | 1926 ------------------------------------------ composer.json | 4 +- 3 files changed, 1 insertion(+), 1929 deletions(-) delete mode 100644 compiled/.gitkeep delete mode 100644 compiled/globals.php diff --git a/compiled/.gitkeep b/compiled/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/compiled/globals.php b/compiled/globals.php deleted file mode 100644 index 9f82a842..00000000 --- a/compiled/globals.php +++ /dev/null @@ -1,1926 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ -use PHPUnit\Framework\Assert; -use PHPUnit\Framework\Constraint\Constraint; - -/** - * Asserts that an array has a specified key. - * - * @param int|string $key - * @param array|\ArrayAccess $array - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertArrayHasKey - */ -function assertArrayHasKey($key, $array, string $message = ''): void -{ - Assert::assertArrayHasKey(...\func_get_args()); -} - -/** - * Asserts that an array does not have a specified key. - * - * @param int|string $key - * @param array|\ArrayAccess $array - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertArrayNotHasKey - */ -function assertArrayNotHasKey($key, $array, string $message = ''): void -{ - Assert::assertArrayNotHasKey(...\func_get_args()); -} - -/** - * Asserts that a haystack contains a needle. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertContains - */ -function assertContains($needle, iterable $haystack, string $message = ''): void -{ - Assert::assertContains(...\func_get_args()); -} - -function assertContainsEquals($needle, iterable $haystack, string $message = ''): void -{ - Assert::assertContainsEquals(...\func_get_args()); -} - -/** - * Asserts that a haystack does not contain a needle. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertNotContains - */ -function assertNotContains($needle, iterable $haystack, string $message = ''): void -{ - Assert::assertNotContains(...\func_get_args()); -} - -function assertNotContainsEquals($needle, iterable $haystack, string $message = ''): void -{ - Assert::assertNotContainsEquals(...\func_get_args()); -} - -/** - * Asserts that a haystack contains only values of a given type. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertContainsOnly - */ -function assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void -{ - Assert::assertContainsOnly(...\func_get_args()); -} - -/** - * Asserts that a haystack contains only instances of a given class name. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertContainsOnlyInstancesOf - */ -function assertContainsOnlyInstancesOf(string $className, iterable $haystack, string $message = ''): void -{ - Assert::assertContainsOnlyInstancesOf(...\func_get_args()); -} - -/** - * Asserts that a haystack does not contain only values of a given type. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertNotContainsOnly - */ -function assertNotContainsOnly(string $type, iterable $haystack, ?bool $isNativeType = null, string $message = ''): void -{ - Assert::assertNotContainsOnly(...\func_get_args()); -} - -/** - * Asserts the number of elements of an array, Countable or Traversable. - * - * @param \Countable|iterable $haystack - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertCount - */ -function assertCount(int $expectedCount, $haystack, string $message = ''): void -{ - Assert::assertCount(...\func_get_args()); -} - -/** - * Asserts the number of elements of an array, Countable or Traversable. - * - * @param \Countable|iterable $haystack - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertNotCount - */ -function assertNotCount(int $expectedCount, $haystack, string $message = ''): void -{ - Assert::assertNotCount(...\func_get_args()); -} - -/** - * Asserts that two variables are equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertEquals - */ -function assertEquals($expected, $actual, string $message = ''): void -{ - Assert::assertEquals(...\func_get_args()); -} - -/** - * Asserts that two variables are equal (canonicalizing). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertEqualsCanonicalizing - */ -function assertEqualsCanonicalizing($expected, $actual, string $message = ''): void -{ - Assert::assertEqualsCanonicalizing(...\func_get_args()); -} - -/** - * Asserts that two variables are equal (ignoring case). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertEqualsIgnoringCase - */ -function assertEqualsIgnoringCase($expected, $actual, string $message = ''): void -{ - Assert::assertEqualsIgnoringCase(...\func_get_args()); -} - -/** - * Asserts that two variables are equal (with delta). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertEqualsWithDelta - */ -function assertEqualsWithDelta($expected, $actual, float $delta, string $message = ''): void -{ - Assert::assertEqualsWithDelta(...\func_get_args()); -} - -/** - * Asserts that two variables are not equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertNotEquals - */ -function assertNotEquals($expected, $actual, string $message = ''): void -{ - Assert::assertNotEquals(...\func_get_args()); -} - -/** - * Asserts that two variables are not equal (canonicalizing). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertNotEqualsCanonicalizing - */ -function assertNotEqualsCanonicalizing($expected, $actual, string $message = ''): void -{ - Assert::assertNotEqualsCanonicalizing(...\func_get_args()); -} - -/** - * Asserts that two variables are not equal (ignoring case). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertNotEqualsIgnoringCase - */ -function assertNotEqualsIgnoringCase($expected, $actual, string $message = ''): void -{ - Assert::assertNotEqualsIgnoringCase(...\func_get_args()); -} - -/** - * Asserts that two variables are not equal (with delta). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertNotEqualsWithDelta - */ -function assertNotEqualsWithDelta($expected, $actual, float $delta, string $message = ''): void -{ - Assert::assertNotEqualsWithDelta(...\func_get_args()); -} - -/** - * Asserts that a variable is empty. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert empty $actual - * - * @see Assert::assertEmpty - */ -function assertEmpty($actual, string $message = ''): void -{ - Assert::assertEmpty(...\func_get_args()); -} - -/** - * Asserts that a variable is not empty. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !empty $actual - * - * @see Assert::assertNotEmpty - */ -function assertNotEmpty($actual, string $message = ''): void -{ - Assert::assertNotEmpty(...\func_get_args()); -} - -/** - * Asserts that a value is greater than another value. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertGreaterThan - */ -function assertGreaterThan($expected, $actual, string $message = ''): void -{ - Assert::assertGreaterThan(...\func_get_args()); -} - -/** - * Asserts that a value is greater than or equal to another value. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertGreaterThanOrEqual - */ -function assertGreaterThanOrEqual($expected, $actual, string $message = ''): void -{ - Assert::assertGreaterThanOrEqual(...\func_get_args()); -} - -/** - * Asserts that a value is smaller than another value. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertLessThan - */ -function assertLessThan($expected, $actual, string $message = ''): void -{ - Assert::assertLessThan(...\func_get_args()); -} - -/** - * Asserts that a value is smaller than or equal to another value. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertLessThanOrEqual - */ -function assertLessThanOrEqual($expected, $actual, string $message = ''): void -{ - Assert::assertLessThanOrEqual(...\func_get_args()); -} - -/** - * Asserts that the contents of one file is equal to the contents of another - * file. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileEquals - */ -function assertFileEquals(string $expected, string $actual, string $message = ''): void -{ - Assert::assertFileEquals(...\func_get_args()); -} - -/** - * Asserts that the contents of one file is equal to the contents of another - * file (canonicalizing). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileEqualsCanonicalizing - */ -function assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void -{ - Assert::assertFileEqualsCanonicalizing(...\func_get_args()); -} - -/** - * Asserts that the contents of one file is equal to the contents of another - * file (ignoring case). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileEqualsIgnoringCase - */ -function assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void -{ - Assert::assertFileEqualsIgnoringCase(...\func_get_args()); -} - -/** - * Asserts that the contents of one file is not equal to the contents of - * another file. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileNotEquals - */ -function assertFileNotEquals(string $expected, string $actual, string $message = ''): void -{ - Assert::assertFileNotEquals(...\func_get_args()); -} - -/** - * Asserts that the contents of one file is not equal to the contents of another - * file (canonicalizing). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileNotEqualsCanonicalizing - */ -function assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void -{ - Assert::assertFileNotEqualsCanonicalizing(...\func_get_args()); -} - -/** - * Asserts that the contents of one file is not equal to the contents of another - * file (ignoring case). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileNotEqualsIgnoringCase - */ -function assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void -{ - Assert::assertFileNotEqualsIgnoringCase(...\func_get_args()); -} - -/** - * Asserts that the contents of a string is equal - * to the contents of a file. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringEqualsFile - */ -function assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void -{ - Assert::assertStringEqualsFile(...\func_get_args()); -} - -/** - * Asserts that the contents of a string is equal - * to the contents of a file (canonicalizing). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringEqualsFileCanonicalizing - */ -function assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void -{ - Assert::assertStringEqualsFileCanonicalizing(...\func_get_args()); -} - -/** - * Asserts that the contents of a string is equal - * to the contents of a file (ignoring case). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringEqualsFileIgnoringCase - */ -function assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void -{ - Assert::assertStringEqualsFileIgnoringCase(...\func_get_args()); -} - -/** - * Asserts that the contents of a string is not equal - * to the contents of a file. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringNotEqualsFile - */ -function assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void -{ - Assert::assertStringNotEqualsFile(...\func_get_args()); -} - -/** - * Asserts that the contents of a string is not equal - * to the contents of a file (canonicalizing). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringNotEqualsFileCanonicalizing - */ -function assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void -{ - Assert::assertStringNotEqualsFileCanonicalizing(...\func_get_args()); -} - -/** - * Asserts that the contents of a string is not equal - * to the contents of a file (ignoring case). - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringNotEqualsFileIgnoringCase - */ -function assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void -{ - Assert::assertStringNotEqualsFileIgnoringCase(...\func_get_args()); -} - -/** - * Asserts that a file/dir is readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertIsReadable - */ -function assertIsReadable(string $filename, string $message = ''): void -{ - Assert::assertIsReadable(...\func_get_args()); -} - -/** - * Asserts that a file/dir exists and is not readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertIsNotReadable - */ -function assertIsNotReadable(string $filename, string $message = ''): void -{ - Assert::assertIsNotReadable(...\func_get_args()); -} - -/** - * Asserts that a file/dir exists and is not readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4062 - * @see Assert::assertNotIsReadable - */ -function assertNotIsReadable(string $filename, string $message = ''): void -{ - Assert::assertNotIsReadable(...\func_get_args()); -} - -/** - * Asserts that a file/dir exists and is writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertIsWritable - */ -function assertIsWritable(string $filename, string $message = ''): void -{ - Assert::assertIsWritable(...\func_get_args()); -} - -/** - * Asserts that a file/dir exists and is not writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertIsNotWritable - */ -function assertIsNotWritable(string $filename, string $message = ''): void -{ - Assert::assertIsNotWritable(...\func_get_args()); -} - -/** - * Asserts that a file/dir exists and is not writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4065 - * @see Assert::assertNotIsWritable - */ -function assertNotIsWritable(string $filename, string $message = ''): void -{ - Assert::assertNotIsWritable(...\func_get_args()); -} - -/** - * Asserts that a directory exists. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertDirectoryExists - */ -function assertDirectoryExists(string $directory, string $message = ''): void -{ - Assert::assertDirectoryExists(...\func_get_args()); -} - -/** - * Asserts that a directory does not exist. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertDirectoryDoesNotExist - */ -function assertDirectoryDoesNotExist(string $directory, string $message = ''): void -{ - Assert::assertDirectoryDoesNotExist(...\func_get_args()); -} - -/** - * Asserts that a directory does not exist. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4068 - * @see Assert::assertDirectoryNotExists - */ -function assertDirectoryNotExists(string $directory, string $message = ''): void -{ - Assert::assertDirectoryNotExists(...\func_get_args()); -} - -/** - * Asserts that a directory exists and is readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertDirectoryIsReadable - */ -function assertDirectoryIsReadable(string $directory, string $message = ''): void -{ - Assert::assertDirectoryIsReadable(...\func_get_args()); -} - -/** - * Asserts that a directory exists and is not readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertDirectoryIsNotReadable - */ -function assertDirectoryIsNotReadable(string $directory, string $message = ''): void -{ - Assert::assertDirectoryIsNotReadable(...\func_get_args()); -} - -/** - * Asserts that a directory exists and is not readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4071 - * @see Assert::assertDirectoryNotIsReadable - */ -function assertDirectoryNotIsReadable(string $directory, string $message = ''): void -{ - Assert::assertDirectoryNotIsReadable(...\func_get_args()); -} - -/** - * Asserts that a directory exists and is writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertDirectoryIsWritable - */ -function assertDirectoryIsWritable(string $directory, string $message = ''): void -{ - Assert::assertDirectoryIsWritable(...\func_get_args()); -} - -/** - * Asserts that a directory exists and is not writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertDirectoryIsNotWritable - */ -function assertDirectoryIsNotWritable(string $directory, string $message = ''): void -{ - Assert::assertDirectoryIsNotWritable(...\func_get_args()); -} - -/** - * Asserts that a directory exists and is not writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4074 - * @see Assert::assertDirectoryNotIsWritable - */ -function assertDirectoryNotIsWritable(string $directory, string $message = ''): void -{ - Assert::assertDirectoryNotIsWritable(...\func_get_args()); -} - -/** - * Asserts that a file exists. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileExists - */ -function assertFileExists(string $filename, string $message = ''): void -{ - Assert::assertFileExists(...\func_get_args()); -} - -/** - * Asserts that a file does not exist. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileDoesNotExist - */ -function assertFileDoesNotExist(string $filename, string $message = ''): void -{ - Assert::assertFileDoesNotExist(...\func_get_args()); -} - -/** - * Asserts that a file does not exist. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4077 - * @see Assert::assertFileNotExists - */ -function assertFileNotExists(string $filename, string $message = ''): void -{ - Assert::assertFileNotExists(...\func_get_args()); -} - -/** - * Asserts that a file exists and is readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileIsReadable - */ -function assertFileIsReadable(string $file, string $message = ''): void -{ - Assert::assertFileIsReadable(...\func_get_args()); -} - -/** - * Asserts that a file exists and is not readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileIsNotReadable - */ -function assertFileIsNotReadable(string $file, string $message = ''): void -{ - Assert::assertFileIsNotReadable(...\func_get_args()); -} - -/** - * Asserts that a file exists and is not readable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4080 - * @see Assert::assertFileNotIsReadable - */ -function assertFileNotIsReadable(string $file, string $message = ''): void -{ - Assert::assertFileNotIsReadable(...\func_get_args()); -} - -/** - * Asserts that a file exists and is writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileIsWritable - */ -function assertFileIsWritable(string $file, string $message = ''): void -{ - Assert::assertFileIsWritable(...\func_get_args()); -} - -/** - * Asserts that a file exists and is not writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFileIsNotWritable - */ -function assertFileIsNotWritable(string $file, string $message = ''): void -{ - Assert::assertFileIsNotWritable(...\func_get_args()); -} - -/** - * Asserts that a file exists and is not writable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4083 - * @see Assert::assertFileNotIsWritable - */ -function assertFileNotIsWritable(string $file, string $message = ''): void -{ - Assert::assertFileNotIsWritable(...\func_get_args()); -} - -/** - * Asserts that a condition is true. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert true $condition - * - * @see Assert::assertTrue - */ -function assertTrue($condition, string $message = ''): void -{ - Assert::assertTrue(...\func_get_args()); -} - -/** - * Asserts that a condition is not true. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !true $condition - * - * @see Assert::assertNotTrue - */ -function assertNotTrue($condition, string $message = ''): void -{ - Assert::assertNotTrue(...\func_get_args()); -} - -/** - * Asserts that a condition is false. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert false $condition - * - * @see Assert::assertFalse - */ -function assertFalse($condition, string $message = ''): void -{ - Assert::assertFalse(...\func_get_args()); -} - -/** - * Asserts that a condition is not false. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !false $condition - * - * @see Assert::assertNotFalse - */ -function assertNotFalse($condition, string $message = ''): void -{ - Assert::assertNotFalse(...\func_get_args()); -} - -/** - * Asserts that a variable is null. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert null $actual - * - * @see Assert::assertNull - */ -function assertNull($actual, string $message = ''): void -{ - Assert::assertNull(...\func_get_args()); -} - -/** - * Asserts that a variable is not null. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !null $actual - * - * @see Assert::assertNotNull - */ -function assertNotNull($actual, string $message = ''): void -{ - Assert::assertNotNull(...\func_get_args()); -} - -/** - * Asserts that a variable is finite. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertFinite - */ -function assertFinite($actual, string $message = ''): void -{ - Assert::assertFinite(...\func_get_args()); -} - -/** - * Asserts that a variable is infinite. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertInfinite - */ -function assertInfinite($actual, string $message = ''): void -{ - Assert::assertInfinite(...\func_get_args()); -} - -/** - * Asserts that a variable is nan. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertNan - */ -function assertNan($actual, string $message = ''): void -{ - Assert::assertNan(...\func_get_args()); -} - -/** - * Asserts that a class has a specified attribute. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertClassHasAttribute - */ -function assertClassHasAttribute(string $attributeName, string $className, string $message = ''): void -{ - Assert::assertClassHasAttribute(...\func_get_args()); -} - -/** - * Asserts that a class does not have a specified attribute. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertClassNotHasAttribute - */ -function assertClassNotHasAttribute(string $attributeName, string $className, string $message = ''): void -{ - Assert::assertClassNotHasAttribute(...\func_get_args()); -} - -/** - * Asserts that a class has a specified static attribute. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertClassHasStaticAttribute - */ -function assertClassHasStaticAttribute(string $attributeName, string $className, string $message = ''): void -{ - Assert::assertClassHasStaticAttribute(...\func_get_args()); -} - -/** - * Asserts that a class does not have a specified static attribute. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertClassNotHasStaticAttribute - */ -function assertClassNotHasStaticAttribute(string $attributeName, string $className, string $message = ''): void -{ - Assert::assertClassNotHasStaticAttribute(...\func_get_args()); -} - -/** - * Asserts that an object has a specified attribute. - * - * @param object $object - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertObjectHasAttribute - */ -function assertObjectHasAttribute(string $attributeName, $object, string $message = ''): void -{ - Assert::assertObjectHasAttribute(...\func_get_args()); -} - -/** - * Asserts that an object does not have a specified attribute. - * - * @param object $object - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertObjectNotHasAttribute - */ -function assertObjectNotHasAttribute(string $attributeName, $object, string $message = ''): void -{ - Assert::assertObjectNotHasAttribute(...\func_get_args()); -} - -/** - * Asserts that two variables have the same type and value. - * Used on objects, it asserts that two variables reference - * the same object. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-template ExpectedType - * @psalm-param ExpectedType $expected - * @psalm-assert =ExpectedType $actual - * - * @see Assert::assertSame - */ -function assertSame($expected, $actual, string $message = ''): void -{ - Assert::assertSame(...\func_get_args()); -} - -/** - * Asserts that two variables do not have the same type and value. - * Used on objects, it asserts that two variables do not reference - * the same object. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertNotSame - */ -function assertNotSame($expected, $actual, string $message = ''): void -{ - Assert::assertNotSame(...\func_get_args()); -} - -/** - * Asserts that a variable is of a given type. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @psalm-template ExpectedType of object - * @psalm-param class-string $expected - * @psalm-assert ExpectedType $actual - * - * @see Assert::assertInstanceOf - */ -function assertInstanceOf(string $expected, $actual, string $message = ''): void -{ - Assert::assertInstanceOf(...\func_get_args()); -} - -/** - * Asserts that a variable is not of a given type. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @psalm-template ExpectedType of object - * @psalm-param class-string $expected - * @psalm-assert !ExpectedType $actual - * - * @see Assert::assertNotInstanceOf - */ -function assertNotInstanceOf(string $expected, $actual, string $message = ''): void -{ - Assert::assertNotInstanceOf(...\func_get_args()); -} - -/** - * Asserts that a variable is of type array. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert array $actual - * - * @see Assert::assertIsArray - */ -function assertIsArray($actual, string $message = ''): void -{ - Assert::assertIsArray(...\func_get_args()); -} - -/** - * Asserts that a variable is of type bool. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert bool $actual - * - * @see Assert::assertIsBool - */ -function assertIsBool($actual, string $message = ''): void -{ - Assert::assertIsBool(...\func_get_args()); -} - -/** - * Asserts that a variable is of type float. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert float $actual - * - * @see Assert::assertIsFloat - */ -function assertIsFloat($actual, string $message = ''): void -{ - Assert::assertIsFloat(...\func_get_args()); -} - -/** - * Asserts that a variable is of type int. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert int $actual - * - * @see Assert::assertIsInt - */ -function assertIsInt($actual, string $message = ''): void -{ - Assert::assertIsInt(...\func_get_args()); -} - -/** - * Asserts that a variable is of type numeric. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert numeric $actual - * - * @see Assert::assertIsNumeric - */ -function assertIsNumeric($actual, string $message = ''): void -{ - Assert::assertIsNumeric(...\func_get_args()); -} - -/** - * Asserts that a variable is of type object. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert object $actual - * - * @see Assert::assertIsObject - */ -function assertIsObject($actual, string $message = ''): void -{ - Assert::assertIsObject(...\func_get_args()); -} - -/** - * Asserts that a variable is of type resource. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert resource $actual - * - * @see Assert::assertIsResource - */ -function assertIsResource($actual, string $message = ''): void -{ - Assert::assertIsResource(...\func_get_args()); -} - -/** - * Asserts that a variable is of type string. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert string $actual - * - * @see Assert::assertIsString - */ -function assertIsString($actual, string $message = ''): void -{ - Assert::assertIsString(...\func_get_args()); -} - -/** - * Asserts that a variable is of type scalar. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert scalar $actual - * - * @see Assert::assertIsScalar - */ -function assertIsScalar($actual, string $message = ''): void -{ - Assert::assertIsScalar(...\func_get_args()); -} - -/** - * Asserts that a variable is of type callable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert callable $actual - * - * @see Assert::assertIsCallable - */ -function assertIsCallable($actual, string $message = ''): void -{ - Assert::assertIsCallable(...\func_get_args()); -} - -/** - * Asserts that a variable is of type iterable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert iterable $actual - * - * @see Assert::assertIsIterable - */ -function assertIsIterable($actual, string $message = ''): void -{ - Assert::assertIsIterable(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type array. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !array $actual - * - * @see Assert::assertIsNotArray - */ -function assertIsNotArray($actual, string $message = ''): void -{ - Assert::assertIsNotArray(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type bool. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !bool $actual - * - * @see Assert::assertIsNotBool - */ -function assertIsNotBool($actual, string $message = ''): void -{ - Assert::assertIsNotBool(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type float. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !float $actual - * - * @see Assert::assertIsNotFloat - */ -function assertIsNotFloat($actual, string $message = ''): void -{ - Assert::assertIsNotFloat(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type int. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !int $actual - * - * @see Assert::assertIsNotInt - */ -function assertIsNotInt($actual, string $message = ''): void -{ - Assert::assertIsNotInt(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type numeric. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !numeric $actual - * - * @see Assert::assertIsNotNumeric - */ -function assertIsNotNumeric($actual, string $message = ''): void -{ - Assert::assertIsNotNumeric(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type object. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !object $actual - * - * @see Assert::assertIsNotObject - */ -function assertIsNotObject($actual, string $message = ''): void -{ - Assert::assertIsNotObject(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type resource. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !resource $actual - * - * @see Assert::assertIsNotResource - */ -function assertIsNotResource($actual, string $message = ''): void -{ - Assert::assertIsNotResource(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type string. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !string $actual - * - * @see Assert::assertIsNotString - */ -function assertIsNotString($actual, string $message = ''): void -{ - Assert::assertIsNotString(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type scalar. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !scalar $actual - * - * @see Assert::assertIsNotScalar - */ -function assertIsNotScalar($actual, string $message = ''): void -{ - Assert::assertIsNotScalar(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type callable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !callable $actual - * - * @see Assert::assertIsNotCallable - */ -function assertIsNotCallable($actual, string $message = ''): void -{ - Assert::assertIsNotCallable(...\func_get_args()); -} - -/** - * Asserts that a variable is not of type iterable. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @psalm-assert !iterable $actual - * - * @see Assert::assertIsNotIterable - */ -function assertIsNotIterable($actual, string $message = ''): void -{ - Assert::assertIsNotIterable(...\func_get_args()); -} - -/** - * Asserts that a string matches a given regular expression. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertMatchesRegularExpression - */ -function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void -{ - Assert::assertMatchesRegularExpression(...\func_get_args()); -} - -/** - * Asserts that a string matches a given regular expression. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4086 - * @see Assert::assertRegExp - */ -function assertRegExp(string $pattern, string $string, string $message = ''): void -{ - Assert::assertRegExp(...\func_get_args()); -} - -/** - * Asserts that a string does not match a given regular expression. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertDoesNotMatchRegularExpression - */ -function assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void -{ - Assert::assertDoesNotMatchRegularExpression(...\func_get_args()); -} - -/** - * Asserts that a string does not match a given regular expression. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4089 - * @see Assert::assertNotRegExp - */ -function assertNotRegExp(string $pattern, string $string, string $message = ''): void -{ - Assert::assertNotRegExp(...\func_get_args()); -} - -/** - * Assert that the size of two arrays (or `Countable` or `Traversable` objects) - * is the same. - * - * @param \Countable|iterable $expected - * @param \Countable|iterable $actual - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertSameSize - */ -function assertSameSize($expected, $actual, string $message = ''): void -{ - Assert::assertSameSize(...\func_get_args()); -} - -/** - * Assert that the size of two arrays (or `Countable` or `Traversable` objects) - * is not the same. - * - * @param \Countable|iterable $expected - * @param \Countable|iterable $actual - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertNotSameSize - */ -function assertNotSameSize($expected, $actual, string $message = ''): void -{ - Assert::assertNotSameSize(...\func_get_args()); -} - -/** - * Asserts that a string matches a given format string. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringMatchesFormat - */ -function assertStringMatchesFormat(string $format, string $string, string $message = ''): void -{ - Assert::assertStringMatchesFormat(...\func_get_args()); -} - -/** - * Asserts that a string does not match a given format string. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringNotMatchesFormat - */ -function assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void -{ - Assert::assertStringNotMatchesFormat(...\func_get_args()); -} - -/** - * Asserts that a string matches a given format file. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringMatchesFormatFile - */ -function assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void -{ - Assert::assertStringMatchesFormatFile(...\func_get_args()); -} - -/** - * Asserts that a string does not match a given format string. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringNotMatchesFormatFile - */ -function assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void -{ - Assert::assertStringNotMatchesFormatFile(...\func_get_args()); -} - -/** - * Asserts that a string starts with a given prefix. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringStartsWith - */ -function assertStringStartsWith(string $prefix, string $string, string $message = ''): void -{ - Assert::assertStringStartsWith(...\func_get_args()); -} - -/** - * Asserts that a string starts not with a given prefix. - * - * @param string $prefix - * @param string $string - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringStartsNotWith - */ -function assertStringStartsNotWith($prefix, $string, string $message = ''): void -{ - Assert::assertStringStartsNotWith(...\func_get_args()); -} - -/** - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringContainsString - */ -function assertStringContainsString(string $needle, string $haystack, string $message = ''): void -{ - Assert::assertStringContainsString(...\func_get_args()); -} - -/** - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringContainsStringIgnoringCase - */ -function assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void -{ - Assert::assertStringContainsStringIgnoringCase(...\func_get_args()); -} - -/** - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringNotContainsString - */ -function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void -{ - Assert::assertStringNotContainsString(...\func_get_args()); -} - -/** - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringNotContainsStringIgnoringCase - */ -function assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void -{ - Assert::assertStringNotContainsStringIgnoringCase(...\func_get_args()); -} - -/** - * Asserts that a string ends with a given suffix. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringEndsWith - */ -function assertStringEndsWith(string $suffix, string $string, string $message = ''): void -{ - Assert::assertStringEndsWith(...\func_get_args()); -} - -/** - * Asserts that a string ends not with a given suffix. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertStringEndsNotWith - */ -function assertStringEndsNotWith(string $suffix, string $string, string $message = ''): void -{ - Assert::assertStringEndsNotWith(...\func_get_args()); -} - -/** - * Asserts that two XML files are equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertXmlFileEqualsXmlFile - */ -function assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void -{ - Assert::assertXmlFileEqualsXmlFile(...\func_get_args()); -} - -/** - * Asserts that two XML files are not equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertXmlFileNotEqualsXmlFile - */ -function assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void -{ - Assert::assertXmlFileNotEqualsXmlFile(...\func_get_args()); -} - -/** - * Asserts that two XML documents are equal. - * - * @param \DOMDocument|string $actualXml - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertXmlStringEqualsXmlFile - */ -function assertXmlStringEqualsXmlFile(string $expectedFile, $actualXml, string $message = ''): void -{ - Assert::assertXmlStringEqualsXmlFile(...\func_get_args()); -} - -/** - * Asserts that two XML documents are not equal. - * - * @param \DOMDocument|string $actualXml - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertXmlStringNotEqualsXmlFile - */ -function assertXmlStringNotEqualsXmlFile(string $expectedFile, $actualXml, string $message = ''): void -{ - Assert::assertXmlStringNotEqualsXmlFile(...\func_get_args()); -} - -/** - * Asserts that two XML documents are equal. - * - * @param \DOMDocument|string $expectedXml - * @param \DOMDocument|string $actualXml - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertXmlStringEqualsXmlString - */ -function assertXmlStringEqualsXmlString($expectedXml, $actualXml, string $message = ''): void -{ - Assert::assertXmlStringEqualsXmlString(...\func_get_args()); -} - -/** - * Asserts that two XML documents are not equal. - * - * @param \DOMDocument|string $expectedXml - * @param \DOMDocument|string $actualXml - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws Exception - * - * @see Assert::assertXmlStringNotEqualsXmlString - */ -function assertXmlStringNotEqualsXmlString($expectedXml, $actualXml, string $message = ''): void -{ - Assert::assertXmlStringNotEqualsXmlString(...\func_get_args()); -} - -/** - * Asserts that a hierarchy of DOMElements matches. - * - * @throws AssertionFailedError - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @codeCoverageIgnore - * - * @deprecated https://github.com/sebastianbergmann/phpunit/issues/4091 - * @see Assert::assertEqualXMLStructure - */ -function assertEqualXMLStructure(\DOMElement $expectedElement, \DOMElement $actualElement, bool $checkAttributes = false, string $message = ''): void -{ - Assert::assertEqualXMLStructure(...\func_get_args()); -} - -/** - * Evaluates a PHPUnit\Framework\Constraint matcher object. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertThat - */ -function assertThat($value, Constraint $constraint, string $message = ''): void -{ - Assert::assertThat(...\func_get_args()); -} - -/** - * Asserts that a string is a valid JSON string. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertJson - */ -function assertJson(string $actualJson, string $message = ''): void -{ - Assert::assertJson(...\func_get_args()); -} - -/** - * Asserts that two given JSON encoded objects or arrays are equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertJsonStringEqualsJsonString - */ -function assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void -{ - Assert::assertJsonStringEqualsJsonString(...\func_get_args()); -} - -/** - * Asserts that two given JSON encoded objects or arrays are not equal. - * - * @param string $expectedJson - * @param string $actualJson - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertJsonStringNotEqualsJsonString - */ -function assertJsonStringNotEqualsJsonString($expectedJson, $actualJson, string $message = ''): void -{ - Assert::assertJsonStringNotEqualsJsonString(...\func_get_args()); -} - -/** - * Asserts that the generated JSON encoded object and the content of the given file are equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertJsonStringEqualsJsonFile - */ -function assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void -{ - Assert::assertJsonStringEqualsJsonFile(...\func_get_args()); -} - -/** - * Asserts that the generated JSON encoded object and the content of the given file are not equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertJsonStringNotEqualsJsonFile - */ -function assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void -{ - Assert::assertJsonStringNotEqualsJsonFile(...\func_get_args()); -} - -/** - * Asserts that two JSON files are equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertJsonFileEqualsJsonFile - */ -function assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void -{ - Assert::assertJsonFileEqualsJsonFile(...\func_get_args()); -} - -/** - * Asserts that two JSON files are not equal. - * - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * - * @see Assert::assertJsonFileNotEqualsJsonFile - */ -function assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void -{ - Assert::assertJsonFileNotEqualsJsonFile(...\func_get_args()); -} diff --git a/composer.json b/composer.json index 4d77bb41..dc98600d 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,7 @@ }, "files": [ "src/globals.php", - "src/Pest.php", - "compiled/globals.php" + "src/Pest.php" ] }, "autoload-dev": { @@ -65,7 +64,6 @@ "bin/pest" ], "scripts": { - "compile": "@php ./scripts/compile.php", "lint": "rector process src && php-cs-fixer fix -v", "test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run", "test:types": "phpstan analyse --ansi --memory-limit=0", From 32ef377284709d4a5ce77c67dbee614debf903bc Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 14 Jul 2020 23:21:51 +0200 Subject: [PATCH 11/19] feat(expect): removes ignore cases related assertions --- src/Expectation.php | 15 +-------------- tests/Expect/toEqualCanonicalizing.php | 16 ---------------- tests/Expect/toEqualWithDelta.php | 6 +++--- 3 files changed, 4 insertions(+), 33 deletions(-) delete mode 100644 tests/Expect/toEqualCanonicalizing.php diff --git a/src/Expectation.php b/src/Expectation.php index 0aaf2159..16f90982 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -168,19 +168,6 @@ final class Expectation return $this; } - /** - * Asserts that two variables are equals, ignoring the casing - * for the comparison. - * - * @param mixed $value - */ - public function toEqualIgnoringCase($value): Expectation - { - Assert::assertEqualsIgnoringCase($value, $this->value); - - return $this; - } - /** * Asserts that two variables have the same value. * The contents of $expected and $actual are canonicalized before @@ -205,7 +192,7 @@ final class Expectation * * @param mixed $value */ - public function toBeEqualWithDelta($value, float $delta): Expectation + public function toEqualWithDelta($value, float $delta): Expectation { Assert::assertEqualsWithDelta($value, $this->value, $delta); diff --git a/tests/Expect/toEqualCanonicalizing.php b/tests/Expect/toEqualCanonicalizing.php deleted file mode 100644 index 2d6c299f..00000000 --- a/tests/Expect/toEqualCanonicalizing.php +++ /dev/null @@ -1,16 +0,0 @@ -toEqualCanonicalizing(123); - expect(['a', 'b', 'c'])->toEqualCanonicalizing(['c', 'a', 'b']); -}); - -test('failures', function () { - expect(['a', 'b', 'c'])->toEqualCanonicalizing(['a', 'b']); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('042')->not->toEqualCanonicalizing(42); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqualWithDelta.php b/tests/Expect/toEqualWithDelta.php index 3faab6e2..bb78b86d 100644 --- a/tests/Expect/toEqualWithDelta.php +++ b/tests/Expect/toEqualWithDelta.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect(1.0)->toBeEqualWithDelta(1.3, .4); + expect(1.0)->toEqualWithDelta(1.3, .4); }); test('failures', function () { - expect(1.0)->toBeEqualWithDelta(1.5, .1); + expect(1.0)->toEqualWithDelta(1.5, .1); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect(1.0)->not->toBeEqualWithDelta(1.6, .7); + expect(1.0)->not->toEqualWithDelta(1.6, .7); })->throws(ExpectationFailedException::class); From 1aec8bac55a072ccc60913f56fef43dd1b260cbf Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 14 Jul 2020 23:37:02 +0200 Subject: [PATCH 12/19] feat(expect): adds toHaveProperty --- src/Expectation.php | 10 +++++++ tests/.snapshots/success.txt | 29 ++++++++----------- tests/Expect/toEqualIgnoringCase.php | 15 ---------- tests/Expect/{toCount.php => toHaveCount.php} | 0 tests/Expect/toHaveProperty.php | 18 ++++++++++++ tests/Features/AfterEach.php | 4 +-- 6 files changed, 42 insertions(+), 34 deletions(-) delete mode 100644 tests/Expect/toEqualIgnoringCase.php rename tests/Expect/{toCount.php => toHaveCount.php} (100%) create mode 100644 tests/Expect/toHaveProperty.php diff --git a/src/Expectation.php b/src/Expectation.php index 16f90982..b5d775a3 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -156,6 +156,16 @@ final class Expectation return $this; } + /** + * Assert that the $value contains the property $name. + */ + public function toHaveProperty(string $name): Expectation + { + Assert::assertTrue(property_exists($this->value, $name)); + + return $this; + } + /** * Asserts that two variables have the same value. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 6f9ce702..e66bf634 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -120,31 +120,26 @@ PASS Tests\Expect\toContain ✓ passes ✓ failures - ✓ not failures - - PASS Tests\Expect\toCount - ✓ pass - ✓ failures ✓ not failures PASS Tests\Expect\toEqual ✓ pass ✓ failures - ✓ not failures - - PASS Tests\Expect\toEqualCanonicalizing - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toEqualIgnoringCase - ✓ pass - ✓ failures ✓ not failures PASS Tests\Expect\toEqualWithDelta ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toHaveCount + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toHaveProperty + ✓ pass + ✓ failures ✓ not failures PASS Tests\Features\AfterAll @@ -312,5 +307,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 2 risked, 6 skipped, 181 passed - Time: 5.72s + Tests: 2 risked, 6 skipped, 178 passed + Time: 5.70s diff --git a/tests/Expect/toEqualIgnoringCase.php b/tests/Expect/toEqualIgnoringCase.php deleted file mode 100644 index 2016fa4d..00000000 --- a/tests/Expect/toEqualIgnoringCase.php +++ /dev/null @@ -1,15 +0,0 @@ -toEqualIgnoringCase('HELLO'); -}); - -test('failures', function () { - expect('hello')->toEqualIgnoringCase('BAR'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('HELLO')->not->toEqualIgnoringCase('HelLo'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toCount.php b/tests/Expect/toHaveCount.php similarity index 100% rename from tests/Expect/toCount.php rename to tests/Expect/toHaveCount.php diff --git a/tests/Expect/toHaveProperty.php b/tests/Expect/toHaveProperty.php new file mode 100644 index 00000000..a7c0c649 --- /dev/null +++ b/tests/Expect/toHaveProperty.php @@ -0,0 +1,18 @@ +foo = 'bar'; + +test('pass', function () use ($obj) { + expect($obj)->toHaveProperty('foo'); +}); + +test('failures', function () use ($obj) { + expect($obj)->toHaveProperty('bar'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () use ($obj) { + expect($obj)->not->toHaveProperty('foo'); +})->throws(ExpectationFailedException::class); diff --git a/tests/Features/AfterEach.php b/tests/Features/AfterEach.php index 5c223833..e16f8529 100644 --- a/tests/Features/AfterEach.php +++ b/tests/Features/AfterEach.php @@ -11,10 +11,10 @@ afterEach(function () use ($state) { }); it('does not get executed before the test', function () { - expect(property_exists($this->state, 'bar'))->toBeFalse(); + expect($this->state)->not->toHaveProperty('bar'); }); it('gets executed after the test', function () { - expect(property_exists($this->state, 'bar'))->toBeTrue(); + expect($this->state)->toHaveProperty('bar'); expect($this->state->bar)->toBe(2); }); From e2deaae6c92d3ac58c81c7e091940b2c2848d85a Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 15 Jul 2020 00:34:59 +0200 Subject: [PATCH 13/19] feat(expect): makes expect work with pending higher order tests --- src/Concerns/TestCase.php | 11 +++++++++++ src/Expectation.php | 10 ++++++++++ src/PendingObjects/TestCall.php | 13 ++----------- src/globals.php | 6 ++++-- tests/.snapshots/success.txt | 15 ++++++++------- tests/Expect/toBe.php | 5 +++-- tests/Features/TestCycle.php | 10 ++++++---- tests/Visual/Success.php | 1 + 8 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/Concerns/TestCase.php b/src/Concerns/TestCase.php index fecd488e..6c1d98ce 100644 --- a/src/Concerns/TestCase.php +++ b/src/Concerns/TestCase.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest\Concerns; use Closure; +use Pest\Expectation; use Pest\Support\ExceptionTrace; use Pest\TestSuite; use PHPUnit\Util\Test; @@ -87,6 +88,16 @@ trait TestCase parent::tearDownAfterClass(); } + /** + * Creates a new expectation. + * + * @param mixed $value + */ + public function expect($value): Expectation + { + return new Expectation($value); + } + /** * Gets executed before the test. */ diff --git a/src/Expectation.php b/src/Expectation.php index b5d775a3..61ac5795 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -30,6 +30,16 @@ final class Expectation $this->value = $value; } + /** + * Creates a new expectation. + * + * @param mixed $value + */ + public function and($value): Expectation + { + return new self($value); + } + /** * Creates the opposite expectation for the value. */ diff --git a/src/PendingObjects/TestCall.php b/src/PendingObjects/TestCall.php index a6c9b499..613a4a97 100644 --- a/src/PendingObjects/TestCall.php +++ b/src/PendingObjects/TestCall.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Pest\PendingObjects; use Closure; -use Pest\Expectation; use Pest\Factories\TestCaseFactory; use Pest\Support\Backtrace; use Pest\Support\NullClosure; @@ -13,6 +12,8 @@ use Pest\TestSuite; use SebastianBergmann\Exporter\Exporter; /** + * @method \Pest\Expectation expect(mixed $value) + * * @internal */ final class TestCall @@ -85,16 +86,6 @@ final class TestCall return $this; } - /** - * Creates a new expectation. - * - * @param mixed $value the Value - */ - public function expect($value): Expectation - { - return expect($value); - } - /** * Sets the test depends. */ diff --git a/src/globals.php b/src/globals.php index 59e5e784..7e85e9a6 100644 --- a/src/globals.php +++ b/src/globals.php @@ -110,8 +110,10 @@ function afterAll(Closure $closure = null): void * Creates a new expectation. * * @param mixed $value the Value + * + * @return Expectation */ -function expect($value): Expectation +function expect($value) { - return new Expectation($value); + return test()->expect($value); } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index e66bf634..f06d1d9f 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -3,6 +3,7 @@ ✓ that gets executed PASS Tests\Expect\toBe + ✓ expect true → toBeTrue → and false → toBeFalse ✓ strict comparisons ✓ failures ✓ not failures @@ -211,9 +212,9 @@ PASS Tests\Features\HigherOrderTests ✓ it proxies calls to object - WARN Tests\Features\It + PASS Tests\Features\It ✓ it is a test - ! it is a higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4 + ✓ it is a higher order message test PASS Tests\Features\Macro ✓ it can call chained macro method @@ -223,8 +224,8 @@ ✓ it has bar PASS Tests\Features\PendingHigherOrderTests - ✓ get 'foo' → get 'bar' - ✓ get 'foo' + ✓ get 'foo' → get 'bar' → expect true → toBeTrue + ✓ get 'foo' → expect true → toBeTrue WARN Tests\Features\Skip ✓ it do not skips @@ -235,9 +236,9 @@ ✓ it do not skips with falsy closure condition - it skips with condition and message → skipped because foo - WARN Tests\Features\Test + PASS Tests\Features\Test ✓ a test - ! higher order message test → This test did not perform any assertions /Users/nunomaduro/pestphp/pest/src/Factories/TestCaseFactory.php(204) : eval()'d code:4 + ✓ higher order message test PASS Tests\Fixtures\DirectoryWithTests\ExampleTest ✓ it example 1 @@ -307,5 +308,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 2 risked, 6 skipped, 178 passed + Tests: 6 skipped, 181 passed Time: 5.70s diff --git a/tests/Expect/toBe.php b/tests/Expect/toBe.php index f3f84608..ef2bce5a 100644 --- a/tests/Expect/toBe.php +++ b/tests/Expect/toBe.php @@ -2,12 +2,13 @@ use PHPUnit\Framework\ExpectationFailedException; +expect(true)->toBeTrue()->and(false)->toBeFalse(); + test('strict comparisons', function () { $nuno = new stdClass(); $dries = new stdClass(); - expect($nuno)->toBe($nuno); - expect($nuno)->not->toBe($dries); + expect($nuno)->toBe($nuno)->not->toBe($dries); }); test('failures', function () { diff --git a/tests/Features/TestCycle.php b/tests/Features/TestCycle.php index efca9588..7d3b785d 100644 --- a/tests/Features/TestCycle.php +++ b/tests/Features/TestCycle.php @@ -1,5 +1,7 @@ beforeAll = false; $foo->beforeEach = false; @@ -20,8 +22,8 @@ afterAll(function () { }); register_shutdown_function(function () use ($foo) { - expect($foo->beforeAll)->toBeFalse(); - expect($foo->beforeEach)->toBeFalse(); - expect($foo->afterEach)->toBeFalse(); - expect($foo->afterAll)->toBeFalse(); + assertFalse($foo->beforeAll); + assertFalse($foo->beforeEach); + assertFalse($foo->afterEach); + assertFalse($foo->afterAll); }); diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index a4f5fae6..14af013e 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -22,6 +22,7 @@ test('visual snapshot of test suite on success', function () { $output = explode("\n", $output()); array_pop($output); array_pop($output); + expect(file_get_contents($snapshot))->toContain(implode("\n", $output)); } })->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')) From 2751bc9674f49e31f1abc0a35cc7ef9c0b367d6f Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 15 Jul 2020 00:57:31 +0200 Subject: [PATCH 14/19] feat(expect): fixes to contain with strings --- src/Expectation.php | 2 +- tests/.snapshots/success.txt | 7 ++++--- tests/Expect/toContain.php | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 61ac5795..67d5aa9e 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -147,7 +147,7 @@ final class Expectation */ public function toContain($value): Expectation { - if (is_string($value)) { + if (is_string($this->value)) { Assert::assertStringContainsString($value, $this->value); } else { Assert::assertContains($value, $this->value); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index f06d1d9f..9b6e5b25 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -119,7 +119,8 @@ ✓ not failures PASS Tests\Expect\toContain - ✓ passes + ✓ passes strings + ✓ passes arrays ✓ failures ✓ not failures @@ -308,5 +309,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 181 passed - Time: 5.70s + Tests: 6 skipped, 182 passed + Time: 5.72s diff --git a/tests/Expect/toContain.php b/tests/Expect/toContain.php index ce477fbf..04d586ff 100644 --- a/tests/Expect/toContain.php +++ b/tests/Expect/toContain.php @@ -2,10 +2,14 @@ use PHPUnit\Framework\ExpectationFailedException; -test('passes', function () { +test('passes strings', function () { expect([1, 2, 42])->toContain(42); }); +test('passes arrays', function () { + expect('Nuno')->toContain('Nu'); +}); + test('failures', function () { expect([1, 2, 42])->toContain(3); })->throws(ExpectationFailedException::class); From 1e61144cd2e27b3a9169b731043901941dfe6b12 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 15 Jul 2020 01:05:36 +0200 Subject: [PATCH 15/19] feat(expect): handle property calls to opposite expectations --- src/Expectation.php | 2 +- src/OppositeExpectation.php | 15 +++++++++++++++ tests/.snapshots/success.txt | 7 +++++-- tests/Expect/not.php | 10 ++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/Expect/not.php diff --git a/src/Expectation.php b/src/Expectation.php index 67d5aa9e..4aa2eee9 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -9,7 +9,7 @@ use PHPUnit\Framework\Assert; /** * @internal * - * @property Expectation $not Creates the opposite expectation. + * @property Expectation not Creates the opposite expectation. */ final class Expectation { diff --git a/src/OppositeExpectation.php b/src/OppositeExpectation.php index 08a7ebc6..4ab4449d 100644 --- a/src/OppositeExpectation.php +++ b/src/OppositeExpectation.php @@ -42,4 +42,19 @@ final class OppositeExpectation throw new ExpectationFailedException(sprintf('@todo')); } + + /** + * Handle dynamic properties gets into the original expectation. + */ + public function __get(string $name): Expectation + { + try { + /* @phpstan-ignore-next-line */ + $this->original->{$name}; + } catch (ExpectationFailedException $e) { + return $this->original; + } + + throw new ExpectationFailedException(sprintf('@todo')); + } } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 9b6e5b25..af19b3e5 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2,6 +2,9 @@ PASS Tests\CustomTestCase\ExecutedTest ✓ that gets executed + PASS Tests\Expect\not + ✓ not property calls + PASS Tests\Expect\toBe ✓ expect true → toBeTrue → and false → toBeFalse ✓ strict comparisons @@ -309,5 +312,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 182 passed - Time: 5.72s + Tests: 6 skipped, 183 passed + Time: 5.77s diff --git a/tests/Expect/not.php b/tests/Expect/not.php new file mode 100644 index 00000000..79220b19 --- /dev/null +++ b/tests/Expect/not.php @@ -0,0 +1,10 @@ +toBeTrue() + ->not()->toBeFalse() + ->not->toBeFalse + ->and(false) + ->toBeFalse(); +}); From f0f79ab24491e27a72888fca9c54c97a0aabe233 Mon Sep 17 00:00:00 2001 From: ceceppa Date: Thu, 16 Jul 2020 07:34:43 +0100 Subject: [PATCH 16/19] feat(expect): add more methods --- src/Expectation.php | 40 ++++++++++++++++++++++++++ tests/.snapshots/success.txt | 26 +++++++++++++++-- tests/Expect/toBeDirectory.php | 17 +++++++++++ tests/Expect/toBeReadableDirectory.php | 15 ++++++++++ tests/Expect/toBeWritableDirectory.php | 15 ++++++++++ 5 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 tests/Expect/toBeDirectory.php create mode 100644 tests/Expect/toBeReadableDirectory.php create mode 100644 tests/Expect/toBeWritableDirectory.php diff --git a/src/Expectation.php b/src/Expectation.php index 4aa2eee9..f46053fa 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -372,6 +372,46 @@ final class Expectation return $this; } + /** + * Assert that the value array has the key. + */ + public function toHaveKey(string $key): Expectation + { + Assert::assertArrayHasKey($key, $this->value); + + return $this; + } + + /** + * Assert that the value is a directory. + */ + public function toBeDirectory(): Expectation + { + Assert::assertDirectoryExists($this->value); + + return $this; + } + + /** + * Assert that the value is a directory and is readable. + */ + public function toBeReadableDirectory(): Expectation + { + Assert::assertDirectoryIsReadable($this->value); + + return $this; + } + + /** + * Assert that the value is a directory and is writable. + */ + public function toBeWritableDirectory(): Expectation + { + Assert::assertDirectoryIsWritable($this->value); + + return $this; + } + /** * Dynamically calls methods on the class without any arguments. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index af19b3e5..d9a8d83b 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -24,6 +24,11 @@ PASS Tests\Expect\toBeCallable ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeEmpty @@ -99,6 +104,11 @@ PASS Tests\Expect\toBeObject ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeReadableDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeResource @@ -119,12 +129,22 @@ PASS Tests\Expect\toBeTrue ✓ strict comparisons ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeWritableDirectory + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toContain ✓ passes strings ✓ passes arrays ✓ failures + ✓ not failures + + PASS Tests\Expect\toCount + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toEqual @@ -137,7 +157,7 @@ ✓ failures ✓ not failures - PASS Tests\Expect\toHaveCount + PASS Tests\Expect\toHaveKey ✓ pass ✓ failures ✓ not failures @@ -312,5 +332,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 183 passed - Time: 5.77s + Tests: 6 skipped, 195 passed + Time: 5.27s diff --git a/tests/Expect/toBeDirectory.php b/tests/Expect/toBeDirectory.php new file mode 100644 index 00000000..f30df144 --- /dev/null +++ b/tests/Expect/toBeDirectory.php @@ -0,0 +1,17 @@ +toBeDirectory(); +}); + +test('failures', function () { + expect('/random/path/whatever')->toBeDirectory(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect('.')->not->toBeDirectory(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeReadableDirectory.php b/tests/Expect/toBeReadableDirectory.php new file mode 100644 index 00000000..88f96019 --- /dev/null +++ b/tests/Expect/toBeReadableDirectory.php @@ -0,0 +1,15 @@ +toBeWritableDirectory(); +}); + +test('failures', function () { + expect('/random/path/whatever')->toBeWritableDirectory(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(sys_get_temp_dir())->not->toBeWritableDirectory(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeWritableDirectory.php b/tests/Expect/toBeWritableDirectory.php new file mode 100644 index 00000000..88f96019 --- /dev/null +++ b/tests/Expect/toBeWritableDirectory.php @@ -0,0 +1,15 @@ +toBeWritableDirectory(); +}); + +test('failures', function () { + expect('/random/path/whatever')->toBeWritableDirectory(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(sys_get_temp_dir())->not->toBeWritableDirectory(); +})->throws(ExpectationFailedException::class); From 46e900e8d20785418341559cc2f44233949ea935 Mon Sep 17 00:00:00 2001 From: ceceppa Date: Thu, 16 Jul 2020 07:35:31 +0100 Subject: [PATCH 17/19] feat(expect): add more methods --- tests/.snapshots/success.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index d9a8d83b..cf138b1c 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -140,11 +140,6 @@ ✓ passes strings ✓ passes arrays ✓ failures - ✓ not failures - - PASS Tests\Expect\toCount - ✓ pass - ✓ failures ✓ not failures PASS Tests\Expect\toEqual @@ -155,6 +150,11 @@ PASS Tests\Expect\toEqualWithDelta ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toHaveCount + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toHaveKey From 03201cb8b7e8243d4b216c46e4a3b986662892d3 Mon Sep 17 00:00:00 2001 From: ceceppa Date: Thu, 16 Jul 2020 07:57:05 +0100 Subject: [PATCH 18/19] feat(expect): add more methods --- tests/Expect/toEqualCanonicalizing.php | 16 ++++++++++++++++ tests/Expect/toHaveKey.php | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/Expect/toEqualCanonicalizing.php create mode 100644 tests/Expect/toHaveKey.php diff --git a/tests/Expect/toEqualCanonicalizing.php b/tests/Expect/toEqualCanonicalizing.php new file mode 100644 index 00000000..5e1178b9 --- /dev/null +++ b/tests/Expect/toEqualCanonicalizing.php @@ -0,0 +1,16 @@ +toEqualCanonicalizing([3, 1, 2]); + expect(['g', 'a', 'z'])->not->toEqualCanonicalizing(['a', 'z']); +}); + +test('failures', function () { + expect([3, 2, 1])->toEqualCanonicalizing([1, 2]); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(['a', 'b', 'c'])->not->toEqualCanonicalizing(['b', 'a', 'c']); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toHaveKey.php b/tests/Expect/toHaveKey.php new file mode 100644 index 00000000..1695688b --- /dev/null +++ b/tests/Expect/toHaveKey.php @@ -0,0 +1,15 @@ + 1, 'b', 'c' => 'world'])->toHaveKey('c'); +}); + +test('failures', function () { + expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKey('hello'); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKey('hello'); +})->throws(ExpectationFailedException::class); From c4c768dcaa8e816c2d1d0a5d81278c6af789195f Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sat, 18 Jul 2020 18:57:14 +0200 Subject: [PATCH 19/19] tests: update snapshots --- src/Expectation.php | 2 +- tests/.snapshots/success.txt | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index f46053fa..1e0f34ba 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -9,7 +9,7 @@ use PHPUnit\Framework\Assert; /** * @internal * - * @property Expectation not Creates the opposite expectation. + * @property Expectation $not Creates the opposite expectation. */ final class Expectation { diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index cf138b1c..ebc40173 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -145,6 +145,11 @@ PASS Tests\Expect\toEqual ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toEqualCanonicalizing + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toEqualWithDelta @@ -332,5 +337,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 195 passed - Time: 5.27s + Tests: 6 skipped, 198 passed + Time: 5.46s