Skip to content

Commit 7e9493d

Browse files
committed
Code clean up
1 parent fb487c1 commit 7e9493d

File tree

11 files changed

+44
-50
lines changed

11 files changed

+44
-50
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor/*
22
composer.lock
33
.idea/*
44
.phpunit.result.cache
5+
storage/*

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
"require-dev": {
3737
"laravel/framework": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0",
3838
"orchestra/testbench": "^8.5",
39-
"phpunit/phpunit": "^10.1"
39+
"phpunit/phpunit": "^10.1",
40+
"ext-gd": "*",
41+
"ext-sqlite3": "*"
4042
},
4143
"autoload": {
4244
"psr-4": {

examples/.DS_Store

-8 KB
Binary file not shown.

examples/tests/TestCase.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
require_once __DIR__.'/../Controllers/MinionController.php';
1313
require_once __DIR__.'/../Repositories/MinionRepository.php';
14-
require_once __DIR__.'/../Requests/MinionCreateRequest.php';
1514

1615
class TestCase extends \Orchestra\Testbench\TestCase
1716
{
@@ -32,8 +31,8 @@ protected function getPackageProviders($app): array
3231
public function defineEnvironment($app)
3332
{
3433
tap($app->make('config'), function (Repository $config) {
35-
$config->set('database.default', 'testbench');
36-
$config->set('database.connections.testbench', [
34+
$config->set('database.default', 'test');
35+
$config->set('database.connections.test', [
3736
'driver' => 'sqlite',
3837
'database' => ':memory:',
3938
'prefix' => '',
@@ -44,13 +43,13 @@ public function defineEnvironment($app)
4443
protected function defineRoutes($router)
4544
{
4645
Route::resource('api/minions', MinionController::class, ['parameters' => ['minions' => 'id']]);
47-
Route::post('api/files',FileController::class.'@store');
46+
Route::post('api/files',[FileController::class, 'store']);
4847
}
4948

5049
protected function defineDatabaseMigrations()
5150
{
5251
$this->loadMigrationsFrom(__DIR__ . '/../migrations');
53-
$this->artisan('migrate', ['--database' => 'testbench'])->run();
52+
$this->artisan('migrate', ['--database' => 'test'])->run();
5453
}
5554

5655

examples/tests/suite/DeleteAPISuccessTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tests\Suite;
44

5-
use Luezoid\Models\Minion;
65
use Tests\TestCase;
76
require_once __DIR__ . '/../TestCase.php';
87
require_once __DIR__ . '/../../Models/Minion.php';
@@ -22,8 +21,8 @@ public function test_delete_minion()
2221
'hasHairs' => true,
2322
];
2423
// Create a minion.
25-
$minion = $this->postJson('/api/minions', $payload);
26-
$minion = Minion::where('id', 1)->first();
24+
$this->postJson('/api/minions', $payload);
25+
2726
// Make the request.
2827
$response = $this->deleteJson('/api/minions/1');
2928
// Assert that the response is successful.
@@ -32,11 +31,11 @@ public function test_delete_minion()
3231
$response->assertJson([
3332
'message' =>"Resource deleted successfully",
3433
'data' => [
35-
'id' => $minion->id,
36-
'name' => $minion->name,
37-
'totalEyes' => $minion->total_eyes,
38-
'favouriteSound' => $minion->favourite_sound,
39-
'hasHairs' => $minion->has_hairs
34+
'id' => 1,
35+
'name' => 'Stuart',
36+
'totalEyes' => 2,
37+
'favouriteSound' => 'Grrrrrrrrrrr',
38+
'hasHairs' => true
4039
],
4140
'type' => null,
4241
]);

examples/tests/suite/FileAPISuccessTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Http\UploadedFile;
66
use Illuminate\Support\Facades\Storage;
7+
use Luezoid\Laravelcore\Contracts\IFile;
8+
use Luezoid\Laravelcore\Files\Services\LocalFileUploadService;
9+
use Luezoid\Laravelcore\Files\Services\SaveFileToS3Service;
710
use Tests\TestCase;
811
require_once __DIR__.'/../TestCase.php';
912
require_once __DIR__.'/../../../src/Models/File.php';
@@ -23,11 +26,11 @@ public function testFileUpload()
2326

2427
$file = UploadedFile::fake()->image('test-image.jpg'); // Create a fake test file
2528

26-
$this->app->bind(\Luezoid\Laravelcore\Contracts\IFile::class, function ($app) {
29+
$this->app->bind(IFile::class, function ($app) {
2730
if (config('file.is_local')) {
28-
return $app->make(\Luezoid\Laravelcore\Files\Services\LocalFileUploadService::class);
31+
return $app->make(LocalFileUploadService::class);
2932
}
30-
return $app->make(\Luezoid\Laravelcore\Files\Services\SaveFileToS3Service::class);
33+
return $app->make(SaveFileToS3Service::class);
3134
});
3235

3336
$response = $this->post('/api/files', [

examples/tests/suite/GetAPISuccessTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tests\Suite;
44

5-
use Luezoid\Models\Minion;
65
use Tests\TestCase;
76
require_once __DIR__ . '/../TestCase.php';
87
require_once __DIR__ . '/../../Models/Minion.php';
@@ -21,8 +20,8 @@ public function test_get_minion()
2120
'hasHairs' => true,
2221
];
2322
// Create a minion.
24-
$minion = $this->postJson('/api/minions', $payload);
25-
$minion = Minion::where('id', 1)->first();
23+
$this->postJson('/api/minions', $payload);
24+
2625
// Make the request.
2726
$response = $this->getJson('/api/minions/1');
2827

@@ -33,11 +32,11 @@ public function test_get_minion()
3332
$response->assertJson([
3433
'message' => null,
3534
'data' => [
36-
'id' => $minion->id,
37-
'name' => $minion->name,
38-
'totalEyes' => $minion->total_eyes,
39-
'favouriteSound' => $minion->favourite_sound,
40-
'hasHairs' => $minion->has_hairs
35+
'id' => 1,
36+
'name' => 'Stuart',
37+
'totalEyes' => 2,
38+
'favouriteSound' => 'Grrrrrrrrrrr',
39+
'hasHairs' => true
4140
],
4241
'type' => null,
4342
]);

examples/tests/suite/IndexAPISuccessTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
namespace Tests\Suite;
4-
use Luezoid\Models\Minion;
54
use Tests\TestCase;
65

76
require_once __DIR__ . '/../TestCase.php';
@@ -21,8 +20,7 @@ public function test_index_minion(): void
2120
'hasHairs' => true,
2221
];
2322
// Create a minion.
24-
$minion = $this->postJson('/api/minions', $payload);
25-
$minion = Minion::where('id', 1)->first();
23+
$this->postJson('/api/minions', $payload);
2624

2725
// Make the request.
2826
$response = $this->getJson('/api/minions');
@@ -35,11 +33,11 @@ public function test_index_minion(): void
3533
'data' => [
3634
'items' => [
3735
[
38-
'id' => $minion->id,
39-
'name' => $minion->name,
40-
'totalEyes' => $minion->total_eyes,
41-
'favouriteSound' => $minion->favourite_sound,
42-
'hasHairs' => $minion->has_hairs
36+
'id' => 1,
37+
'name' => 'Stuart',
38+
'totalEyes' => 2,
39+
'favouriteSound' => 'Grrrrrrrrrrr',
40+
'hasHairs' => true
4341
]
4442
],
4543
'page' => 1,

examples/tests/suite/PutAPISuccessTest.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tests\Suite;
44

5-
use Luezoid\Models\Minion;
65
use Tests\TestCase;
76
require_once __DIR__ . '/../TestCase.php';
87
require_once __DIR__ . '/../../Models/Minion.php';
@@ -16,14 +15,13 @@ class PutAPISuccessTest extends TestCase
1615
public function test_update_minion()
1716
{
1817
// Create a minion.
19-
$minion = $this->postJson('/api/minions', [
18+
$this->postJson('/api/minions', [
2019
'name' => 'Stuart',
2120
'totalEyes' => 2,
2221
'favouriteSound' => 'Grrrrrrrrrrr',
2322
'hasHairs' => true,
2423
]);
25-
// Get the minion.
26-
$minion = Minion::where('id', 1)->first();
24+
2725
// Prepare the request payload.
2826
$payload = [
2927
'name' => 'Stuart',
@@ -42,11 +40,11 @@ public function test_update_minion()
4240
$response->assertJson([
4341
'message' => 'Resource Updated successfully',
4442
'data' => [
45-
'id' => $minion->id,
46-
'name' => $payload['name'],
47-
'totalEyes' => $payload['totalEyes'],
48-
'favouriteSound' => $payload['favouriteSound'],
49-
'hasHairs' => $payload['hasHairs'],
43+
'id' => 1,
44+
'name' => 'Stuart',
45+
'totalEyes' => 2,
46+
'favouriteSound' => 'Hrrrrrrrrrrr',
47+
'hasHairs' => true
5048
],
5149
'type' => null,
5250
]);

phpunit.xml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@
66
>
77
<testsuites>
88
<testsuite name="Unit">
9-
<directory suffix="Test.php">./examples/tests/suite</directory>
9+
<directory>./examples/tests/suite</directory>
1010
</testsuite>
1111
</testsuites>
12-
<source>
13-
<include>
14-
<directory suffix=".php">./app</directory>
15-
</include>
16-
</source>
1712
<php>
18-
<env name="APP_ENV" value="testbench"/>
13+
<env name="APP_ENV" value="test"/>
1914
<env name="BCRYPT_ROUNDS" value="4"/>
2015
<env name="CACHE_DRIVER" value="array"/>
21-
<env name="DB_CONNECTION" value="testbench"/>
16+
<env name="DB_CONNECTION" value="test"/>
2217
<env name="DB_DATABASE" value=":memory:"/>
2318
<env name="MAIL_MAILER" value="array"/>
2419
<env name="QUEUE_CONNECTION" value="sync"/>

0 commit comments

Comments
 (0)