You are here

class ScheduledTransitionsCronUnitTest in Scheduled Transitions 2.x

Same name and namespace in other branches
  1. 8 tests/src/Unit/ScheduledTransitionsCronUnitTest.php \Drupal\Tests\scheduled_transitions\Unit\ScheduledTransitionsCronUnitTest

Tests cron hooks.

@coversDefaultClass \Drupal\scheduled_transitions\ScheduledTransitionsHooks @group scheduled_transitions

Hierarchy

Expanded class hierarchy of ScheduledTransitionsCronUnitTest

File

tests/src/Unit/ScheduledTransitionsCronUnitTest.php, line 19

Namespace

Drupal\Tests\scheduled_transitions\Unit
View source
class ScheduledTransitionsCronUnitTest extends UnitTestCase {

  /**
   * A test config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $testConfigFactory;

  /**
   * Test jobs.
   *
   * @var \Drupal\scheduled_transitions\ScheduledTransitionsJobsInterface
   */
  protected $testJobs;

  /**
   * ScheduledTransitionsCronUnitTest constructor.
   */
  public function __construct() {
    parent::__construct();
    $this->testConfigFactory = $this
      ->createMock(ConfigFactoryInterface::class);
    $this->testJobs = $this
      ->createMock(ScheduledTransitionsJobsInterface::class);
  }

  /**
   * Tests creating queue items during cron.
   *
   * @covers ::cron
   */
  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();
  }

  /**
   * Tests not creating queue items during cron.
   *
   * @covers ::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();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
ScheduledTransitionsCronUnitTest::$testConfigFactory protected property A test config factory.
ScheduledTransitionsCronUnitTest::$testJobs protected property Test jobs.
ScheduledTransitionsCronUnitTest::testCronOff public function Tests not creating queue items during cron.
ScheduledTransitionsCronUnitTest::testCronOn public function Tests creating queue items during cron.
ScheduledTransitionsCronUnitTest::__construct public function ScheduledTransitionsCronUnitTest constructor.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 308
UnitTestCase::setUpBeforeClass public static function