From a51c354268e24a23fef44b3e811e5280b1381979 Mon Sep 17 00:00:00 2001 From: Alex Martin Date: Sun, 2 Aug 2020 19:25:54 +0200 Subject: [PATCH 01/17] Update globals.php Typo. --- src/globals.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/globals.php b/src/globals.php index 7e85e9a6..87bc6c4e 100644 --- a/src/globals.php +++ b/src/globals.php @@ -44,8 +44,8 @@ function dataset(string $name, $dataset): void } /** - * The uses function adds the binds the - * given arguments to test closures. + * The uses function binds the given + * arguments to test closures. */ function uses(string ...$classAndTraits): UsesCall { From 64bb85372056bd5a1d86dcc4ec1f04c0512f53d0 Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Mon, 3 Aug 2020 21:39:58 +0200 Subject: [PATCH 02/17] fix: correctly avoid interactions --- src/Laravel/Commands/PestInstallCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index 1e924e09..2885f629 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -60,7 +60,9 @@ final class PestInstallCommand extends Command $this->output->success('`tests/Pest.php` created successfully.'); $this->output->success('`tests/Helpers.php` created successfully.'); - (new \Pest\Console\Thanks($this->output))(); + if (! (bool) $this->option('no-interaction')) { + (new \Pest\Console\Thanks($this->output))(); + } } /** From 128ff1006fe65acf78de6fd14afc105f3dfcaa9d Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 3 Aug 2020 20:48:45 +0100 Subject: [PATCH 03/17] chore: removes broken rector set --- rector.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/rector.yaml b/rector.yaml index 317a9e8e..18392829 100644 --- a/rector.yaml +++ b/rector.yaml @@ -3,7 +3,6 @@ parameters: sets: - 'action-injection-to-constructor-injection' - 'array-str-functions-to-static-call' - - 'celebrity' - 'phpstan' - 'phpunit-code-quality' - 'solid' From 4009177e563a850c960584a526f1016fb997bfca Mon Sep 17 00:00:00 2001 From: Enzo Innocenzi Date: Mon, 3 Aug 2020 21:49:09 +0200 Subject: [PATCH 04/17] style: fix unary_operator_space --- src/Laravel/Commands/PestInstallCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index 2885f629..c5247548 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -60,7 +60,7 @@ final class PestInstallCommand extends Command $this->output->success('`tests/Pest.php` created successfully.'); $this->output->success('`tests/Helpers.php` created successfully.'); - if (! (bool) $this->option('no-interaction')) { + if (!(bool) $this->option('no-interaction')) { (new \Pest\Console\Thanks($this->output))(); } } From 356b9c01c7032ca86001594a0e445f3d9ea68e66 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Mon, 3 Aug 2020 21:03:17 +0100 Subject: [PATCH 05/17] Added additional rector sets --- rector.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rector.yaml b/rector.yaml index 18392829..bf3cd023 100644 --- a/rector.yaml +++ b/rector.yaml @@ -8,6 +8,11 @@ parameters: - 'solid' - 'doctrine-code-quality' - 'code-quality' + - 'php53' + - 'php54' + - 'php55' + - 'php56' + - 'php70' - 'php71' - 'php72' - 'php73' From 50a273f1f136dfc5f6d540e18432515e57c04af8 Mon Sep 17 00:00:00 2001 From: Musa <40173603+voyula@users.noreply.github.com> Date: Tue, 4 Aug 2020 12:54:49 +0300 Subject: [PATCH 06/17] Add Yaml Support For: https://github.com/pestphp/pest/blob/master/rector.yaml --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 79c3e0d8..e8ed8f32 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,5 +14,5 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false -[*.yml] +[*.{yml,yaml}] indent_size = 2 From 3cfadee2bb960457d4c1e4e9cd51faff309808ff Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Fri, 7 Aug 2020 11:23:45 +0100 Subject: [PATCH 07/17] PHP 8 and PHPUnit 9.3 support --- .github/workflows/static.yml | 4 +-- .github/workflows/tests.yml | 34 ++++++++++++-------------- composer.json | 7 +++--- phpstan.neon | 1 + src/Actions/ValidatesConfiguration.php | 7 ++---- src/Factories/TestCaseFactory.php | 11 +++++++-- src/PendingObjects/TestCall.php | 7 ++++++ src/Support/Container.php | 15 ++++++------ src/Support/HigherOrderMessage.php | 11 ++++++++- src/Support/Reflection.php | 30 +++++++++++++++++++++++ tests/.snapshots/success.txt | 16 ++++++------ 11 files changed, 95 insertions(+), 48 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0f54227d..e3860614 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -20,7 +20,7 @@ jobs: coverage: none - name: Install Dependencies - run: composer update --no-interaction --prefer-dist --no-progress + run: composer update --no-interaction --no-progress - name: Run Rector run: vendor/bin/rector process src --dry-run @@ -48,7 +48,7 @@ jobs: coverage: none - name: Install Dependencies - run: composer update --prefer-stable --no-interaction --prefer-dist --no-progress + run: composer update --prefer-stable --no-interaction --no-progress - name: Run PHPStan run: vendor/bin/phpstan analyse --no-progress diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dfb07edc..883e3fd6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,43 +6,39 @@ jobs: ci: runs-on: ${{ matrix.os }} strategy: - fail-fast: true matrix: os: [ubuntu-latest, macos-latest, windows-latest] - php: [7.3, 7.4] + php: ['7.3', '7.4', '8.0'] dependency-version: [prefer-lowest, prefer-stable] - name: Tests P${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} + name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }} steps: - - name: Checkout uses: actions/checkout@v2 - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ~/.composer/cache/files - key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, mbstring, zip + tools: composer:v2 coverage: none - - name: Install Composer dependencies - run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-dist + - name: Setup Problem Matches + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install PHP 7 dependencies + run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress + if: "matrix.php < 8" + + - name: Install PHP 8 dependencies + run: composer update --${{ matrix.dependency-version }} --ignore-platform-req=php --no-interaction --no-progress + if: "matrix.php >= 8" - name: Unit Tests run: php bin/pest --colors=always --exclude-group=integration - name: Integration Tests run: php bin/pest --colors=always --group=integration - - - name: Setup problem matchers for PHP - run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - - name: Setup problem matchers for Pest - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" diff --git a/composer.json b/composer.json index 837e6f11..9907d7e4 100644 --- a/composer.json +++ b/composer.json @@ -17,13 +17,12 @@ } ], "require": { - "php": "^7.3", + "php": "^7.3 || ^8.0", "nunomaduro/collision": "^5.0.0-BETA4", "pestphp/pest-plugin": "^0.3", "pestphp/pest-plugin-coverage": "^0.3", "pestphp/pest-plugin-init": "^0.3", - "phpunit/phpunit": "^9.2.6", - "sebastian/environment": "^5.1.2" + "phpunit/phpunit": "9.3.2" }, "autoload": { "psr-4": { @@ -45,7 +44,7 @@ "require-dev": { "illuminate/console": "^7.16.1", "illuminate/support": "^7.16.1", - "mockery/mockery": "^1.4.0", + "mockery/mockery": "^1.4.1", "pestphp/pest-dev-tools": "dev-master" }, "minimum-stability": "dev", diff --git a/phpstan.neon b/phpstan.neon index e133d425..6900f634 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -21,3 +21,4 @@ parameters: - "# with null as default value#" - "#has parameter \\$closure with default value.#" - "#has parameter \\$description with default value.#" + - "#Method Pest\\\\Support\\\\Reflection::getParameterClassName\\(\\) has a nullable return type declaration.#" diff --git a/src/Actions/ValidatesConfiguration.php b/src/Actions/ValidatesConfiguration.php index a2a6a481..1cbb19a9 100644 --- a/src/Actions/ValidatesConfiguration.php +++ b/src/Actions/ValidatesConfiguration.php @@ -6,8 +6,7 @@ namespace Pest\Actions; use Pest\Exceptions\AttributeNotSupportedYet; use Pest\Exceptions\FileOrFolderNotFound; -use PHPUnit\TextUI\Configuration\Configuration; -use PHPUnit\TextUI\Configuration\Registry; +use PHPUnit\TextUI\XmlConfiguration\Loader; /** * @internal @@ -30,9 +29,7 @@ final class ValidatesConfiguration throw new FileOrFolderNotFound('phpunit.xml'); } - $configuration = Registry::getInstance() - ->get($arguments[self::CONFIGURATION_KEY]) - ->phpunit(); + $configuration = (new Loader())->load($arguments[self::CONFIGURATION_KEY])->phpunit(); if ($configuration->processIsolation()) { throw new AttributeNotSupportedYet('processIsolation', 'true'); diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index f3e8e282..06a2a6fb 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -157,8 +157,15 @@ final class TestCaseFactory } /** - * Makes a fully qualified class name - * from the given filename. + * Makes a fully qualified class name from the current filename. + */ + public function getClassName(): string + { + return $this->makeClassFromFilename($this->filename); + } + + /** + * Makes a fully qualified class name from the given filename. */ public function makeClassFromFilename(string $filename): string { diff --git a/src/PendingObjects/TestCall.php b/src/PendingObjects/TestCall.php index 613a4a97..34aae3fc 100644 --- a/src/PendingObjects/TestCall.php +++ b/src/PendingObjects/TestCall.php @@ -9,6 +9,7 @@ use Pest\Factories\TestCaseFactory; use Pest\Support\Backtrace; use Pest\Support\NullClosure; use Pest\TestSuite; +use PHPUnit\Framework\ExecutionOrderDependency; use SebastianBergmann\Exporter\Exporter; /** @@ -91,6 +92,12 @@ final class TestCall */ public function depends(string ...$tests): TestCall { + $className = $this->testCaseFactory->getClassName(); + + $tests = array_map(function (string $test) use ($className): ExecutionOrderDependency { + return ExecutionOrderDependency::createFromDependsAnnotation($className, $test); + }, $tests); + $this->testCaseFactory ->factoryProxies ->add(Backtrace::file(), Backtrace::line(), 'setDependencies', [$tests]); diff --git a/src/Support/Container.php b/src/Support/Container.php index fa45f500..42175289 100644 --- a/src/Support/Container.php +++ b/src/Support/Container.php @@ -75,14 +75,15 @@ final class Container if ($constructor !== null) { $params = array_map( function (ReflectionParameter $param) use ($id) { - $candidate = null; + $candidate = Reflection::getParameterClassName($param); - if ($param->getType() !== null && $param->getType()->isBuiltin()) { - $candidate = $param->getName(); - } elseif ($param->getClass() !== null) { - $candidate = $param->getClass()->getName(); - } else { - throw ShouldNotHappen::fromMessage(sprintf('The type of `$%s` in `%s` cannot be determined.', $id, $param->getName())); + if ($candidate === null) { + $type = $param->getType(); + if ($type !== null && $type->isBuiltin()) { + $candidate = $param->getName(); + } else { + throw ShouldNotHappen::fromMessage(sprintf('The type of `$%s` in `%s` cannot be determined.', $id, $param->getName())); + } } return $this->get($candidate); diff --git a/src/Support/HigherOrderMessage.php b/src/Support/HigherOrderMessage.php index e5e4e21b..75e351b6 100644 --- a/src/Support/HigherOrderMessage.php +++ b/src/Support/HigherOrderMessage.php @@ -76,7 +76,7 @@ final class HigherOrderMessage Reflection::setPropertyValue($throwable, 'file', $this->filename); Reflection::setPropertyValue($throwable, 'line', $this->line); - if ($throwable->getMessage() === sprintf(self::UNDEFINED_METHOD, $this->methodName)) { + if ($throwable->getMessage() === self::getUndefinedMethodMessage($target, $this->methodName)) { /** @var \ReflectionClass $reflection */ $reflection = new ReflectionClass($target); /* @phpstan-ignore-next-line */ @@ -87,4 +87,13 @@ final class HigherOrderMessage throw $throwable; } } + + private static function getUndefinedMethodMessage(object $target, string $methodName): string + { + if (\PHP_MAJOR_VERSION >= 8) { + return sprintf(sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', get_class($target), $methodName))); + } + + return sprintf(self::UNDEFINED_METHOD, $methodName); + } } diff --git a/src/Support/Reflection.php b/src/Support/Reflection.php index 44805ba2..984cfef6 100644 --- a/src/Support/Reflection.php +++ b/src/Support/Reflection.php @@ -9,6 +9,8 @@ use Pest\Exceptions\ShouldNotHappen; use ReflectionClass; use ReflectionException; use ReflectionFunction; +use ReflectionNamedType; +use ReflectionParameter; use ReflectionProperty; /** @@ -117,4 +119,32 @@ final class Reflection $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($object, $value); } + + /** + * Get the class name of the given parameter's type, if possible. + * + * @see https://github.com/laravel/framework/blob/v6.18.25/src/Illuminate/Support/Reflector.php + */ + public static function getParameterClassName(ReflectionParameter $parameter): ?string + { + $type = $parameter->getType(); + + if (!$type instanceof ReflectionNamedType || $type->isBuiltin()) { + return null; + } + + $name = $type->getName(); + + if (($class = $parameter->getDeclaringClass()) instanceof ReflectionClass) { + if ($name === 'self') { + return $class->getName(); + } + + if ($name === 'parent' && ($parent = $class->getParentClass()) instanceof ReflectionClass) { + return $parent->getName(); + } + } + + return $name; + } } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index ebc40173..8334095a 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -219,14 +219,6 @@ ✓ it creates unique test case names with ('Name 1', Pest\Plugin Object (), true) #3 ✓ it creates unique test case names - count - PASS Tests\Features\Depends - ✓ first - ✓ second - ✓ depends - ✓ depends with ...params - ✓ depends with defined arguments - ✓ depends run test only once - PASS Tests\Features\Exceptions ✓ it gives access the the underlying expectException ✓ it catch exceptions @@ -337,5 +329,13 @@ WARN Tests\Visual\Success - visual snapshot of test suite on success + PASS Tests\Features\Depends + ✓ first + ✓ second + ✓ depends + ✓ depends with ...params + ✓ depends with defined arguments + ✓ depends run test only once + Tests: 6 skipped, 198 passed Time: 5.46s From d2db71bb7879ae0a32d52d88cd7456119732b495 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 9 Aug 2020 18:31:08 +0100 Subject: [PATCH 08/17] tests: update snapshots --- composer.json | 4 ++-- tests/.snapshots/success.txt | 3 +-- tests/Visual/Success.php | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 9907d7e4..e292481c 100644 --- a/composer.json +++ b/composer.json @@ -18,11 +18,11 @@ ], "require": { "php": "^7.3 || ^8.0", - "nunomaduro/collision": "^5.0.0-BETA4", + "nunomaduro/collision": "^5.0.0-BETA5", "pestphp/pest-plugin": "^0.3", "pestphp/pest-plugin-coverage": "^0.3", "pestphp/pest-plugin-init": "^0.3", - "phpunit/phpunit": "9.3.2" + "phpunit/phpunit": "9.3.3" }, "autoload": { "psr-4": { diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 8334095a..500f7a52 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -337,5 +337,4 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 6 skipped, 198 passed - Time: 5.46s + Tests: 6 skipped, 198 passed \ No newline at end of file diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index 14af013e..609f5b19 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -23,7 +23,7 @@ test('visual snapshot of test suite on success', function () { array_pop($output); array_pop($output); - expect(file_get_contents($snapshot))->toContain(implode("\n", $output)); + expect(implode("\n", $output))->toContain(file_get_contents($snapshot)); } })->skip(!getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')) ->skip(PHP_OS_FAMILY === 'Windows'); From 439ebcdcaf6607ab875da8c0ce453e05b5b2b096 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 9 Aug 2020 19:08:27 +0100 Subject: [PATCH 09/17] feat(expectation-api): adds failed assertations on not methods --- src/Expectation.php | 4 +++- src/OppositeExpectation.php | 24 ++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 71c4a82f..0770e367 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -16,9 +16,11 @@ final class Expectation /** * The expectation value. * + * @readonly + * * @var mixed */ - private $value; + public $value; /** * Creates a new expectation. diff --git a/src/OppositeExpectation.php b/src/OppositeExpectation.php index 4ab4449d..143d35c9 100644 --- a/src/OppositeExpectation.php +++ b/src/OppositeExpectation.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest; use PHPUnit\Framework\ExpectationFailedException; +use SebastianBergmann\Exporter\Exporter; /** * @internal @@ -40,7 +41,8 @@ final class OppositeExpectation return $this->original; } - throw new ExpectationFailedException(sprintf('@todo')); + // @phpstan-ignore-next-line + $this->throwExpectationFailedExpection($name, $arguments); } /** @@ -55,6 +57,24 @@ final class OppositeExpectation return $this->original; } - throw new ExpectationFailedException(sprintf('@todo')); + // @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('/(? Date: Wed, 12 Aug 2020 11:39:57 +0100 Subject: [PATCH 10/17] Require PHPUnit 7.3.7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e292481c..c97cdcd8 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "pestphp/pest-plugin": "^0.3", "pestphp/pest-plugin-coverage": "^0.3", "pestphp/pest-plugin-init": "^0.3", - "phpunit/phpunit": "9.3.3" + "phpunit/phpunit": "9.3.7" }, "autoload": { "psr-4": { From 98ed77942405ae96a964c9a9e95c719aeada1cfa Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 13:00:19 +0100 Subject: [PATCH 11/17] build: update Rector config to PHP --- rector.php | 31 +++++++++++++++++++++++++++++++ rector.yaml | 18 ------------------ 2 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 rector.php delete mode 100644 rector.yaml diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..3069da26 --- /dev/null +++ b/rector.php @@ -0,0 +1,31 @@ +parameters(); + + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + + $parameters->set(Option::SETS, [ + SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION, + SetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL, + SetList::CODE_QUALITY, + SetList::PHP_53, + SetList::PHP_54, + SetList::PHP_56, + SetList::PHP_70, + SetList::PHP_71, + SetList::PHP_72, + SetList::PHP_73, + SetList::PHPSTAN, + SetList::PHPUNIT_CODE_QUALITY, + SetList::SOLID, + ]); + + $parameters->set(Option::PATHS, [__DIR__.'/src', __DIR__.'/tests']); +}; diff --git a/rector.yaml b/rector.yaml deleted file mode 100644 index bf3cd023..00000000 --- a/rector.yaml +++ /dev/null @@ -1,18 +0,0 @@ -# rector.yaml -parameters: - sets: - - 'action-injection-to-constructor-injection' - - 'array-str-functions-to-static-call' - - 'phpstan' - - 'phpunit-code-quality' - - 'solid' - - 'doctrine-code-quality' - - 'code-quality' - - 'php53' - - 'php54' - - 'php55' - - 'php56' - - 'php70' - - 'php71' - - 'php72' - - 'php73' From 38344c99f1501a9dce5d3a83a511b8db63a76b01 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 14:45:55 +0100 Subject: [PATCH 12/17] style: apply Rector changes --- src/Concerns/TestCase.php | 5 +++-- src/Laravel/Commands/PestInstallCommand.php | 3 ++- src/Repositories/TestRepository.php | 3 ++- src/Support/ExceptionTrace.php | 2 +- src/Support/HigherOrderMessage.php | 2 +- src/Support/HigherOrderTapProxy.php | 5 +++-- src/TestSuite.php | 3 ++- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Concerns/TestCase.php b/src/Concerns/TestCase.php index 6c1d98ce..58d17059 100644 --- a/src/Concerns/TestCase.php +++ b/src/Concerns/TestCase.php @@ -9,6 +9,7 @@ use Pest\Expectation; use Pest\Support\ExceptionTrace; use Pest\TestSuite; use PHPUnit\Util\Test; +use Throwable; /** * To avoid inheritance conflicts, all the fields related @@ -143,7 +144,7 @@ trait TestCase * * @return mixed * - * @throws \Throwable + * @throws Throwable */ public function __test() { @@ -153,7 +154,7 @@ trait TestCase /** * @return mixed * - * @throws \Throwable + * @throws Throwable */ private function __callClosure(Closure $closure, array $arguments) { diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index c5247548..b1f34a45 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -6,6 +6,7 @@ namespace Pest\Laravel\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\File; +use Pest\Console\Thanks; use Pest\Exceptions\InvalidConsoleArgument; use Pest\Support\Str; @@ -61,7 +62,7 @@ final class PestInstallCommand extends Command $this->output->success('`tests/Helpers.php` created successfully.'); if (!(bool) $this->option('no-interaction')) { - (new \Pest\Console\Thanks($this->output))(); + (new Thanks($this->output))(); } } diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 09242448..cf36319e 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -11,6 +11,7 @@ use Pest\Exceptions\TestCaseClassOrTraitNotFound; use Pest\Factories\TestCaseFactory; use Pest\Support\Str; use Pest\TestSuite; +use PHPUnit\Framework\TestCase; /** * @internal @@ -52,7 +53,7 @@ final class TestRepository if ((!is_dir($path) && $filename === $path) || (is_dir($path) && $startsWith($filename, $path))) { foreach ($classOrTraits as $class) { if (class_exists($class)) { - if ($testCase->class !== \PHPUnit\Framework\TestCase::class) { + if ($testCase->class !== TestCase::class) { throw new TestCaseAlreadyInUse($testCase->class, $class, $filename); } $testCase->class = $class; diff --git a/src/Support/ExceptionTrace.php b/src/Support/ExceptionTrace.php index 72a1d829..014b88df 100644 --- a/src/Support/ExceptionTrace.php +++ b/src/Support/ExceptionTrace.php @@ -20,7 +20,7 @@ final class ExceptionTrace * * @return mixed * - * @throws \Throwable + * @throws Throwable */ public static function ensure(Closure $closure) { diff --git a/src/Support/HigherOrderMessage.php b/src/Support/HigherOrderMessage.php index 75e351b6..9f363b5a 100644 --- a/src/Support/HigherOrderMessage.php +++ b/src/Support/HigherOrderMessage.php @@ -77,7 +77,7 @@ final class HigherOrderMessage Reflection::setPropertyValue($throwable, 'line', $this->line); if ($throwable->getMessage() === self::getUndefinedMethodMessage($target, $this->methodName)) { - /** @var \ReflectionClass $reflection */ + /** @var ReflectionClass $reflection */ $reflection = new ReflectionClass($target); /* @phpstan-ignore-next-line */ $reflection = $reflection->getParentClass() ?: $reflection; diff --git a/src/Support/HigherOrderTapProxy.php b/src/Support/HigherOrderTapProxy.php index 9e9506d2..4b5664d3 100644 --- a/src/Support/HigherOrderTapProxy.php +++ b/src/Support/HigherOrderTapProxy.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest\Support; use ReflectionClass; +use Throwable; /** * @internal @@ -51,12 +52,12 @@ final class HigherOrderTapProxy try { // @phpstan-ignore-next-line return $this->target->{$property}; - } catch (\Throwable $throwable) { + } catch (Throwable $throwable) { Reflection::setPropertyValue($throwable, 'file', Backtrace::file()); Reflection::setPropertyValue($throwable, 'line', Backtrace::line()); if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_PROPERTY)) { - /** @var \ReflectionClass $reflection */ + /** @var ReflectionClass $reflection */ $reflection = (new ReflectionClass($this->target))->getParentClass(); Reflection::setPropertyValue($throwable, 'message', sprintf('Undefined property %s::$%s', $reflection->getName(), $property)); } diff --git a/src/TestSuite.php b/src/TestSuite.php index b9c232b2..63e58f4e 100644 --- a/src/TestSuite.php +++ b/src/TestSuite.php @@ -10,6 +10,7 @@ use Pest\Repositories\AfterEachRepository; use Pest\Repositories\BeforeAllRepository; use Pest\Repositories\BeforeEachRepository; use Pest\Repositories\TestRepository; +use PHPUnit\Framework\TestCase; /** * @internal @@ -19,7 +20,7 @@ final class TestSuite /** * Holds the current test case. * - * @var \PHPUnit\Framework\TestCase|null + * @var TestCase|null */ public $test; From 50cd1056eb818ee79d2ed54c24c737ea6d1cf1e3 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:24:00 +0100 Subject: [PATCH 13/17] feat(expectations): add file assertions --- src/Expectation.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Expectation.php b/src/Expectation.php index 0770e367..4e5b9633 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -414,6 +414,36 @@ final class Expectation 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; + } + /** * Dynamically calls methods on the class without any arguments. * From e1fbf56f3d96484289ca20def1bcfab883bb6932 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:51:35 +0100 Subject: [PATCH 14/17] tests(expectations): fix method in test file --- tests/Expect/toBeReadableDirectory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Expect/toBeReadableDirectory.php b/tests/Expect/toBeReadableDirectory.php index 88f96019..704109b5 100644 --- a/tests/Expect/toBeReadableDirectory.php +++ b/tests/Expect/toBeReadableDirectory.php @@ -3,13 +3,13 @@ use PHPUnit\Framework\ExpectationFailedException; test('pass', function () { - expect(sys_get_temp_dir())->toBeWritableDirectory(); + expect(sys_get_temp_dir())->toBeReadableDirectory(); }); test('failures', function () { - expect('/random/path/whatever')->toBeWritableDirectory(); + expect('/random/path/whatever')->toBeReadableDirectory(); })->throws(ExpectationFailedException::class); test('not failures', function () { - expect(sys_get_temp_dir())->not->toBeWritableDirectory(); + expect(sys_get_temp_dir())->not->toBeReadableDirectory(); })->throws(ExpectationFailedException::class); From 8cc95802537482c11b9c279569d50057d9ba9a52 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:51:49 +0100 Subject: [PATCH 15/17] tests(expectations): add tests for file assertions --- tests/Expect/toBeFile.php | 23 +++++++++++++++++++++++ tests/Expect/toBeReadableFile.php | 23 +++++++++++++++++++++++ tests/Expect/toBeWritableFile.php | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/Expect/toBeFile.php create mode 100644 tests/Expect/toBeReadableFile.php create mode 100644 tests/Expect/toBeWritableFile.php diff --git a/tests/Expect/toBeFile.php b/tests/Expect/toBeFile.php new file mode 100644 index 00000000..e8bc59d1 --- /dev/null +++ b/tests/Expect/toBeFile.php @@ -0,0 +1,23 @@ +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/toBeReadableFile.php b/tests/Expect/toBeReadableFile.php new file mode 100644 index 00000000..756046fa --- /dev/null +++ b/tests/Expect/toBeReadableFile.php @@ -0,0 +1,23 @@ +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/toBeWritableFile.php b/tests/Expect/toBeWritableFile.php new file mode 100644 index 00000000..96fe05c3 --- /dev/null +++ b/tests/Expect/toBeWritableFile.php @@ -0,0 +1,23 @@ +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); From 3695736b3a725c00620166f122d8d570e116ebe7 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Wed, 12 Aug 2020 12:58:01 +0100 Subject: [PATCH 16/17] tests: update snapshots --- tests/.snapshots/success.txt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 500f7a52..4d1480dd 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -39,6 +39,11 @@ PASS Tests\Expect\toBeFalse ✓ strict comparisons ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeFile + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeFloat @@ -109,6 +114,11 @@ PASS Tests\Expect\toBeReadableDirectory ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeReadableFile + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toBeResource @@ -134,6 +144,11 @@ PASS Tests\Expect\toBeWritableDirectory ✓ pass ✓ failures + ✓ not failures + + PASS Tests\Expect\toBeWritableFile + ✓ pass + ✓ failures ✓ not failures PASS Tests\Expect\toContain @@ -337,4 +352,6 @@ ✓ depends with defined arguments ✓ depends run test only once - Tests: 6 skipped, 198 passed \ No newline at end of file + Tests: 6 skipped, 207 passed + Time: 5.89s + From 708b4b1d498ed420b47c12439c36a91a68ae0320 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Thu, 13 Aug 2020 10:03:15 +0100 Subject: [PATCH 17/17] tests: fix snapshots --- tests/.snapshots/success.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 4d1480dd..a0769abf 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -353,5 +353,3 @@ ✓ depends run test only once Tests: 6 skipped, 207 passed - Time: 5.89s -