Skip to content

Commit

Permalink
Merge pull request #20 from liberu-genealogy/sweep/add-missing-unit-t…
Browse files Browse the repository at this point in the history
…ests

Add Missing Unit Tests for DispatchMatchkitsJob and DnaServiceProvider
  • Loading branch information
curtisdelicata authored Mar 13, 2024
2 parents 8c9a124 + 7776534 commit 1e1717c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
36 changes: 36 additions & 0 deletions tests/Unit/DispatchMatchkitsJobConstructorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Tests\Unit;

use Mockery;
use Tests\TestCase;
use Src\Jobs\DispatchMatchkitsJob;
use LiburuGenealogy\PhpDna\Matchkits;

class DispatchMatchkitsJobConstructorTest extends TestCase
{
public function testConstructorAssignsMatchkitsCorrectly()
{
$mockMatchkits = Mockery::mock(Matchkits::class);
$job = new DispatchMatchkitsJob($mockMatchkits);

$this->assertAttributeEquals($mockMatchkits, 'matchkits', $job);
}

public function testHandleCallsProcessOnMatchkits()
{
$mockMatchkits = Mockery::mock(Matchkits::class);
$mockMatchkits->shouldReceive('process')->once();

$job = new DispatchMatchkitsJob($mockMatchkits);
$job->handle();

Mockery::close();
}

protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}
}
19 changes: 15 additions & 4 deletions tests/Unit/DispatchMatchkitsJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ public function testProcessIsCalledSuccessfully()

Queue::assertNothingPushed();

DispatchMatchkitsJob::dispatch();
DispatchMatchkitsJob::dispatch($mock);

Queue::assertPushed(DispatchMatchkitsJob::class);
Queue::assertPushed(DispatchMatchkitsJob::class, function ($job) use ($mock) {
return $job->matchkits === $mock;
});

Queue::assertPushedOn('default', DispatchMatchkitsJob::class);
Queue::after(function () use ($mock) {
$mock->shouldHaveReceived('process')->once();
});
}
}
/**
Expand All @@ -43,12 +50,16 @@ public function testProcessIsCalledSuccessfully()
public function testProcessMatchkitsHandlesExceptionsProperly()
{
Queue::fake();
Log::shouldReceive('error')->once();
Log::shouldReceive('error')->once()->withArgs(function($message) {
return str_contains($message, 'Failed to process matchkits');
});

$mock = Mockery::mock(Matchkits::class);
$mock->shouldReceive('process')->once()->andThrow(\Exception::class);
$this->app->instance(Matchkits::class, $mock);

DispatchMatchkitsJob::dispatch();
DispatchMatchkitsJob::dispatch($mock);
}
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Log;
use Exception;
13 changes: 13 additions & 0 deletions tests/Unit/DnaServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ public function testDispatchMatchkitsJobIsBoundCorrectly()
$resolvedInstance = App::make('dispatchMatchkits');
$this->assertInstanceOf(DispatchMatchkitsJob::class, $resolvedInstance);
}

/**
* Additional test methods will be placed here.
*/
}
/**
* Test that the DnaServiceProvider boots correctly.
*/
public function testServiceProviderBootsCorrectly()
{
// Since the boot method is currently empty, this test will act as a placeholder.
// Future logic to be tested can be added here.
$this->assertTrue(true, 'Placeholder assertion until boot logic is implemented.');
}

0 comments on commit 1e1717c

Please sign in to comment.