DevelReinstallCommandTest.php
Namespace
Drupal\Tests\devel\Kernel
File
-
tests/src/Kernel/DevelReinstallCommandTest.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\devel\Kernel;
use Drupal\devel\Command\DevelReinstallCommand;
use Drupal\KernelTests\KernelTestBase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
class DevelReinstallCommandTest extends KernelTestBase {
protected static $modules = [
'system',
'user',
];
public function testReinstall() : void {
$this->installSchema('user', [
'users_data',
]);
$this->container
->get('module_installer')
->install([
'help',
'syslog',
]);
\Drupal::keyValue('system.schema')->set('help', 1234);
$tester = $this->runCommand('help, syslog');
$this->assertSame(Command::SUCCESS, $tester->getStatusCode(), $tester->getDisplay());
$this->assertStringContainsString('help,syslog reinstalled.', $tester->getDisplay());
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('help'));
$this->assertTrue(\Drupal::moduleHandler()->moduleExists('syslog'));
$this->assertNotSame(1234, \Drupal::keyValue('system.schema')->get('help'));
}
public function testNotInstalled() : void {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Not installed: no_such_module');
$this->runCommand('system,no_such_module');
}
public function testRequired() : void {
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Unable to uninstall.');
$this->runCommand('system');
}
protected function runCommand(string $modules) : CommandTester {
$command = new DevelReinstallCommand(\Drupal::service('module_installer'), \Drupal::moduleHandler());
$tester = new CommandTester(new Command(NULL, $command));
$tester->execute([
'modules' => $modules,
], [
'interactive' => FALSE,
]);
return $tester;
}
}
Classes