|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Illuminate\Tests\Console\Scheduling; |
| 6 | + |
| 7 | +use Illuminate\Console\Scheduling\EventMutex; |
| 8 | +use Illuminate\Console\Scheduling\Schedule; |
| 9 | +use Illuminate\Console\Scheduling\SchedulingMutex; |
| 10 | +use Illuminate\Container\Container; |
| 11 | +use Illuminate\Contracts\Queue\ShouldQueue; |
| 12 | +use Illuminate\Tests\Console\Fixtures\JobToTestWithSchedule; |
| 13 | +use Mockery as m; |
| 14 | +use Mockery\MockInterface; |
| 15 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 16 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +#[CoversClass(Schedule::class)] |
| 20 | +final class ScheduleTest extends TestCase |
| 21 | +{ |
| 22 | + private Container $container; |
| 23 | + private EventMutex&MockInterface $eventMutex; |
| 24 | + private SchedulingMutex&MockInterface $schedulingMutex; |
| 25 | + |
| 26 | + protected function setUp(): void |
| 27 | + { |
| 28 | + parent::setUp(); |
| 29 | + |
| 30 | + $this->container = new Container; |
| 31 | + Container::setInstance($this->container); |
| 32 | + $this->eventMutex = m::mock(EventMutex::class); |
| 33 | + $this->container->instance(EventMutex::class, $this->eventMutex); |
| 34 | + $this->schedulingMutex = m::mock(SchedulingMutex::class); |
| 35 | + $this->container->instance(SchedulingMutex::class, $this->schedulingMutex); |
| 36 | + } |
| 37 | + |
| 38 | + #[DataProvider('jobHonoursDisplayNameIfMethodExistsProvider')] |
| 39 | + public function testJobHonoursDisplayNameIfMethodExists(object $job, string $jobName): void |
| 40 | + { |
| 41 | + $schedule = new Schedule(); |
| 42 | + $scheduledJob = $schedule->job($job); |
| 43 | + self::assertSame($jobName, $scheduledJob->description); |
| 44 | + self::assertFalse($this->container->resolved(JobToTestWithSchedule::class)); |
| 45 | + } |
| 46 | + |
| 47 | + public static function jobHonoursDisplayNameIfMethodExistsProvider(): array |
| 48 | + { |
| 49 | + $job = new class implements ShouldQueue |
| 50 | + { |
| 51 | + public function displayName(): string |
| 52 | + { |
| 53 | + return 'testJob-123'; |
| 54 | + } |
| 55 | + }; |
| 56 | + |
| 57 | + return [ |
| 58 | + [new JobToTestWithSchedule, JobToTestWithSchedule::class], |
| 59 | + [$job, 'testJob-123'], |
| 60 | + ]; |
| 61 | + } |
| 62 | + |
| 63 | + public function testJobIsNotInstantiatedIfSuppliedAsClassname(): void |
| 64 | + { |
| 65 | + $schedule = new Schedule(); |
| 66 | + $scheduledJob = $schedule->job(JobToTestWithSchedule::class); |
| 67 | + self::assertSame(JobToTestWithSchedule::class, $scheduledJob->description); |
| 68 | + self::assertFalse($this->container->resolved(JobToTestWithSchedule::class)); |
| 69 | + } |
| 70 | +} |
0 commit comments