-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added package Test Cases using sqlite DB connection
Added package Test Cases using sqlite DB connection
- Loading branch information
Showing
11 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
vendor/* | ||
composer.lock | ||
.idea/* | ||
.idea/* | ||
.phpunit.result.cache | ||
storage/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Tests; | ||
|
||
use Illuminate\Contracts\Config\Repository; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Support\ServiceProvider; | ||
use Luezoid\Http\Controllers\MinionController; | ||
use Luezoid\Laravelcore\Http\Controllers\FileController; | ||
|
||
require_once __DIR__.'/../Controllers/MinionController.php'; | ||
require_once __DIR__.'/../Repositories/MinionRepository.php'; | ||
|
||
class TestCase extends \Orchestra\Testbench\TestCase | ||
{ | ||
/** | ||
* Get package providers. | ||
* | ||
* @param Application $app | ||
* | ||
* @return array<int, class-string<ServiceProvider>> | ||
*/ | ||
protected function getPackageProviders($app): array | ||
{ | ||
return [ | ||
'Luezoid\Laravelcore\CoreServiceProvider', | ||
]; | ||
} | ||
|
||
public function defineEnvironment($app) | ||
{ | ||
tap($app->make('config'), function (Repository $config) { | ||
$config->set('database.default', 'test'); | ||
$config->set('database.connections.test', [ | ||
'driver' => 'sqlite', | ||
'database' => ':memory:', | ||
'prefix' => '', | ||
]); | ||
}); | ||
} | ||
|
||
protected function defineRoutes($router) | ||
{ | ||
Route::resource('api/minions', MinionController::class, ['parameters' => ['minions' => 'id']]); | ||
Route::post('api/files',[FileController::class, 'store']); | ||
} | ||
|
||
protected function defineDatabaseMigrations() | ||
{ | ||
$this->loadMigrationsFrom(__DIR__ . '/../migrations'); | ||
$this->artisan('migrate', ['--database' => 'test'])->run(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Tests\Suite; | ||
|
||
use Tests\TestCase; | ||
require_once __DIR__ . '/../TestCase.php'; | ||
require_once __DIR__ . '/../../Models/Minion.php'; | ||
require_once __DIR__ . '/../../Requests/MinionDeleteRequest.php'; | ||
|
||
class DeleteAPISuccessTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function test_delete_minion() | ||
{ | ||
$payload = [ | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true, | ||
]; | ||
// Create a minion. | ||
$this->postJson('/api/minions', $payload); | ||
|
||
// Make the request. | ||
$response = $this->deleteJson('/api/minions/1'); | ||
// Assert that the response is successful. | ||
$response->assertOk(); | ||
// Assert that the minion is deleted. | ||
$response->assertJson([ | ||
'message' =>"Resource deleted successfully", | ||
'data' => [ | ||
'id' => 1, | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true | ||
], | ||
'type' => null, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Tests\Suite; | ||
|
||
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'; | ||
require_once __DIR__.'/../../../src/config/file.php'; | ||
require_once __DIR__.'/../../../src/Contracts/IFile.php'; | ||
require_once __DIR__.'/../../../src/Files/Services/LocalFileUploadService.php'; | ||
require_once __DIR__.'/../../../src/Files/Services/SaveFileToS3Service.php'; | ||
|
||
class FileAPISuccessTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function testFileUpload() | ||
{ | ||
Storage::fake('local'); // Use a fake disk for testing file uploads | ||
|
||
$file = UploadedFile::fake()->image('test-image.jpg'); // Create a fake test file | ||
|
||
$this->app->bind(IFile::class, function ($app) { | ||
if (config('file.is_local')) { | ||
return $app->make(LocalFileUploadService::class); | ||
} | ||
return $app->make(SaveFileToS3Service::class); | ||
}); | ||
|
||
$response = $this->post('/api/files', [ | ||
'file' => $file, | ||
'type' => 'EXAMPLE', | ||
]); | ||
|
||
$response->assertStatus(200); // Assert that the response has a status code of 200 | ||
// Assert the JSON structure of the response | ||
$response->assertJsonStructure([ | ||
'message', | ||
'data' => [ | ||
'type', | ||
'name', | ||
'localPath', | ||
's3Key', | ||
'updatedAt', | ||
'createdAt', | ||
'id', | ||
'url', | ||
], | ||
'type', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Tests\Suite; | ||
|
||
use Tests\TestCase; | ||
require_once __DIR__ . '/../TestCase.php'; | ||
require_once __DIR__ . '/../../Models/Minion.php'; | ||
|
||
class GetAPISuccessTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function test_get_minion() | ||
{ | ||
$payload = [ | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true, | ||
]; | ||
// Create a minion. | ||
$this->postJson('/api/minions', $payload); | ||
|
||
// Make the request. | ||
$response = $this->getJson('/api/minions/1'); | ||
|
||
// Assert that the response is successful. | ||
$response->assertOk(); | ||
|
||
// Assert that the response data is correct. | ||
$response->assertJson([ | ||
'message' => null, | ||
'data' => [ | ||
'id' => 1, | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true | ||
], | ||
'type' => null, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Tests\Suite; | ||
use Tests\TestCase; | ||
|
||
require_once __DIR__ . '/../TestCase.php'; | ||
require_once __DIR__ . '/../../Models/Minion.php'; | ||
|
||
class IndexAPISuccessTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function test_index_minion(): void | ||
{ | ||
$payload = [ | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true, | ||
]; | ||
// Create a minion. | ||
$this->postJson('/api/minions', $payload); | ||
|
||
// Make the request. | ||
$response = $this->getJson('/api/minions'); | ||
|
||
$response->assertOk(); | ||
|
||
// Assert that the response data is correct. | ||
$response->assertJson([ | ||
'message' => null, | ||
'data' => [ | ||
'items' => [ | ||
[ | ||
'id' => 1, | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true | ||
] | ||
], | ||
'page' => 1, | ||
'total' => 1, | ||
'pages' => 1, | ||
'perpage' => 15, | ||
], | ||
'type' => null, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Tests\Suite; | ||
|
||
use Tests\TestCase; | ||
|
||
require_once __DIR__ . '/../TestCase.php'; | ||
require_once __DIR__ . '/../../Models/Minion.php'; | ||
require_once __DIR__ . '/../../Requests/MinionCreateRequest.php'; | ||
|
||
class PostAPISuccessTest extends TestCase | ||
{ | ||
public function test_post_api() | ||
{ | ||
$payload = [ | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true, | ||
]; | ||
|
||
$response = $this->postJson('/api/minions', $payload); | ||
$response->assertStatus(200); | ||
$response->assertJson([ | ||
'message' => 'Resource Created successfully', | ||
'data' => [ | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true, | ||
'id' => 1, | ||
], | ||
'type' => null, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Tests\Suite; | ||
|
||
use Tests\TestCase; | ||
require_once __DIR__ . '/../TestCase.php'; | ||
require_once __DIR__ . '/../../Models/Minion.php'; | ||
require_once __DIR__ . '/../../Requests/MinionUpdateRequest.php'; | ||
|
||
class PutAPISuccessTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function test_update_minion() | ||
{ | ||
// Create a minion. | ||
$this->postJson('/api/minions', [ | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Grrrrrrrrrrr', | ||
'hasHairs' => true, | ||
]); | ||
|
||
// Prepare the request payload. | ||
$payload = [ | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Hrrrrrrrrrrr', | ||
'hasHairs' => true, | ||
]; | ||
|
||
// Make the request. | ||
$response = $this->putJson('/api/minions/1', $payload); | ||
|
||
// Assert that the response is successful. | ||
$response->assertOk(); | ||
|
||
// Assert that the response data is correct. | ||
$response->assertJson([ | ||
'message' => 'Resource Updated successfully', | ||
'data' => [ | ||
'id' => 1, | ||
'name' => 'Stuart', | ||
'totalEyes' => 2, | ||
'favouriteSound' => 'Hrrrrrrrrrrr', | ||
'hasHairs' => true | ||
], | ||
'type' => null, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory>./examples/tests/suite</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="test"/> | ||
<env name="BCRYPT_ROUNDS" value="4"/> | ||
<env name="CACHE_DRIVER" value="array"/> | ||
<env name="DB_CONNECTION" value="test"/> | ||
<env name="DB_DATABASE" value=":memory:"/> | ||
<env name="MAIL_MAILER" value="array"/> | ||
<env name="QUEUE_CONNECTION" value="sync"/> | ||
<env name="SESSION_DRIVER" value="array"/> | ||
<env name="TELESCOPE_ENABLED" value="false"/> | ||
</php> | ||
</phpunit> |