|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Unit; |
| 4 | + |
| 5 | +use Tests\TestCase; |
| 6 | +use FamilyTree365\LaravelGedcom\Facades\GedcomParserFacade; |
| 7 | +use FamilyTree365\LaravelGedcom\Jobs\GedcomImportJob; |
| 8 | +use Illuminate\Support\Facades\Queue; |
| 9 | + |
| 10 | +class GedcomImportJobTest extends TestCase |
| 11 | +{ |
| 12 | + protected function getPackageProviders($app): array |
| 13 | + { |
| 14 | + return ['FamilyTree365\LaravelGedcom\ServiceProvider']; |
| 15 | + } |
| 16 | + |
| 17 | + public function testJobIsDispatchedByGedcomImporter(): void |
| 18 | + { |
| 19 | + Queue::fake(); |
| 20 | + |
| 21 | + \FamilyTree365\LaravelGedcom\Utils\GedcomImporter::importData('family'); |
| 22 | + |
| 23 | + Queue::assertPushed(GedcomImportJob::class, function ($job) { |
| 24 | + return $job->conn === 'mysql' |
| 25 | + && $job->filename === 'family.ged' |
| 26 | + && $job->slug === 'family'; |
| 27 | + }); |
| 28 | + } |
| 29 | + |
| 30 | + public function testGedcomImporterDispatchesWithLowercaseGedExtension(): void |
| 31 | + { |
| 32 | + Queue::fake(); |
| 33 | + |
| 34 | + \FamilyTree365\LaravelGedcom\Utils\GedcomImporter::importData('family'); |
| 35 | + |
| 36 | + Queue::assertPushed(GedcomImportJob::class, function ($job) { |
| 37 | + return str_ends_with($job->filename, '.ged') |
| 38 | + && !str_ends_with($job->filename, '.GED'); |
| 39 | + }); |
| 40 | + } |
| 41 | + |
| 42 | + public function testJobHandleCallsParser(): void |
| 43 | + { |
| 44 | + GedcomParserFacade::shouldReceive('parse') |
| 45 | + ->once() |
| 46 | + ->with('mysql', 'family.ged', 'family', true) |
| 47 | + ->andReturn(null); |
| 48 | + |
| 49 | + $job = new GedcomImportJob('mysql', 'family.ged', 'family'); |
| 50 | + $job->handle(); |
| 51 | + } |
| 52 | + |
| 53 | + public function testJobImplementsShouldQueue(): void |
| 54 | + { |
| 55 | + $job = new GedcomImportJob('mysql', 'test.ged', 'test'); |
| 56 | + $this->assertInstanceOf(\Illuminate\Contracts\Queue\ShouldQueue::class, $job); |
| 57 | + } |
| 58 | +} |
0 commit comments