You are here

public function UpdateManagerTest::testGetTasks in Lightning Core 8.3

Same name and namespace in other branches
  1. 8.5 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest::testGetTasks()
  2. 8 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest::testGetTasks()
  3. 8.2 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest::testGetTasks()
  4. 8.4 tests/src/Unit/UpdateManagerTest.php \Drupal\Tests\lightning_core\Unit\UpdateManagerTest::testGetTasks()

@covers ::getTasks

File

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

Class

UpdateManagerTest
@coversDefaultClass \Drupal\lightning_core\UpdateManager

Namespace

Drupal\Tests\lightning_core\Unit

Code

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());
}