From c97fd1712066d542c4ee788f7c1511194417fe6c Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 14 May 2020 23:03:56 +0200 Subject: [PATCH] feat(helpers): adds helpers file --- src/Actions/LoadStructure.php | 1 + src/Laravel/Commands/PestInstallCommand.php | 19 +++++++++++++++---- stubs/Helpers.php | 12 ++++++++++++ tests/Features/Mocks.php | 2 +- tests/Helpers.php | 8 ++++++++ 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 stubs/Helpers.php create mode 100644 tests/Helpers.php diff --git a/src/Actions/LoadStructure.php b/src/Actions/LoadStructure.php index 35f816cf..49d30b84 100644 --- a/src/Actions/LoadStructure.php +++ b/src/Actions/LoadStructure.php @@ -22,6 +22,7 @@ final class LoadStructure */ private const STRUCTURE = [ 'Datasets.php', + 'Helpers.php', 'Pest.php', 'Datasets', ]; diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index fe4facfc..17a71095 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -33,18 +33,29 @@ final class PestInstallCommand extends Command public function handle(): void { /* @phpstan-ignore-next-line */ - $target = base_path('tests/Pest.php'); + $pest = base_path('tests/Pest.php'); + /* @phpstan-ignore-next-line */ + $helpers = base_path('tests/Helpers.php'); - if (File::exists($target)) { - throw new InvalidConsoleArgument(sprintf('%s already exist', $target)); + foreach ([$pest, $helpers] as $file) { + if (File::exists($file)) { + throw new InvalidConsoleArgument(sprintf('%s already exist', $file)); + } } File::copy(implode(DIRECTORY_SEPARATOR, [ dirname(__DIR__, 3), 'stubs', 'Pest.php', - ]), $target); + ]), $pest); + + File::copy(implode(DIRECTORY_SEPARATOR, [ + dirname(__DIR__, 3), + 'stubs', + 'Helpers.php', + ]), $helpers); $this->output->success('`tests/Pest.php` created successfully.'); + $this->output->success('`tests/Helpers.php` created successfully.'); } } diff --git a/stubs/Helpers.php b/stubs/Helpers.php new file mode 100644 index 00000000..895a97d8 --- /dev/null +++ b/stubs/Helpers.php @@ -0,0 +1,12 @@ +actingAs($user, $driver); +} diff --git a/tests/Features/Mocks.php b/tests/Features/Mocks.php index 1760f057..f914c6bd 100644 --- a/tests/Features/Mocks.php +++ b/tests/Features/Mocks.php @@ -6,7 +6,7 @@ interface Foo } it('has bar', function () { - $mock = Mockery::mock(Foo::class); + $mock = mock(Foo::class); $mock->shouldReceive('bar') ->times(1) ->andReturn(2); diff --git a/tests/Helpers.php b/tests/Helpers.php new file mode 100644 index 00000000..5d82fb3d --- /dev/null +++ b/tests/Helpers.php @@ -0,0 +1,8 @@ +