Simplify test by mocking filesystem always (#1019)

This commit is contained in:
Barry vd. Heuvel
2020-08-25 17:43:39 +02:00
committed by GitHub
parent c852650d7e
commit 9599cfbbc9
21 changed files with 100 additions and 593 deletions
@@ -22,38 +22,8 @@ class Test extends AbstractModelsCommand
}
}
protected function getEnvironmentSetUp($app)
public function test(): void
{
parent::getEnvironmentSetUp($app);
$app['config']->set('ide-helper', [
'model_locations' => [
// This is calculated from the base_path() which points to
// vendor/orchestra/testbench-core/laravel
'/../../../../tests/Console/ModelsCommand/LaravelCustomCasts/Models',
],
]);
}
public function test_it_parses_casted_properties_correctly(): void
{
$actualContent = null;
$mockFilesystem = Mockery::mock(Filesystem::class);
$mockFilesystem
->shouldReceive('get')
->andReturn(file_get_contents(__DIR__ . '/Models/CustomCast.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, [
@@ -62,6 +32,6 @@ class Test extends AbstractModelsCommand
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesPhpSnapshot($actualContent);
$this->assertMatchesMockedSnapshot();
}
}