ScheduledTransitionsCronUnitTest.php in Scheduled Transitions 2.x
File
tests/src/Unit/ScheduledTransitionsCronUnitTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\scheduled_transitions\Unit;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\scheduled_transitions\ScheduledTransitionsHooks;
use Drupal\scheduled_transitions\ScheduledTransitionsJobsInterface;
use Drupal\Tests\UnitTestCase;
class ScheduledTransitionsCronUnitTest extends UnitTestCase {
protected $testConfigFactory;
protected $testJobs;
public function __construct() {
parent::__construct();
$this->testConfigFactory = $this
->createMock(ConfigFactoryInterface::class);
$this->testJobs = $this
->createMock(ScheduledTransitionsJobsInterface::class);
}
public function testCronOn() : void {
$testConfig = $this
->createMock(ImmutableConfig::class);
$testConfig
->expects($this
->once())
->method('get')
->with('automation.cron_create_queue_items')
->willReturn(TRUE);
$this->testConfigFactory
->expects($this
->once())
->method('get')
->with('scheduled_transitions.settings')
->willReturn($testConfig);
$this->testJobs
->expects($this
->once())
->method('jobCreator');
$hooksService = new ScheduledTransitionsHooks($this->testConfigFactory, $this->testJobs);
$hooksService
->cron();
}
public function testCronOff() : void {
$testConfig = $this
->createMock(ImmutableConfig::class);
$testConfig
->expects($this
->once())
->method('get')
->with('automation.cron_create_queue_items')
->willReturn(FALSE);
$this->testConfigFactory
->expects($this
->once())
->method('get')
->with('scheduled_transitions.settings')
->willReturn($testConfig);
$this->testJobs
->expects($this
->never())
->method('jobCreator');
$hooksService = new ScheduledTransitionsHooks($this->testConfigFactory, $this->testJobs);
$hooksService
->cron();
}
}