Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Controllers/CypressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -40,7 +40,7 @@ public function login(Request $request)
->where($attributes)
->first();

if (!$user) {
if (! $user) {
$user = $this->factoryBuilder(
$this->userClassName(),
$request->input('state', [])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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([
Expand Down
16 changes: 8 additions & 8 deletions src/CypressBoilerplateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(protected Filesystem $files)
*/
public function handle()
{
if (!$this->isCypressInstalled()) {
if (! $this->isCypressInstalled()) {
$this->requireCypressInstall();

return;
Expand All @@ -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();

Expand All @@ -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');
Expand Down Expand Up @@ -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')
);
}

Expand All @@ -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 : '');
}

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/CypressControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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']);
Expand Down Expand Up @@ -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']);
Expand All @@ -136,15 +136,15 @@ 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']);

// 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']);
Expand All @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 7 additions & 5 deletions tests/CypressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}

Expand All @@ -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');
}
}
2 changes: 1 addition & 1 deletion tests/database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function definition()

public function guest($plan = 'guest')
{
return $this->state(fn() => ['plan' => $plan]);
return $this->state(fn () => ['plan' => $plan]);
}
}
1 change: 1 addition & 0 deletions tests/support/TestUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TestUser extends Authenticatable
use HasFactory;

protected $table = 'users';

protected $hidden = ['plan'];

protected static function booted()
Expand Down