Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslaw-przylucki committed May 2, 2024
1 parent 6c5e41a commit 0847885
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Tempest\Console\ConsoleOutput;
use Tempest\Container\Container;

final class SchedulerRunInvocation
final class SchedulerRunInvocationCommand
{
public const string NAME = 'scheduler:invoke';

Expand Down
4 changes: 2 additions & 2 deletions src/Scheduler/GenericScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Tempest\Console\Scheduler;

use DateTime;
use Tempest\Console\Commands\SchedulerRunInvocation;
use Tempest\Console\Commands\SchedulerRunInvocationCommand;

final class GenericScheduler implements Scheduler
{
Expand Down Expand Up @@ -38,7 +38,7 @@ private function execute(ScheduledInvocation $invocation): void
private function compileInvocation(ScheduledInvocation $invocation): string
{
$commandName = $invocation->invocation instanceof HandlerInvocation ?
SchedulerRunInvocation::NAME . ' ' . $invocation->invocation->getName()
SchedulerRunInvocationCommand::NAME . ' ' . $invocation->invocation->getName()
: $invocation->invocation->getName();

return join(' ', [
Expand Down
24 changes: 0 additions & 24 deletions tests/Fixtures/ScheduledCommand.php

This file was deleted.

12 changes: 7 additions & 5 deletions tests/Scheduler/GenericSchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
final class GenericSchedulerTest extends TestCase
{
public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -89,6 +89,8 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times()
// command won't run twice in a row
$scheduler->run($at);

// nor when it's called before the next minute
$scheduler->run($at->modify('+30 seconds'));

$executor = $this->createMock(NullInvocationExecutor::class);

Expand All @@ -101,13 +103,13 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times()
$scheduler->run($at->modify('+1 minute'));
}

public function handler()
// dummy handler for testing
public function handler(): void
{

}

public function command()
// dummy command for testing
public function command(): void
{

}
}
34 changes: 34 additions & 0 deletions tests/Scheduler/HandlerInvocationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Tests\Tempest\Console\Scheduler;

use PHPUnit\Framework\TestCase;
use ReflectionMethod;
use Tempest\Console\Scheduler\HandlerInvocation;

/**
* @internal
* @small
*/
final class HandlerInvocationTest extends TestCase
{
public function test_name_gets_constructed_properly(): void
{
$invocation = new HandlerInvocation(
new ReflectionMethod(
objectOrMethod: $this,
method: 'handler',
),
);

$this->assertSame('Tests\\\Tempest\\\Console\\\Scheduler\\\HandlerInvocationTest::handler', $invocation->getName());
}

// dummy handler method
public function handler()
{

}
}
22 changes: 22 additions & 0 deletions tests/Scheduler/SchedulerInvokeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Tests\Tempest\Console\Scheduler;

use App\Console\ScheduledCommand;
use Tempest\Console\Commands\SchedulerRunInvocationCommand;
use Tests\Tempest\Console\TestCase;

/**
* @internal
* @small
*/
final class SchedulerInvokeCommandTest extends TestCase
{
public function test_scheduler_invoke_command_executes_handler()
{
$this->console->call(SchedulerRunInvocationCommand::NAME . ' ' . (ScheduledCommand::class . '::method'))
->assertContains('method got scheduled');
}
}

0 comments on commit 0847885

Please sign in to comment.