From 5d7f262f4ab280a660a85900f402eebb23abfda8 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 13 Dec 2020 22:35:30 +0100 Subject: [PATCH] feat: removes expectation api for a plugin --- composer.json | 9 +- phpstan.neon | 3 +- src/Actions/LoadStructure.php | 1 + src/Concerns/Extendable.php | 55 -- src/Concerns/TestCase.php | 11 - src/Datasets.php | 6 +- src/Expectation.php | 618 ----------------------- src/{globals.php => Functions.php} | 24 +- src/OppositeExpectation.php | 100 ---- src/Support/Extendable.php | 33 -- src/TeamCity.php | 2 +- tests/.snapshots/success.txt | 230 +-------- tests/Expect/extend.php | 29 -- tests/Expect/not.php | 10 - tests/Expect/toBe.php | 20 - tests/Expect/toBeArray.php | 16 - tests/Expect/toBeBool.php | 16 - tests/Expect/toBeCallable.php | 18 - tests/Expect/toBeDirectory.php | 17 - tests/Expect/toBeEmpty.php | 18 - tests/Expect/toBeFalse.php | 15 - tests/Expect/toBeFile.php | 23 - tests/Expect/toBeFloat.php | 16 - tests/Expect/toBeGreatherThan.php | 16 - tests/Expect/toBeGreatherThanOrEqual.php | 16 - tests/Expect/toBeInfinite.php | 16 - tests/Expect/toBeInstanceOf.php | 16 - tests/Expect/toBeInt.php | 16 - tests/Expect/toBeIterable.php | 23 - tests/Expect/toBeLessThan.php | 16 - tests/Expect/toBeLessThanOrEqual.php | 16 - tests/Expect/toBeNAN.php | 16 - tests/Expect/toBeNull.php | 16 - tests/Expect/toBeNumeric.php | 16 - tests/Expect/toBeObject.php | 16 - tests/Expect/toBeReadableDirectory.php | 15 - tests/Expect/toBeReadableFile.php | 23 - tests/Expect/toBeResource.php | 22 - tests/Expect/toBeScalar.php | 15 - tests/Expect/toBeString.php | 16 - tests/Expect/toBeTrue.php | 15 - tests/Expect/toBeWritableDirectory.php | 15 - tests/Expect/toBeWritableFile.php | 23 - tests/Expect/toContain.php | 19 - tests/Expect/toEndWith.php | 15 - tests/Expect/toEqual.php | 15 - tests/Expect/toEqualCanonicalizing.php | 16 - tests/Expect/toEqualWithDelta.php | 15 - tests/Expect/toHaveCount.php | 15 - tests/Expect/toHaveKey.php | 15 - tests/Expect/toHaveKeys.php | 15 - tests/Expect/toHaveProperty.php | 22 - tests/Expect/toMatch.php | 15 - tests/Expect/toMatchArray.php | 31 -- tests/Expect/toMatchConstraint.php | 16 - tests/Expect/toMatchObject.php | 31 -- tests/Expect/toStartWith.php | 15 - tests/Features/AfterEach.php | 2 +- tests/Features/Datasets.php | 2 +- tests/Unit/Actions/AddsTests.php | 2 +- 60 files changed, 19 insertions(+), 1875 deletions(-) delete mode 100644 src/Concerns/Extendable.php delete mode 100644 src/Expectation.php rename src/{globals.php => Functions.php} (83%) delete mode 100644 src/OppositeExpectation.php delete mode 100644 src/Support/Extendable.php delete mode 100644 tests/Expect/extend.php delete mode 100644 tests/Expect/not.php delete mode 100644 tests/Expect/toBe.php delete mode 100644 tests/Expect/toBeArray.php delete mode 100644 tests/Expect/toBeBool.php delete mode 100644 tests/Expect/toBeCallable.php delete mode 100644 tests/Expect/toBeDirectory.php delete mode 100644 tests/Expect/toBeEmpty.php delete mode 100644 tests/Expect/toBeFalse.php delete mode 100644 tests/Expect/toBeFile.php delete mode 100644 tests/Expect/toBeFloat.php delete mode 100644 tests/Expect/toBeGreatherThan.php delete mode 100644 tests/Expect/toBeGreatherThanOrEqual.php delete mode 100644 tests/Expect/toBeInfinite.php delete mode 100644 tests/Expect/toBeInstanceOf.php delete mode 100644 tests/Expect/toBeInt.php delete mode 100644 tests/Expect/toBeIterable.php delete mode 100644 tests/Expect/toBeLessThan.php delete mode 100644 tests/Expect/toBeLessThanOrEqual.php delete mode 100644 tests/Expect/toBeNAN.php delete mode 100644 tests/Expect/toBeNull.php delete mode 100644 tests/Expect/toBeNumeric.php delete mode 100644 tests/Expect/toBeObject.php delete mode 100644 tests/Expect/toBeReadableDirectory.php delete mode 100644 tests/Expect/toBeReadableFile.php delete mode 100644 tests/Expect/toBeResource.php delete mode 100644 tests/Expect/toBeScalar.php delete mode 100644 tests/Expect/toBeString.php delete mode 100644 tests/Expect/toBeTrue.php delete mode 100644 tests/Expect/toBeWritableDirectory.php delete mode 100644 tests/Expect/toBeWritableFile.php delete mode 100644 tests/Expect/toContain.php delete mode 100644 tests/Expect/toEndWith.php delete mode 100644 tests/Expect/toEqual.php delete mode 100644 tests/Expect/toEqualCanonicalizing.php delete mode 100644 tests/Expect/toEqualWithDelta.php delete mode 100644 tests/Expect/toHaveCount.php delete mode 100644 tests/Expect/toHaveKey.php delete mode 100644 tests/Expect/toHaveKeys.php delete mode 100644 tests/Expect/toHaveProperty.php delete mode 100644 tests/Expect/toMatch.php delete mode 100644 tests/Expect/toMatchArray.php delete mode 100644 tests/Expect/toMatchConstraint.php delete mode 100644 tests/Expect/toMatchObject.php delete mode 100644 tests/Expect/toStartWith.php diff --git a/composer.json b/composer.json index 7b2fd337..c8bc3217 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "nunomaduro/collision": "^5.0", "pestphp/pest-plugin": "^0.3", "pestphp/pest-plugin-coverage": "^0.3", + "pestphp/pest-plugin-expectations": "^0.3", "pestphp/pest-plugin-init": "^0.3", "phpunit/phpunit": ">= 9.3.7 <= 9.5.0" }, @@ -29,7 +30,7 @@ "Pest\\": "src/" }, "files": [ - "src/globals.php", + "src/Functions.php", "src/Pest.php" ] }, @@ -44,7 +45,7 @@ "require-dev": { "illuminate/console": "^7.16.1", "illuminate/support": "^7.16.1", - "laravel/dusk": "^6.9.0", + "laravel/dusk": "^6.9.1", "mockery/mockery": "^1.4.1", "pestphp/pest-dev-tools": "dev-master" }, @@ -58,8 +59,8 @@ "bin/pest" ], "scripts": { - "lint": "rector process src && php-cs-fixer fix -v", - "test:lint": "php-cs-fixer fix -v --dry-run && rector process src --dry-run", + "lint": "php-cs-fixer fix -v", + "test:lint": "php-cs-fixer fix -v --dry-run", "test:types": "phpstan analyse --ansi --memory-limit=0", "test:unit": "php bin/pest --colors=always --exclude-group=integration", "test:integration": "php bin/pest --colors=always --group=integration", diff --git a/phpstan.neon b/phpstan.neon index 81e3bd98..8861607d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,14 +7,13 @@ parameters: level: max paths: - src - excludes_analyse: - - src/globals.php checkMissingIterableValueType: true checkGenericClassInNonGenericObjectType: false reportUnmatchedIgnoredErrors: true ignoreErrors: + - "#type mixed is not subtype of native#" - "#Undefined variable: \\$this#" - "#is not allowed to extend#" - "#Language construct eval#" diff --git a/src/Actions/LoadStructure.php b/src/Actions/LoadStructure.php index 49d30b84..f7fe250c 100644 --- a/src/Actions/LoadStructure.php +++ b/src/Actions/LoadStructure.php @@ -21,6 +21,7 @@ final class LoadStructure * @var array */ private const STRUCTURE = [ + 'Expectations.php', 'Datasets.php', 'Helpers.php', 'Pest.php', diff --git a/src/Concerns/Extendable.php b/src/Concerns/Extendable.php deleted file mode 100644 index 41757a9f..00000000 --- a/src/Concerns/Extendable.php +++ /dev/null @@ -1,55 +0,0 @@ - - */ - private static $extends = []; - - /** - * Register a custom extend. - */ - public static function extend(string $name, Closure $extend): void - { - static::$extends[$name] = $extend; - } - - /** - * Checks if extend is registered. - */ - public static function hasExtend(string $name): bool - { - return array_key_exists($name, static::$extends); - } - - /** - * Dynamically handle calls to the class. - * - * @param array $parameters - * - * @return mixed - * - * @throws BadMethodCallException - */ - public function __call(string $method, array $parameters) - { - if (!static::hasExtend($method)) { - throw new BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method)); - } - - $extend = static::$extends[$method]->bindTo($this, static::class); - - return $extend(...$parameters); - } -} diff --git a/src/Concerns/TestCase.php b/src/Concerns/TestCase.php index 86862d9f..b7d29448 100644 --- a/src/Concerns/TestCase.php +++ b/src/Concerns/TestCase.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Pest\Concerns; use Closure; -use Pest\Expectation; use Pest\Support\ExceptionTrace; use Pest\TestSuite; use PHPUnit\Util\Test; @@ -94,16 +93,6 @@ 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/Datasets.php b/src/Datasets.php index 84b4ba72..8ee1d3c0 100644 --- a/src/Datasets.php +++ b/src/Datasets.php @@ -18,14 +18,14 @@ final class Datasets /** * Holds the datasets. * - * @var array> + * @var array> */ private static $datasets = []; /** * Sets the given. * - * @param Closure|iterable $data + * @param Closure|iterable $data */ public static function set(string $name, $data): void { @@ -37,7 +37,7 @@ final class Datasets } /** - * @return Closure|iterable + * @return Closure|iterable */ public static function get(string $name) { diff --git a/src/Expectation.php b/src/Expectation.php deleted file mode 100644 index 2815ef14..00000000 --- a/src/Expectation.php +++ /dev/null @@ -1,618 +0,0 @@ -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. - */ - 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 $expected - */ - public function toBe($expected): Expectation - { - Assert::assertSame($expected, $this->value); - - return $this; - } - - /** - * Asserts that the value is empty. - */ - public function toBeEmpty(): Expectation - { - Assert::assertEmpty($this->value); - - return $this; - } - - /** - * Asserts that the value is true. - */ - public function toBeTrue(): Expectation - { - Assert::assertTrue($this->value); - - return $this; - } - - /** - * Asserts that the value is false. - */ - public function toBeFalse(): Expectation - { - Assert::assertFalse($this->value); - - return $this; - } - - /** - * Asserts that the value is greater than $expected. - * - * @param int|float $expected - */ - public function toBeGreaterThan($expected): Expectation - { - Assert::assertGreaterThan($expected, $this->value); - - return $this; - } - - /** - * Asserts that the value is greater than or equal to $expected. - * - * @param int|float $expected - */ - public function toBeGreaterThanOrEqual($expected): Expectation - { - Assert::assertGreaterThanOrEqual($expected, $this->value); - - return $this; - } - - /** - * Asserts that the value is less than or equal to $expected. - * - * @param int|float $expected - */ - public function toBeLessThan($expected): Expectation - { - Assert::assertLessThan($expected, $this->value); - - return $this; - } - - /** - * Asserts that the value is less than $expected. - * - * @param int|float $expected - */ - public function toBeLessThanOrEqual($expected): Expectation - { - Assert::assertLessThanOrEqual($expected, $this->value); - - return $this; - } - - /** - * Asserts that $needle is an element of the value. - * - * @param mixed $needle - */ - public function toContain($needle): Expectation - { - if (is_string($this->value)) { - Assert::assertStringContainsString($needle, $this->value); - } else { - Assert::assertContains($needle, $this->value); - } - - return $this; - } - - /** - * Asserts that the value starts with $expected. - */ - public function toStartWith(string $expected): Expectation - { - Assert::assertStringStartsWith($expected, $this->value); - - return $this; - } - - /** - * Asserts that the value ends with $expected. - */ - public function toEndWith(string $expected): Expectation - { - Assert::assertStringEndsWith($expected, $this->value); - - return $this; - } - - /** - * Asserts that $count matches the number of elements of the value. - */ - public function toHaveCount(int $count): Expectation - { - Assert::assertCount($count, $this->value); - - return $this; - } - - /** - * Asserts that the value contains the property $name. - * - * @param mixed $value - */ - public function toHaveProperty(string $name, $value = null): Expectation - { - $this->toBeObject(); - - Assert::assertTrue(property_exists($this->value, $name)); - - if (func_num_args() > 1) { - /* @phpstan-ignore-next-line */ - Assert::assertEquals($value, $this->value->{$name}); - } - - return $this; - } - - /** - * Asserts that two variables have the same value. - * - * @param mixed $expected - */ - public function toEqual($expected): Expectation - { - Assert::assertEquals($expected, $this->value); - - return $this; - } - - /** - * Asserts that two variables have the same value. - * The contents of $expected and the $this->value are - * canonicalized before they are compared. For instance, when the two - * variables $expected and $this->value are arrays, then these arrays - * are sorted before they are compared. When $expected and $this->value - * are objects, each object is converted to an array containing all - * private, protected and public attributes. - * - * @param mixed $expected - */ - public function toEqualCanonicalizing($expected): Expectation - { - Assert::assertEqualsCanonicalizing($expected, $this->value); - - return $this; - } - - /** - * Asserts that the absolute difference between the value and $expected - * is lower than $delta. - * - * @param mixed $expected - */ - public function toEqualWithDelta($expected, float $delta): Expectation - { - Assert::assertEqualsWithDelta($expected, $this->value, $delta); - - return $this; - } - - /** - * Asserts that the value is infinite. - */ - public function toBeInfinite(): Expectation - { - Assert::assertInfinite($this->value); - - return $this; - } - - /** - * Asserts that the value is an instance of $class. - * - * @param string $class - */ - public function toBeInstanceOf($class): Expectation - { - /* @phpstan-ignore-next-line */ - Assert::assertInstanceOf($class, $this->value); - - return $this; - } - - /** - * Asserts that the value is an array. - */ - public function toBeArray(): Expectation - { - Assert::assertIsArray($this->value); - - return $this; - } - - /** - * Asserts that the value is of type bool. - */ - public function toBeBool(): Expectation - { - Assert::assertIsBool($this->value); - - return $this; - } - - /** - * Asserts that the value is of type callable. - */ - public function toBeCallable(): Expectation - { - Assert::assertIsCallable($this->value); - - return $this; - } - - /** - * Asserts that the value is of type float. - */ - public function toBeFloat(): Expectation - { - Assert::assertIsFloat($this->value); - - return $this; - } - - /** - * Asserts that the value is of type int. - */ - public function toBeInt(): Expectation - { - Assert::assertIsInt($this->value); - - return $this; - } - - /** - * Asserts that the value is of type iterable. - */ - public function toBeIterable(): Expectation - { - Assert::assertIsIterable($this->value); - - return $this; - } - - /** - * Asserts that the value is of type numeric. - */ - public function toBeNumeric(): Expectation - { - Assert::assertIsNumeric($this->value); - - return $this; - } - - /** - * Asserts that the value is of type object. - */ - public function toBeObject(): Expectation - { - Assert::assertIsObject($this->value); - - return $this; - } - - /** - * Asserts that the value is of type resource. - */ - public function toBeResource(): Expectation - { - Assert::assertIsResource($this->value); - - return $this; - } - - /** - * Asserts that the value is of type scalar. - */ - public function toBeScalar(): Expectation - { - Assert::assertIsScalar($this->value); - - return $this; - } - - /** - * Asserts that the value is of type string. - */ - public function toBeString(): Expectation - { - Assert::assertIsString($this->value); - - return $this; - } - - /** - * Asserts that the value is NAN. - */ - public function toBeNan(): Expectation - { - Assert::assertNan($this->value); - - return $this; - } - - /** - * Asserts that the value is null. - */ - public function toBeNull(): Expectation - { - Assert::assertNull($this->value); - - return $this; - } - - /** - * Asserts that the value array has the provided $key. - * - * @param string|int $key - * @param mixed $value - */ - public function toHaveKey($key, $value = null): Expectation - { - if (is_object($this->value) && method_exists($this->value, 'toArray')) { - $array = $this->value->toArray(); - } else { - $array = (array) $this->value; - } - - Assert::assertArrayHasKey($key, $array); - - if (func_num_args() > 1) { - Assert::assertEquals($value, $array[$key]); - } - - return $this; - } - - /** - * Asserts that the value array has the provided $keys. - * - * @param array $keys - */ - public function toHaveKeys(array $keys): Expectation - { - foreach ($keys as $key) { - $this->toHaveKey($key); - } - - return $this; - } - - /** - * Asserts that the value is a directory. - */ - public function toBeDirectory(): Expectation - { - Assert::assertDirectoryExists($this->value); - - return $this; - } - - /** - * Asserts that the value is a directory and is readable. - */ - public function toBeReadableDirectory(): Expectation - { - Assert::assertDirectoryIsReadable($this->value); - - return $this; - } - - /** - * Asserts that the value is a directory and is writable. - */ - public function toBeWritableDirectory(): Expectation - { - Assert::assertDirectoryIsWritable($this->value); - - return $this; - } - - /** - * Asserts that the value is a file. - */ - public function toBeFile(): Expectation - { - Assert::assertFileExists($this->value); - - return $this; - } - - /** - * Asserts that the value is a file and is readable. - */ - public function toBeReadableFile(): Expectation - { - Assert::assertFileIsReadable($this->value); - - return $this; - } - - /** - * Asserts that the value is a file and is writable. - */ - public function toBeWritableFile(): Expectation - { - Assert::assertFileIsWritable($this->value); - - return $this; - } - - /** - * Asserts that the value array matches the given array subset. - * - * @param array $array - */ - public function toMatchArray($array): Expectation - { - if (is_object($this->value) && method_exists($this->value, 'toArray')) { - $valueAsArray = $this->value->toArray(); - } else { - $valueAsArray = (array) $this->value; - } - - foreach ($array as $key => $value) { - Assert::assertArrayHasKey($key, $valueAsArray); - - Assert::assertEquals( - $value, - $valueAsArray[$key], - sprintf( - 'Failed asserting that an array has a key %s with the value %s.', - $this->export($key), - $this->export($valueAsArray[$key]), - ), - ); - } - - return $this; - } - - /** - * Asserts that the value object matches a subset - * of the properties of an given object. - * - * @param array|object $object - */ - public function toMatchObject($object): Expectation - { - foreach ((array) $object as $property => $value) { - Assert::assertTrue(property_exists($this->value, $property)); - - /* @phpstan-ignore-next-line */ - $propertyValue = $this->value->{$property}; - Assert::assertEquals( - $value, - $propertyValue, - sprintf( - 'Failed asserting that an object has a property %s with the value %s.', - $this->export($property), - $this->export($propertyValue), - ), - ); - } - - return $this; - } - - /** - * Asserts that the value matches a regular expression. - */ - public function toMatch(string $expression): Expectation - { - Assert::assertMatchesRegularExpression($expression, $this->value); - - return $this; - } - - /** - * Asserts that the value matches a constraint. - */ - public function toMatchConstraint(Constraint $constraint): Expectation - { - Assert::assertThat($this->value, $constraint); - - return $this; - } - - /** - * Exports the given value. - * - * @param mixed $value - */ - private function export($value): string - { - if ($this->exporter === null) { - $this->exporter = new Exporter(); - } - - return $this->exporter->export($value); - } - - /** - * 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/globals.php b/src/Functions.php similarity index 83% rename from src/globals.php rename to src/Functions.php index ed642a21..a7e1354a 100644 --- a/src/globals.php +++ b/src/Functions.php @@ -3,13 +3,11 @@ declare(strict_types=1); use Pest\Datasets; -use Pest\Expectation; use Pest\PendingObjects\AfterEachCall; use Pest\PendingObjects\BeforeEachCall; use Pest\PendingObjects\TestCall; use Pest\PendingObjects\UsesCall; use Pest\Support\Backtrace; -use Pest\Support\Extendable; use Pest\Support\HigherOrderTapProxy; use Pest\TestSuite; use PHPUnit\Framework\TestCase; @@ -37,7 +35,7 @@ function beforeEach(Closure $closure = null): BeforeEachCall /** * Registers the given dataset. * - * @param Closure|iterable $dataset + * @param Closure|iterable $dataset */ function dataset(string $name, $dataset): void { @@ -64,7 +62,7 @@ function uses(string ...$classAndTraits): UsesCall */ function test(string $description = null, Closure $closure = null) { - if ($description === null && TestSuite::getInstance()->test) { + if ($description === null && TestSuite::getInstance()->test !== null) { return new HigherOrderTapProxy(TestSuite::getInstance()->test); } @@ -102,23 +100,7 @@ function afterEach(Closure $closure = null): AfterEachCall /** * Runs the given closure after all tests in the current file. */ -function afterAll(Closure $closure = null): void +function afterAll(Closure $closure): void { TestSuite::getInstance()->afterAll->set($closure); } - -/** - * Creates a new expectation. - * - * @param mixed $value the Value - * - * @return Expectation|Extendable - */ -function expect($value = null) -{ - if (func_num_args() === 0) { - return new Extendable(Expectation::class); - } - - return test()->expect($value); -} diff --git a/src/OppositeExpectation.php b/src/OppositeExpectation.php deleted file mode 100644 index 9e045eb9..00000000 --- a/src/OppositeExpectation.php +++ /dev/null @@ -1,100 +0,0 @@ -original = $original; - } - - /** - * Asserts that the value array not has the provided $keys. - * - * @param array $keys - */ - public function toHaveKeys(array $keys): Expectation - { - foreach ($keys as $key) { - try { - $this->original->toHaveKey($key); - } catch (ExpectationFailedException $e) { - continue; - } - - $this->throwExpectationFailedExpection('toHaveKey', [$key]); - } - - return $this->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; - } - - // @phpstan-ignore-next-line - $this->throwExpectationFailedExpection($name, $arguments); - } - - /** - * 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; - } - - // @phpstan-ignore-next-line - $this->throwExpectationFailedExpection($name); - } - - /** - * Creates a new expectation failed exception - * with a nice readable message. - * - * @param array $arguments - */ - private function throwExpectationFailedExpection(string $name, array $arguments = []): void - { - $exporter = new Exporter(); - - $toString = function ($argument) use ($exporter): string { - return $exporter->shortenedExport($argument); - }; - - throw new ExpectationFailedException(sprintf('Expecting %s not %s %s.', $toString($this->original->value), strtolower((string) preg_replace('/(?extendableClass = $extendableClass; - } - - /** - * Register a custom extend. - */ - public function extend(string $name, Closure $extend): void - { - $this->extendableClass::extend($name, $extend); - } -} diff --git a/src/TeamCity.php b/src/TeamCity.php index b252ab38..02e5ce8d 100644 --- a/src/TeamCity.php +++ b/src/TeamCity.php @@ -56,7 +56,7 @@ final class TeamCity extends DefaultResultPrinter /** @phpstan-ignore-next-line */ public function startTestSuite(TestSuite $suite): void { - $this->flowId = getmypid(); + $this->flowId = (int) getmypid(); if (!$this->isSummaryTestCountPrinted) { $this->printEvent( diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index b8319ef8..6f966abc 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -2,232 +2,6 @@ PASS Tests\CustomTestCase\ExecutedTest ✓ that gets executed - PASS Tests\Expect\extend - ✓ it macros true is true - ✓ it macros false is not true - ✓ it macros true is true with argument - ✓ it macros false is not true with argument - - PASS Tests\Expect\not - ✓ not property calls - - PASS Tests\Expect\toBe - ✓ expect true → toBeTrue → and false → toBeFalse - ✓ 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\toBeDirectory - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toBeEmpty - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toBeFalse - ✓ strict comparisons - ✓ failures - ✓ not failures - - PASS Tests\Expect\toBeFile - ✓ pass - ✓ 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\toBeReadableDirectory - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toBeReadableFile - ✓ 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\toBeTrue - ✓ strict comparisons - ✓ failures - ✓ not failures - - PASS Tests\Expect\toBeWritableDirectory - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toBeWritableFile - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toContain - ✓ passes strings - ✓ passes arrays - ✓ failures - ✓ not failures - - PASS Tests\Expect\toEndWith - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toEqual - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toEqualCanonicalizing - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toEqualWithDelta - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toHaveCount - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toHaveKey - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toHaveKeys - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toHaveProperty - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toMatch - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toMatchArray - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toMatchConstraint - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toMatchObject - ✓ pass - ✓ failures - ✓ not failures - - PASS Tests\Expect\toStartWith - ✓ pass - ✓ failures - ✓ not failures - PASS Tests\Features\AfterAll ✓ deletes file after all @@ -340,7 +114,7 @@ ✓ trait applied in this file PASS Tests\Playground - ✓ basic + ✓ numeric ranges PASS Tests\Plugins\Traits ✓ it allows global uses @@ -410,5 +184,5 @@ ✓ depends run test only once ✓ depends works with the correct test name - Tests: 7 skipped, 242 passed + Tests: 7 skipped, 106 passed \ No newline at end of file diff --git a/tests/Expect/extend.php b/tests/Expect/extend.php deleted file mode 100644 index 4be88241..00000000 --- a/tests/Expect/extend.php +++ /dev/null @@ -1,29 +0,0 @@ -extend('toBeAMacroExpectation', function () { - $this->toBeTrue(); - - return $this; -}); - -expect()->extend('toBeAMacroExpectationWithArguments', function (bool $value) { - $this->toBe($value); - - return $this; -}); - -it('macros true is true', function () { - expect(true)->toBeAMacroExpectation(); -}); - -it('macros false is not true', function () { - expect(false)->not->toBeAMacroExpectation(); -}); - -it('macros true is true with argument', function () { - expect(true)->toBeAMacroExpectationWithArguments(true); -}); - -it('macros false is not true with argument', function () { - expect(false)->not->toBeAMacroExpectationWithArguments(true); -}); diff --git a/tests/Expect/not.php b/tests/Expect/not.php deleted file mode 100644 index 79220b19..00000000 --- a/tests/Expect/not.php +++ /dev/null @@ -1,10 +0,0 @@ -toBeTrue() - ->not()->toBeFalse() - ->not->toBeFalse - ->and(false) - ->toBeFalse(); -}); diff --git a/tests/Expect/toBe.php b/tests/Expect/toBe.php deleted file mode 100644 index ef2bce5a..00000000 --- a/tests/Expect/toBe.php +++ /dev/null @@ -1,20 +0,0 @@ -toBeTrue()->and(false)->toBeFalse(); - -test('strict comparisons', function () { - $nuno = new stdClass(); - $dries = new stdClass(); - - expect($nuno)->toBe($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); diff --git a/tests/Expect/toBeArray.php b/tests/Expect/toBeArray.php deleted file mode 100644 index 3fcec231..00000000 --- a/tests/Expect/toBeArray.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 5dc37b21..00000000 --- a/tests/Expect/toBeBool.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 2bd8f139..00000000 --- a/tests/Expect/toBeCallable.php +++ /dev/null @@ -1,18 +0,0 @@ -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/toBeDirectory.php b/tests/Expect/toBeDirectory.php deleted file mode 100644 index f30df144..00000000 --- a/tests/Expect/toBeDirectory.php +++ /dev/null @@ -1,17 +0,0 @@ -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/toBeEmpty.php b/tests/Expect/toBeEmpty.php deleted file mode 100644 index 05e5180a..00000000 --- a/tests/Expect/toBeEmpty.php +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 1371c86e..00000000 --- a/tests/Expect/toBeFalse.php +++ /dev/null @@ -1,15 +0,0 @@ -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/toBeFile.php b/tests/Expect/toBeFile.php deleted file mode 100644 index e8bc59d1..00000000 --- a/tests/Expect/toBeFile.php +++ /dev/null @@ -1,23 +0,0 @@ -tempFile = sys_get_temp_dir() . '/fake.file'); -}); - -afterEach(function () { - unlink($this->tempFile); -}); - -test('pass', function () { - expect($this->tempFile)->toBeFile(); -}); - -test('failures', function () { - expect('/random/path/whatever.file')->toBeFile(); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect($this->tempFile)->not->toBeFile(); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeFloat.php b/tests/Expect/toBeFloat.php deleted file mode 100644 index 69aa2306..00000000 --- a/tests/Expect/toBeFloat.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index ed840ed6..00000000 --- a/tests/Expect/toBeGreatherThan.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 3b1cd029..00000000 --- a/tests/Expect/toBeGreatherThanOrEqual.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index ebcb0a36..00000000 --- a/tests/Expect/toBeInfinite.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 03b3e881..00000000 --- a/tests/Expect/toBeInstanceOf.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 9eb1b3db..00000000 --- a/tests/Expect/toBeInt.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index fca23688..00000000 --- a/tests/Expect/toBeIterable.php +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 08db8545..00000000 --- a/tests/Expect/toBeLessThan.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index c9f00577..00000000 --- a/tests/Expect/toBeLessThanOrEqual.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 0767f1ad..00000000 --- a/tests/Expect/toBeNAN.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 2bd7d987..00000000 --- a/tests/Expect/toBeNull.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 710ca236..00000000 --- a/tests/Expect/toBeNumeric.php +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index e227b4cb..00000000 --- a/tests/Expect/toBeObject.php +++ /dev/null @@ -1,16 +0,0 @@ - 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/toBeReadableDirectory.php b/tests/Expect/toBeReadableDirectory.php deleted file mode 100644 index 704109b5..00000000 --- a/tests/Expect/toBeReadableDirectory.php +++ /dev/null @@ -1,15 +0,0 @@ -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/toBeReadableFile.php b/tests/Expect/toBeReadableFile.php deleted file mode 100644 index 756046fa..00000000 --- a/tests/Expect/toBeReadableFile.php +++ /dev/null @@ -1,23 +0,0 @@ -tempFile = sys_get_temp_dir() . '/fake.file'); -}); - -afterEach(function () { - unlink($this->tempFile); -}); - -test('pass', function () { - expect($this->tempFile)->toBeReadableFile(); -}); - -test('failures', function () { - expect('/random/path/whatever.file')->toBeReadableFile(); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect($this->tempFile)->not->toBeReadableFile(); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toBeResource.php b/tests/Expect/toBeResource.php deleted file mode 100644 index 575fabe3..00000000 --- a/tests/Expect/toBeResource.php +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 236c0e0b..00000000 --- a/tests/Expect/toBeScalar.php +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 91c31881..00000000 --- a/tests/Expect/toBeString.php +++ /dev/null @@ -1,16 +0,0 @@ -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/toBeTrue.php b/tests/Expect/toBeTrue.php deleted file mode 100644 index 8e998f9b..00000000 --- a/tests/Expect/toBeTrue.php +++ /dev/null @@ -1,15 +0,0 @@ -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/toBeWritableDirectory.php b/tests/Expect/toBeWritableDirectory.php deleted file mode 100644 index 88f96019..00000000 --- a/tests/Expect/toBeWritableDirectory.php +++ /dev/null @@ -1,15 +0,0 @@ -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/toBeWritableFile.php b/tests/Expect/toBeWritableFile.php deleted file mode 100644 index 96fe05c3..00000000 --- a/tests/Expect/toBeWritableFile.php +++ /dev/null @@ -1,23 +0,0 @@ -tempFile = sys_get_temp_dir() . '/fake.file'); -}); - -afterEach(function () { - unlink($this->tempFile); -}); - -test('pass', function () { - expect($this->tempFile)->toBeWritableFile(); -}); - -test('failures', function () { - expect('/random/path/whatever.file')->toBeWritableFile(); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect($this->tempFile)->not->toBeWritableFile(); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toContain.php b/tests/Expect/toContain.php deleted file mode 100644 index 04d586ff..00000000 --- a/tests/Expect/toContain.php +++ /dev/null @@ -1,19 +0,0 @@ -toContain(42); -}); - -test('passes arrays', function () { - expect('Nuno')->toContain('Nu'); -}); - -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/toEndWith.php b/tests/Expect/toEndWith.php deleted file mode 100644 index e669795e..00000000 --- a/tests/Expect/toEndWith.php +++ /dev/null @@ -1,15 +0,0 @@ -toEndWith('name'); -}); - -test('failures', function () { - expect('username')->toEndWith('password'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('username')->not->toEndWith('name'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toEqual.php b/tests/Expect/toEqual.php deleted file mode 100644 index de0b7e50..00000000 --- a/tests/Expect/toEqual.php +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 5e1178b9..00000000 --- a/tests/Expect/toEqualCanonicalizing.php +++ /dev/null @@ -1,16 +0,0 @@ -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/toEqualWithDelta.php b/tests/Expect/toEqualWithDelta.php deleted file mode 100644 index bb78b86d..00000000 --- a/tests/Expect/toEqualWithDelta.php +++ /dev/null @@ -1,15 +0,0 @@ -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); diff --git a/tests/Expect/toHaveCount.php b/tests/Expect/toHaveCount.php deleted file mode 100644 index a1948260..00000000 --- a/tests/Expect/toHaveCount.php +++ /dev/null @@ -1,15 +0,0 @@ -toHaveCount(3); -}); - -test('failures', function () { - expect([1, 2, 3])->toHaveCount(4); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect([1, 2, 3])->not->toHaveCount(3); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toHaveKey.php b/tests/Expect/toHaveKey.php deleted file mode 100644 index 1695688b..00000000 --- a/tests/Expect/toHaveKey.php +++ /dev/null @@ -1,15 +0,0 @@ - 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); diff --git a/tests/Expect/toHaveKeys.php b/tests/Expect/toHaveKeys.php deleted file mode 100644 index a09c8809..00000000 --- a/tests/Expect/toHaveKeys.php +++ /dev/null @@ -1,15 +0,0 @@ - 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'c']); -}); - -test('failures', function () { - expect(['a' => 1, 'b', 'c' => 'world'])->toHaveKeys(['a', 'd']); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect(['a' => 1, 'hello' => 'world', 'c'])->not->toHaveKeys(['hello', 'c']); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toHaveProperty.php b/tests/Expect/toHaveProperty.php deleted file mode 100644 index 19b4c92e..00000000 --- a/tests/Expect/toHaveProperty.php +++ /dev/null @@ -1,22 +0,0 @@ -foo = 'bar'; -$obj->fooNull = null; - -test('pass', function () use ($obj) { - expect($obj)->toHaveProperty('foo'); - expect($obj)->toHaveProperty('foo', 'bar'); - expect($obj)->toHaveProperty('fooNull'); - expect($obj)->toHaveProperty('fooNull', null); -}); - -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/Expect/toMatch.php b/tests/Expect/toMatch.php deleted file mode 100644 index 9088a3c4..00000000 --- a/tests/Expect/toMatch.php +++ /dev/null @@ -1,15 +0,0 @@ -toMatch('/^hello wo.*$/i'); -}); - -test('failures', function () { - expect('Hello World')->toMatch('/^hello$/i'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('Hello World')->not->toMatch('/^hello wo.*$/i'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toMatchArray.php b/tests/Expect/toMatchArray.php deleted file mode 100644 index b1646b9e..00000000 --- a/tests/Expect/toMatchArray.php +++ /dev/null @@ -1,31 +0,0 @@ -user = [ - 'id' => 1, - 'name' => 'Nuno', - 'email' => 'enunomaduro@gmail.com', - ]; -}); - -test('pass', function () { - expect($this->user)->toMatchArray([ - 'name' => 'Nuno', - 'email' => 'enunomaduro@gmail.com', - ]); -}); - -test('failures', function () { - expect($this->user)->toMatchArray([ - 'name' => 'Not the same name', - 'email' => 'enunomaduro@gmail.com', - ]); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect($this->user)->not->toMatchArray([ - 'id' => 1, - ]); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toMatchConstraint.php b/tests/Expect/toMatchConstraint.php deleted file mode 100644 index e5b4b681..00000000 --- a/tests/Expect/toMatchConstraint.php +++ /dev/null @@ -1,16 +0,0 @@ -toMatchConstraint(new IsTrue()); -}); - -test('failures', function () { - expect(false)->toMatchConstraint(new IsTrue()); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect(true)->not->toMatchConstraint(new IsTrue()); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toMatchObject.php b/tests/Expect/toMatchObject.php deleted file mode 100644 index fd2c358b..00000000 --- a/tests/Expect/toMatchObject.php +++ /dev/null @@ -1,31 +0,0 @@ -user = (object) [ - 'id' => 1, - 'name' => 'Nuno', - 'email' => 'enunomaduro@gmail.com', - ]; -}); - -test('pass', function () { - expect($this->user)->toMatchObject([ - 'name' => 'Nuno', - 'email' => 'enunomaduro@gmail.com', - ]); -}); - -test('failures', function () { - expect($this->user)->toMatchObject([ - 'name' => 'Not the same name', - 'email' => 'enunomaduro@gmail.com', - ]); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect($this->user)->not->toMatchObject([ - 'id' => 1, - ]); -})->throws(ExpectationFailedException::class); diff --git a/tests/Expect/toStartWith.php b/tests/Expect/toStartWith.php deleted file mode 100644 index 64465869..00000000 --- a/tests/Expect/toStartWith.php +++ /dev/null @@ -1,15 +0,0 @@ -toStartWith('user'); -}); - -test('failures', function () { - expect('username')->toStartWith('password'); -})->throws(ExpectationFailedException::class); - -test('not failures', function () { - expect('username')->not->toStartWith('user'); -})->throws(ExpectationFailedException::class); diff --git a/tests/Features/AfterEach.php b/tests/Features/AfterEach.php index e16f8529..cdaed1d3 100644 --- a/tests/Features/AfterEach.php +++ b/tests/Features/AfterEach.php @@ -6,7 +6,7 @@ beforeEach(function () use ($state) { $this->state = $state; }); -afterEach(function () use ($state) { +afterEach(function () { $this->state->bar = 2; }); diff --git a/tests/Features/Datasets.php b/tests/Features/Datasets.php index 54618d92..dabda849 100644 --- a/tests/Features/Datasets.php +++ b/tests/Features/Datasets.php @@ -116,7 +116,7 @@ $namedDatasets = [ new Bar(), ]; -test('lazy named datasets', function ($text) use ($state, $datasets) { +test('lazy named datasets', function ($text) { expect(true)->toBeTrue(); })->with($namedDatasets); diff --git a/tests/Unit/Actions/AddsTests.php b/tests/Unit/Actions/AddsTests.php index 9f1beec0..ea8e2a38 100644 --- a/tests/Unit/Actions/AddsTests.php +++ b/tests/Unit/Actions/AddsTests.php @@ -22,7 +22,7 @@ test('default php unit tests', function () { expect($testSuite->tests())->toHaveCount(1); }); -it('removes warnings', function () use ($pestTestCase) { +it('removes warnings', function () { $testSuite = new TestSuite(); $warningTestCase = new WarningTestCase('No tests found in class "Pest\TestCase".'); $testSuite->addTest($warningTestCase);