Init
This commit is contained in:
21
tests/CreatesApplication.php
Normal file
21
tests/CreatesApplication.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
trait CreatesApplication
|
||||
{
|
||||
/**
|
||||
* Creates the application.
|
||||
*/
|
||||
public function createApplication(): Application
|
||||
{
|
||||
$app = require __DIR__.'/../bootstrap/app.php';
|
||||
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
|
||||
return $app;
|
||||
}
|
||||
}
|
62
tests/Feature/GalleryServiceTest.php
Normal file
62
tests/Feature/GalleryServiceTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
use App\Services\GalleryService;
|
||||
use App\Models\Hentai;
|
||||
use App\Models\Episode;
|
||||
use App\Models\Gallery;
|
||||
use App\Models\Studios;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
class GalleryServiceTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected $galleryService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->galleryService = new GalleryService();
|
||||
}
|
||||
|
||||
public function test_create_or_update_gallery()
|
||||
{
|
||||
// Fake the storage disk
|
||||
Storage::fake('public');
|
||||
|
||||
// Create a Hentai and Episode instance
|
||||
$hentai = Hentai::factory()->create();
|
||||
$studio = Studios::factory()->create();
|
||||
$episode = Episode::factory()->create(['hentai_id' => $hentai->id, 'studios_id' => $studio->id]);
|
||||
|
||||
// Create a fake image file
|
||||
$file = UploadedFile::fake()->image('test_image.jpg');
|
||||
|
||||
// Create a request with the fake file
|
||||
$request = new \Illuminate\Http\Request();
|
||||
$request->files->add(['episodegallery1' => [$file]]);
|
||||
|
||||
// Call the method to test
|
||||
$this->galleryService->createOrUpdateGallery($request, $hentai, $episode, $episode->episode, true);
|
||||
|
||||
$imageURL = "/images/hentai/{$hentai->slug}/gallery-ep-{$episode->episode}-0.webp";
|
||||
$thumbnailURL = "/images/hentai/{$hentai->slug}/gallery-ep-{$episode->episode}-0-thumbnail.webp";
|
||||
|
||||
// Assert that the gallery was created
|
||||
$this->assertDatabaseHas('gallery', [
|
||||
'hentai_id' => $hentai->id,
|
||||
'episode_id' => $episode->id,
|
||||
'image_url' => $imageURL,
|
||||
'thumbnail_url' => $thumbnailURL,
|
||||
]);
|
||||
|
||||
// Assert that the image and thumbnail were saved
|
||||
$this->assertTrue(Storage::disk('public')->exists($imageURL));
|
||||
$this->assertTrue(Storage::disk('public')->exists($thumbnailURL));
|
||||
}
|
||||
}
|
10
tests/TestCase.php
Normal file
10
tests/TestCase.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
}
|
16
tests/Unit/ExampleTest.php
Normal file
16
tests/Unit/ExampleTest.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ExampleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* A basic test example.
|
||||
*/
|
||||
public function test_that_true_is_true(): void
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user