Skip to content

Commit

Permalink
Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
choxx committed May 24, 2023
1 parent fb487c1 commit 7e9493d
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor/*
composer.lock
.idea/*
.phpunit.result.cache
storage/*
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"require-dev": {
"laravel/framework": "^5.0|^6.0|^7.0|^8.0|^9.0|^10.0",
"orchestra/testbench": "^8.5",
"phpunit/phpunit": "^10.1"
"phpunit/phpunit": "^10.1",
"ext-gd": "*",
"ext-sqlite3": "*"
},
"autoload": {
"psr-4": {
Expand Down
Binary file removed examples/.DS_Store
Binary file not shown.
9 changes: 4 additions & 5 deletions examples/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

require_once __DIR__.'/../Controllers/MinionController.php';
require_once __DIR__.'/../Repositories/MinionRepository.php';
require_once __DIR__.'/../Requests/MinionCreateRequest.php';

class TestCase extends \Orchestra\Testbench\TestCase
{
Expand All @@ -32,8 +31,8 @@ protected function getPackageProviders($app): array
public function defineEnvironment($app)
{
tap($app->make('config'), function (Repository $config) {
$config->set('database.default', 'testbench');
$config->set('database.connections.testbench', [
$config->set('database.default', 'test');
$config->set('database.connections.test', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
Expand All @@ -44,13 +43,13 @@ public function defineEnvironment($app)
protected function defineRoutes($router)
{
Route::resource('api/minions', MinionController::class, ['parameters' => ['minions' => 'id']]);
Route::post('api/files',FileController::class.'@store');
Route::post('api/files',[FileController::class, 'store']);
}

protected function defineDatabaseMigrations()
{
$this->loadMigrationsFrom(__DIR__ . '/../migrations');
$this->artisan('migrate', ['--database' => 'testbench'])->run();
$this->artisan('migrate', ['--database' => 'test'])->run();
}


Expand Down
15 changes: 7 additions & 8 deletions examples/tests/suite/DeleteAPISuccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Suite;

use Luezoid\Models\Minion;
use Tests\TestCase;
require_once __DIR__ . '/../TestCase.php';
require_once __DIR__ . '/../../Models/Minion.php';
Expand All @@ -22,8 +21,8 @@ public function test_delete_minion()
'hasHairs' => true,
];
// Create a minion.
$minion = $this->postJson('/api/minions', $payload);
$minion = Minion::where('id', 1)->first();
$this->postJson('/api/minions', $payload);

// Make the request.
$response = $this->deleteJson('/api/minions/1');
// Assert that the response is successful.
Expand All @@ -32,11 +31,11 @@ public function test_delete_minion()
$response->assertJson([
'message' =>"Resource deleted successfully",
'data' => [
'id' => $minion->id,
'name' => $minion->name,
'totalEyes' => $minion->total_eyes,
'favouriteSound' => $minion->favourite_sound,
'hasHairs' => $minion->has_hairs
'id' => 1,
'name' => 'Stuart',
'totalEyes' => 2,
'favouriteSound' => 'Grrrrrrrrrrr',
'hasHairs' => true
],
'type' => null,
]);
Expand Down
9 changes: 6 additions & 3 deletions examples/tests/suite/FileAPISuccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Luezoid\Laravelcore\Contracts\IFile;
use Luezoid\Laravelcore\Files\Services\LocalFileUploadService;
use Luezoid\Laravelcore\Files\Services\SaveFileToS3Service;
use Tests\TestCase;
require_once __DIR__.'/../TestCase.php';
require_once __DIR__.'/../../../src/Models/File.php';
Expand All @@ -23,11 +26,11 @@ public function testFileUpload()

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

$this->app->bind(\Luezoid\Laravelcore\Contracts\IFile::class, function ($app) {
$this->app->bind(IFile::class, function ($app) {
if (config('file.is_local')) {
return $app->make(\Luezoid\Laravelcore\Files\Services\LocalFileUploadService::class);
return $app->make(LocalFileUploadService::class);
}
return $app->make(\Luezoid\Laravelcore\Files\Services\SaveFileToS3Service::class);
return $app->make(SaveFileToS3Service::class);
});

$response = $this->post('/api/files', [
Expand Down
15 changes: 7 additions & 8 deletions examples/tests/suite/GetAPISuccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Suite;

use Luezoid\Models\Minion;
use Tests\TestCase;
require_once __DIR__ . '/../TestCase.php';
require_once __DIR__ . '/../../Models/Minion.php';
Expand All @@ -21,8 +20,8 @@ public function test_get_minion()
'hasHairs' => true,
];
// Create a minion.
$minion = $this->postJson('/api/minions', $payload);
$minion = Minion::where('id', 1)->first();
$this->postJson('/api/minions', $payload);

// Make the request.
$response = $this->getJson('/api/minions/1');

Expand All @@ -33,11 +32,11 @@ public function test_get_minion()
$response->assertJson([
'message' => null,
'data' => [
'id' => $minion->id,
'name' => $minion->name,
'totalEyes' => $minion->total_eyes,
'favouriteSound' => $minion->favourite_sound,
'hasHairs' => $minion->has_hairs
'id' => 1,
'name' => 'Stuart',
'totalEyes' => 2,
'favouriteSound' => 'Grrrrrrrrrrr',
'hasHairs' => true
],
'type' => null,
]);
Expand Down
14 changes: 6 additions & 8 deletions examples/tests/suite/IndexAPISuccessTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

namespace Tests\Suite;
use Luezoid\Models\Minion;
use Tests\TestCase;

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

// Make the request.
$response = $this->getJson('/api/minions');
Expand All @@ -35,11 +33,11 @@ public function test_index_minion(): void
'data' => [
'items' => [
[
'id' => $minion->id,
'name' => $minion->name,
'totalEyes' => $minion->total_eyes,
'favouriteSound' => $minion->favourite_sound,
'hasHairs' => $minion->has_hairs
'id' => 1,
'name' => 'Stuart',
'totalEyes' => 2,
'favouriteSound' => 'Grrrrrrrrrrr',
'hasHairs' => true
]
],
'page' => 1,
Expand Down
16 changes: 7 additions & 9 deletions examples/tests/suite/PutAPISuccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Suite;

use Luezoid\Models\Minion;
use Tests\TestCase;
require_once __DIR__ . '/../TestCase.php';
require_once __DIR__ . '/../../Models/Minion.php';
Expand All @@ -16,14 +15,13 @@ class PutAPISuccessTest extends TestCase
public function test_update_minion()
{
// Create a minion.
$minion = $this->postJson('/api/minions', [
$this->postJson('/api/minions', [
'name' => 'Stuart',
'totalEyes' => 2,
'favouriteSound' => 'Grrrrrrrrrrr',
'hasHairs' => true,
]);
// Get the minion.
$minion = Minion::where('id', 1)->first();

// Prepare the request payload.
$payload = [
'name' => 'Stuart',
Expand All @@ -42,11 +40,11 @@ public function test_update_minion()
$response->assertJson([
'message' => 'Resource Updated successfully',
'data' => [
'id' => $minion->id,
'name' => $payload['name'],
'totalEyes' => $payload['totalEyes'],
'favouriteSound' => $payload['favouriteSound'],
'hasHairs' => $payload['hasHairs'],
'id' => 1,
'name' => 'Stuart',
'totalEyes' => 2,
'favouriteSound' => 'Hrrrrrrrrrrr',
'hasHairs' => true
],
'type' => null,
]);
Expand Down
11 changes: 3 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./examples/tests/suite</directory>
<directory>./examples/tests/suite</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
<php>
<env name="APP_ENV" value="testbench"/>
<env name="APP_ENV" value="test"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="testbench"/>
<env name="DB_CONNECTION" value="test"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
Expand Down
Binary file not shown.

0 comments on commit 7e9493d

Please sign in to comment.