You are here

class UpdateManagerTest in Lightning Core 8.5

Same name in this branch
  1. 8.5 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest
  2. 8.5 tests/src/Kernel/UpdateManagerTest.php \Drupal\Tests\lightning_core\Kernel\UpdateManagerTest
Same name and namespace in other branches
  1. 8 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest
  2. 8.2 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest
  3. 8.3 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest
  4. 8.4 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest

@coversDefaultClass \Drupal\lightning_core\UpdateManager

@group lightning_core @group orca_public

Hierarchy

Expanded class hierarchy of UpdateManagerTest

File

tests/src/Unit/UpdateManagerTest.php, line 15

Namespace

Drupal\Tests\lightning_core\Unit
View source
class UpdateManagerTest extends UnitTestCase {

  /**
   * @covers ::toSemanticVersion
   *
   * @dataProvider providerSemanticVersion
   */
  public function testSemanticVersion($drupal_version, $semantic_version) {
    $this
      ->assertSame($semantic_version, UpdateManager::toSemanticVersion($drupal_version));
  }
  public function providerSemanticVersion() {
    return [
      [
        '8.x-1.12',
        '1.12.0',
      ],
      [
        '8.x-1.2-alpha3',
        '1.2.0-alpha3',
      ],
      [
        '8.x-2.7-beta3',
        '2.7.0-beta3',
      ],
      [
        '8.x-1.42-rc1',
        '1.42.0-rc1',
      ],
      [
        '8.x-1.x-dev',
        '1.x-dev',
      ],
      // This is a weird edge case only used by the Lightning profile.
      [
        '8.x-3.001',
        '3.001.0',
      ],
    ];
  }

  /**
   * @covers ::getTasks
   */
  public function testGetTasks() {

    // Prevent 'undefined constant' errors caused by ModuleExtensionList using
    // the DRUPAL_MINIMUM_PHP constant from bootstrap.inc, which is never loaded
    // during this test.
    if (!defined('DRUPAL_MINIMUM_PHP')) {
      define('DRUPAL_MINIMUM_PHP', '5.5.9');
    }
    $update_manager = new TestUpdateManager(new \ArrayIterator(), $this
      ->createMock('\\Drupal\\Core\\DependencyInjection\\ClassResolverInterface'), $this
      ->createMock('\\Drupal\\Core\\Config\\ConfigFactoryInterface'), $this
      ->createMock('\\Drupal\\Core\\Extension\\ModuleExtensionList'));
    $tasks = $update_manager
      ->getTasks(new TestUpdateHandler());
    $tasks = iterator_to_array($tasks);
    $this
      ->assertCount(2, $tasks);
    $io = $this
      ->prophesize(StyleInterface::class);
    $io
      ->confirm('Can you trip like I do?')
      ->willReturn(TRUE);
    $io
      ->success('Dude, sweet!')
      ->shouldBeCalled();
    $tasks[0]
      ->execute($io
      ->reveal());
    $io
      ->confirm('Why would you do this?')
      ->willReturn(FALSE);
    $io
      ->error('Oh, the humanity!')
      ->shouldNotBeCalled();
    $tasks[1]
      ->execute($io
      ->reveal());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
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 340
UpdateManagerTest::providerSemanticVersion public function
UpdateManagerTest::testGetTasks public function @covers ::getTasks
UpdateManagerTest::testSemanticVersion public function @covers ::toSemanticVersion