diff --git a/src/Controllers/CypressController.php b/src/Controllers/CypressController.php index 2b25bc8..52f206c 100644 --- a/src/Controllers/CypressController.php +++ b/src/Controllers/CypressController.php @@ -3,10 +3,10 @@ namespace Laracasts\Cypress\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; -use Illuminate\Support\Arr; class CypressController { @@ -40,7 +40,7 @@ public function login(Request $request) ->where($attributes) ->first(); - if (!$user) { + if (! $user) { $user = $this->factoryBuilder( $this->userClassName(), $request->input('state', []) @@ -75,7 +75,7 @@ public function factory(Request $request) ) ->count(intval($request->input('count', 1))) ->create($request->input('attributes')) - ->each(fn($model) => $model->setHidden([])->setVisible([])) + ->each(fn ($model) => $model->setHidden([])->setVisible([])) ->load($request->input('load', [])) ->pipe(function ($collection) { return $collection->count() > 1 @@ -105,8 +105,8 @@ public function runPhp(Request $request) $code .= ';'; } - if (!Str::contains($code, 'return')) { - $code = 'return ' . $code; + if (! Str::contains($code, 'return')) { + $code = 'return '.$code; } return response()->json([ diff --git a/src/CypressBoilerplateCommand.php b/src/CypressBoilerplateCommand.php index 98d7112..f93a985 100644 --- a/src/CypressBoilerplateCommand.php +++ b/src/CypressBoilerplateCommand.php @@ -36,7 +36,7 @@ public function __construct(protected Filesystem $files) */ public function handle() { - if (!$this->isCypressInstalled()) { + if (! $this->isCypressInstalled()) { $this->requireCypressInstall(); return; @@ -63,9 +63,9 @@ public function handle() */ protected function copyStubs(): void { - $this->files->copyDirectory(__DIR__ . '/stubs/support', $this->cypressPath('support')); - $this->files->copyDirectory(__DIR__ . '/stubs/plugins', $this->cypressPath('plugins')); - $this->files->copyDirectory(__DIR__ . '/stubs/integration', $this->cypressPath('integration')); + $this->files->copyDirectory(__DIR__.'/stubs/support', $this->cypressPath('support')); + $this->files->copyDirectory(__DIR__.'/stubs/plugins', $this->cypressPath('plugins')); + $this->files->copyDirectory(__DIR__.'/stubs/integration', $this->cypressPath('integration')); $this->lineBreak(); @@ -80,7 +80,7 @@ protected function copyStubs(): void $this->createCypressConfig(); - if (!$this->files->exists($path = base_path('.env.cypress'))) { + if (! $this->files->exists($path = base_path('.env.cypress'))) { $this->files->copy(base_path('.env'), $path); $this->status('Created', '.env.cypress'); @@ -116,9 +116,9 @@ protected function defaultCypressConfig(array $config = []): string ], [ config('app.url'), - $this->cypressPath('', false) + $this->cypressPath('', false), ], - $this->files->get(__DIR__ . '/stubs/cypress.config.js') + $this->files->get(__DIR__.'/stubs/cypress.config.js') ); } @@ -129,7 +129,7 @@ protected function cypressPath(string $path = '', bool $absolute = true): string { $cypressPath = $absolute ? base_path($this->cypressPath) : $this->cypressPath; - return $cypressPath . ($path ? DIRECTORY_SEPARATOR . $path : ''); + return $cypressPath.($path ? DIRECTORY_SEPARATOR.$path : ''); } /** diff --git a/tests/CypressControllerTest.php b/tests/CypressControllerTest.php index 731f96e..c45d73b 100644 --- a/tests/CypressControllerTest.php +++ b/tests/CypressControllerTest.php @@ -20,13 +20,13 @@ protected function setUp(): void { parent::setUp(); - $this->loadMigrationsFrom(__DIR__ . '/database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/database/migrations'); config(['auth.providers.users.model' => TestUser::class]); } /** @test */ - function it_fetches_a_collection_of_named_routes() + public function it_fetches_a_collection_of_named_routes() { Route::get('foo')->name('home'); @@ -79,7 +79,7 @@ public function it_logs_a_user_in() { $this->post(route('cypress.login'), [ 'attributes' => ['name' => 'Frank'], - 'state' => ['guest'] + 'state' => ['guest'], ]); $this->assertDatabaseHas('users', ['name' => 'Frank']); @@ -122,7 +122,7 @@ public function it_builds_a_model_factory() 'name' => 'John Doe', ], 'load' => ['profile'], - 'state' => ['guest'] + 'state' => ['guest'], ]); $this->assertDatabaseHas('users', ['name' => 'John Doe']); @@ -136,7 +136,7 @@ public function it_accepts_arguments_to_model_factory_states() { $response = $this->post(route('cypress.factory'), [ 'model' => TestUser::class, - 'state' => ['guest' => 'forum'] + 'state' => ['guest' => 'forum'], ]); $this->assertEquals('forum', $response->json()['plan']); @@ -144,7 +144,7 @@ public function it_accepts_arguments_to_model_factory_states() // When passing an array of arguments. $response = $this->post(route('cypress.factory'), [ 'model' => TestUser::class, - 'state' => ['guest' => ['forum']] + 'state' => ['guest' => ['forum']], ]); $this->assertEquals('forum', $response->json()['plan']); @@ -155,14 +155,14 @@ public function it_builds_a_collection_of_model_factories() { $response = $this->post(route('cypress.factory'), [ 'model' => TestUser::class, - 'count' => 2 + 'count' => 2, ]); $this->assertCount(2, $response->json()); } /** @test */ - function it_makes_model_attributes_visible() + public function it_makes_model_attributes_visible() { $response = $this->post(route('cypress.factory'), [ 'model' => TestUser::class, @@ -177,7 +177,7 @@ function it_makes_model_attributes_visible() } /** @test */ - function it_makes_collection_model_attributes_visible() + public function it_makes_collection_model_attributes_visible() { $response = $this->post(route('cypress.factory'), [ 'model' => TestUser::class, diff --git a/tests/CypressTest.php b/tests/CypressTest.php index 478800d..4b9d854 100644 --- a/tests/CypressTest.php +++ b/tests/CypressTest.php @@ -15,23 +15,25 @@ protected function getPackageProviders($app) /** * @test + * * @environment-setup setUpProductionEnvironment */ public function it_does_not_expose_cypress_routes_in_production() { $this->routeNames()->each( - fn($name) => $this->assertFalse(Route::has($name)) + fn ($name) => $this->assertFalse(Route::has($name)) ); } /** * @test + * * @environment-setup setUpAcceptanceEnvironment */ public function it_exposes_cypress_routes_if_not_in_production() { $this->routeNames()->each( - fn($name) => $this->assertTrue(Route::has($name)) + fn ($name) => $this->assertTrue(Route::has($name)) ); } @@ -45,17 +47,17 @@ protected function routeNames() 'cypress.run-php', 'cypress.csrf-token', 'cypress.routes', - 'cypress.current-user' + 'cypress.current-user', ]); } protected function setUpAcceptanceEnvironment() { - app()->detectEnvironment(fn() => 'acceptance'); + app()->detectEnvironment(fn () => 'acceptance'); } protected function setUpProductionEnvironment() { - app()->detectEnvironment(fn() => 'production'); + app()->detectEnvironment(fn () => 'production'); } } diff --git a/tests/database/factories/UserFactory.php b/tests/database/factories/UserFactory.php index 62adf9a..6543e31 100644 --- a/tests/database/factories/UserFactory.php +++ b/tests/database/factories/UserFactory.php @@ -42,6 +42,6 @@ public function definition() public function guest($plan = 'guest') { - return $this->state(fn() => ['plan' => $plan]); + return $this->state(fn () => ['plan' => $plan]); } } diff --git a/tests/support/TestUser.php b/tests/support/TestUser.php index 6d6f038..778e41c 100644 --- a/tests/support/TestUser.php +++ b/tests/support/TestUser.php @@ -11,6 +11,7 @@ class TestUser extends Authenticatable use HasFactory; protected $table = 'users'; + protected $hidden = ['plan']; protected static function booted()