Skip to content

Commit 0ea2509

Browse files
committed
♻️ reworked quick start tests
1 parent 0d2acf0 commit 0ea2509

File tree

3 files changed

+3
-58
lines changed

3 files changed

+3
-58
lines changed

phpunit.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
<env name="QUEUE_CONNECTION" value="sync"/>
1919
<env name="SESSION_DRIVER" value="array"/>
2020
<env name="TELESCOPE_ENABLED" value="false"/>
21-
<env name="APP_ENV" value="testing"/>
22-
<env name="DB_CONNECTION" value="testing"/>
2321
</php>
2422
<source>
2523
<include>

tests/Feature/Commands/QuickStartCommandTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class QuickStartCommandTest extends TestCase
1010
protected function setUp(): void
1111
{
1212
parent::setUp();
13-
$this->cleanUp();
13+
1414
// Ensure api.php exists for tests
1515
if (! File::exists(base_path('routes/api.php'))) {
1616
File::put(base_path('routes/api.php'), '<?php');
@@ -27,9 +27,7 @@ protected function cleanUp(): void
2727
{
2828
File::deleteDirectory(app_path('Rest'));
2929
File::deleteDirectory(app_path('Models'));
30-
if (File::exists(base_path('routes/api.php'))) {
31-
File::put(base_path('routes/api.php'), '<?php');
32-
}
30+
File::delete(base_path('routes/api.php'));
3331
}
3432

3533
public function test_quick_start_command_creates_necessary_files()
@@ -53,7 +51,6 @@ public function test_quick_start_command_updates_api_routes()
5351

5452
public function test_quick_start_command_does_not_duplicate_routes()
5553
{
56-
// Run the command twice
5754
$this->artisan('rest:quick-start')->assertExitCode(0);
5855
$this->artisan('rest:quick-start')->assertExitCode(0);
5956

@@ -68,24 +65,18 @@ public function test_quick_start_command_updates_user_model_namespace()
6865
File::makeDirectory(app_path('Models'), 0755, true);
6966
File::put(app_path('Models/User.php'), '<?php namespace App\Models; class User {}');
7067

71-
// Run the command
7268
$this->artisan('rest:quick-start')->assertExitCode(0);
7369

74-
// Check if the files were created
7570
$this->assertFileExists(app_path('Rest/Resources/UserResource.php'));
7671
$this->assertFileExists(app_path('Rest/Controllers/UsersController.php'));
7772

7873
$resourceContent = File::get(app_path('Rest/Resources/UserResource.php'));
7974
$controllerContent = File::get(app_path('Rest/Controllers/UsersController.php'));
8075

81-
// Check for the updated namespace in UserResource.php
8276
$this->assertStringContainsString('\App\Models\User::class', $resourceContent);
8377

84-
// Check for the updated namespace in UsersController.php
85-
// TODO: We are putting this control in the comment line for now, because UsersController may not have this change made.
86-
// $this->assertStringContainsString('\App\Models\User::class', $controllerContent);
78+
$this->assertStringContainsString('\App\Rest\Resources\UserResource::class', $controllerContent);
8779

88-
// Additional check Let's check that the User model is used correctly in UserResource
8980
$this->assertStringContainsString('public static $model = \App\Models\User::class;', $resourceContent);
9081
}
9182
}

tests/Feature/TestCase.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,11 @@ protected function setUp(): void
1616
{
1717
parent::setUp();
1818

19-
$this->loadMigrationsFrom(__DIR__.'/Support/Database/migrations');
20-
$this->artisan('migrate', ['--database' => 'testing'])->run();
2119
$this->withAuthenticatedUser();
2220
}
2321

2422
protected function resolveAuthFactoryClass()
2523
{
2624
return UserFactory::class;
2725
}
28-
29-
protected function getPackageProviders($app)
30-
{
31-
return [
32-
\Lomkit\Rest\RestServiceProvider::class,
33-
];
34-
}
35-
36-
protected function getEnvironmentSetUp($app)
37-
{
38-
$app['config']->set('database.default', 'testing');
39-
40-
$connection = env('DB_CONNECTION', 'sqlite');
41-
42-
switch ($connection) {
43-
case 'mysql':
44-
$app['config']->set('database.connections.testing', [
45-
'driver' => 'mysql',
46-
'host' => env('DB_HOST', '127.0.0.1'),
47-
'port' => env('DB_PORT', '3306'),
48-
'database' => 'rest',
49-
'username' => env('DB_USERNAME', 'root'),
50-
'password' => env('DB_PASSWORD', ''),
51-
]);
52-
break;
53-
case 'pgsql':
54-
$app['config']->set('database.connections.testing', [
55-
'driver' => 'pgsql',
56-
'host' => env('DB_HOST', '127.0.0.1'),
57-
'port' => env('DB_PORT', '5432'),
58-
'database' => 'rest',
59-
'username' => env('DB_USERNAME', 'postgres'),
60-
'password' => env('DB_PASSWORD', 'postgres'),
61-
]);
62-
break;
63-
default:
64-
$app['config']->set('database.connections.testing', [
65-
'driver' => 'sqlite',
66-
'database' => ':memory:',
67-
]);
68-
}
69-
}
7026
}

0 commit comments

Comments
 (0)