diff --git a/src/Expectation.php b/src/Expectation.php index 2afe4088..db123468 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -52,6 +52,347 @@ final class Expectation return $this; } + /** + * Assert the value is empty. + */ + public function toBeEmpty(): Expectation + { + Assert::assertEmpty($this->value); + + return $this; + } + + /** + * Assert the value is false. + */ + public function toBeFalse(): Expectation + { + Assert::assertFalse($this->value); + + return $this; + } + + /** + * Assert the value is greater than expected one. + * + * @param int|float $value + */ + public function toBeGreaterThan($value): Expectation + { + 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): Expectation + { + 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): Expectation + { + Assert::assertLessThan($value, $this->value); + + return $this; + } + + /** + * Assert that value is less than the expected one. + * + * @param int|float $value + */ + public function toBeLessThanOrEqual($value): Expectation + { + Assert::assertLessThanOrEqual($value, $this->value); + + return $this; + } + + /** + * Assert that needles is an element of value. + * + * @param mixed $needle + */ + public function toContain($needle): 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); + + return $this; + } + + /** + * Assert that $count matches the number of elements of $value. + */ + public function toCount(int $count): Expectation + { + Assert::assertCount($count, $this->value); + + return $this; + } + + /** + * Asserts that two variables have the same value. + * + * @param mixed $value + */ + public function toEqual($value): Expectation + { + 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): 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 + * 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): Expectation + { + Assert::assertEqualsCanonicalizing($value, $this->value); + + return $this; + } + + /** + * Assert that the absolute difference between $value and $this->value + * is greater than $delta. + * + * @param mixed $value + */ + public function toEqualWithDelta($value, float $delta): Expectation + { + Assert::assertEqualsWithDelta($value, $this->value, $delta); + + return $this; + } + + /** + * Assert that the value infinite. + */ + public function toBeInfinite(): Expectation + { + Assert::assertInfinite($this->value); + + return $this; + } + + /** + * Assert that the value is an instance of $value. + * + * @param mixed $value + */ + public function toBeInstanceOf($value): Expectation + { + Assert::assertInstanceOf($value, $this->value); + + return $this; + } + + /** + * Assert that the value is an array. + */ + public function toBeArray(): Expectation + { + 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; + } + /** * Dynamically calls methods on the class without any arguments. * diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index bcff1d84..916c0d6c 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2,9 +2,164 @@ 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 + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeFalse + ✓ strict comparisons + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeFloat + ✓ pass + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeGreatherThan + ✓ passes + ✓ failures + ✓ not failures + + 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 + ✓ passes + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeLessThanOrEqual + ✓ passes + ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeNAN + ✓ pass + ✓ failures + ✓ not failures + + 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 + + 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 +327,5 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success - Tests: 6 skipped, 99 passed - Time: 3.62s + 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/toBeArray.php b/tests/Expect/toBeArray.php new file mode 100644 index 00000000..3fcec231 --- /dev/null +++ b/tests/Expect/toBeArray.php @@ -0,0 +1,16 @@ +toBeArray(); + expect('1, 2, 3')->not->toBeArray(); +}); + +test('failures', function () { + expect(null)->toBeArray(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(['a', 'b', 'c'])->not->toBeArray(); +})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeBool.php b/tests/Expect/toBeBool.php new file mode 100644 index 00000000..5dc37b21 --- /dev/null +++ b/tests/Expect/toBeBool.php @@ -0,0 +1,16 @@ +toBeBool(); + expect(0)->not->toBeBool(); +}); + +test('failures', function () { + expect(null)->toBeBool(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + 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/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/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/toBeFloat.php b/tests/Expect/toBeFloat.php new file mode 100644 index 00000000..69aa2306 --- /dev/null +++ b/tests/Expect/toBeFloat.php @@ -0,0 +1,16 @@ +toBeFloat(); + expect(1)->not->toBeFloat(); +}); + +test('failures', function () { + expect(42)->toBeFloat(); +})->throws(ExpectationFailedException::class); + +test('not failures', function () { + expect(log(3))->not->toBeFloat(); +})->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/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/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/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); 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/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/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); 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);