From cf1fe247df3d4a50773554e99692b4c889c47eb3 Mon Sep 17 00:00:00 2001 From: pataar Date: Tue, 10 Mar 2020 11:09:24 +0100 Subject: [PATCH] Add tests --- .../ModelsCommand/Ignored/Models/Ignored.php | 10 +++ .../Ignored/Models/Unignored.php | 9 +++ tests/Console/ModelsCommand/Ignored/Test.php | 80 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 tests/Console/ModelsCommand/Ignored/Models/Ignored.php create mode 100644 tests/Console/ModelsCommand/Ignored/Models/Unignored.php create mode 100644 tests/Console/ModelsCommand/Ignored/Test.php diff --git a/tests/Console/ModelsCommand/Ignored/Models/Ignored.php b/tests/Console/ModelsCommand/Ignored/Models/Ignored.php new file mode 100644 index 0000000..df4c7d2 --- /dev/null +++ b/tests/Console/ModelsCommand/Ignored/Models/Ignored.php @@ -0,0 +1,10 @@ +set('ide-helper', [ + 'model_locations' => [ + // This is calculated from the base_path() which points to + // vendor/orchestra/testbench-core/laravel + '/../../../../tests/Console/ModelsCommand/Ignored/Models', + ], + 'ignored_models' => [ + Ignored::class + ] + ]); + } + + public function test(): void + { + $actualContent = null; + $mockFilesystem = Mockery::mock(Filesystem::class); + $mockFilesystem + ->shouldReceive('get') + ->andReturn(file_get_contents(__DIR__ . '/Models/Unignored.php')) + ->once(); + $mockFilesystem + ->shouldReceive('put') + ->with( + Mockery::any(), + Mockery::capture($actualContent) + ) + ->andReturn(1) // Simulate we wrote _something_ to the file + ->once(); + + $this->instance(Filesystem::class, $mockFilesystem); + + $command = $this->app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertEmpty($tester->getDisplay()); + + $expectedContent = <<<'PHP' +assertSame($expectedContent, $actualContent); + } +}