| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Tests\Unit\Service\Cron;
- use App\Service\Cron\BaseCronJob;
- use App\Service\Cron\UI\ConsoleUI;
- use App\Service\Cron\UI\CronUIInterface;
- use App\Service\Cron\UI\SilentUI;
- use PHPUnit\Framework\TestCase;
- use Psr\Log\LoggerInterface;
- class TestableBaseCronJob extends BaseCronJob
- {
- public function getUI(): CronUIInterface
- {
- return $this->ui;
- }
- public function getLogger(): LoggerInterface
- {
- return $this->logger;
- }
- public function preview(): void
- {
- }
- public function execute(): void
- {
- }
- }
- class BaseCronJobTest extends TestCase
- {
- public function testName(): void
- {
- $job = new TestableBaseCronJob(); // can't use a mock here, because it'll mess up with the class's name
- $this->assertEquals(
- 'testable-base-cron-job',
- $job->name()
- );
- }
- public function testSetLogger(): void
- {
- $job = $this->getMockBuilder(TestableBaseCronJob::class)
- ->setMethodsExcept(['setLoggerInterface', 'getLogger'])
- ->getMock();
- $logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock();
- $job->setLoggerInterface($logger);
- $this->assertEquals(
- $logger,
- $job->getLogger()
- );
- }
- public function testDefaultUi(): void
- {
- $job = new TestableBaseCronJob(); // can't use a mock here, because we need the constructor to run
- $this->assertInstanceOf(
- SilentUI::class,
- $job->getUI()
- );
- }
- public function testSetUi(): void
- {
- $job = $this->getMockBuilder(TestableBaseCronJob::class)
- ->setMethodsExcept(['setUI', 'getUI'])
- ->getMock();
- $ui = $this->getMockBuilder(ConsoleUI::class)
- ->disableOriginalConstructor()
- ->getMock();
- $job->setUI($ui);
- $this->assertEquals(
- $ui,
- $job->getUI()
- );
- }
- }
|