View source
<?php
namespace Drupal\Tests\lightning_core\Unit;
use Drupal\lightning_core\UpdateManager;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Console\Style\StyleInterface;
class UpdateManagerTest extends UnitTestCase {
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',
],
[
'8.x-3.001',
'3.001.0',
],
];
}
public function testGetTasks() {
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());
}
}
final class TestUpdateManager extends UpdateManager {
public function getTasks($handler) {
return parent::getTasks($handler);
}
}
final class TestUpdateHandler {
public function foo(StyleInterface $io) {
$io
->success('Dude, sweet!');
}
public function nope(StyleInterface $io) {
$io
->error('Oh, the humanity!');
}
public function bar() {
}
protected function baz() {
}
private function wambooli() {
}
}