Generate a .info file

This commit is contained in:
Oliver Davies 2020-02-09 13:32:21 +00:00
parent 000716d670
commit 55ca3647c4
6 changed files with 255 additions and 69 deletions

View file

@ -6,12 +6,14 @@ use Opdavies\DrupalModuleGenerator\Command\GenerateDrupal7Command;
use Opdavies\DrupalModuleGenerator\Exception\CannotCreateModuleException;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
class GenerateDrupal7ModuleCommandTest extends TestCase
{
protected function tearDown(): void
{
rmdir('test_module');
(new Filesystem())->remove('test_module');
}
/** @test */
@ -20,7 +22,10 @@ class GenerateDrupal7ModuleCommandTest extends TestCase
$this->expectExceptionObject(CannotCreateModuleException::directoryAlreadyExists());
$commandTester = new CommandTester(new GenerateDrupal7Command());
$finder = new Finder();
$command = new GenerateDrupal7Command($finder);
$commandTester = new CommandTester($command);
$commandTester->execute([
'module-name' => 'test_module'
]);
@ -29,17 +34,33 @@ class GenerateDrupal7ModuleCommandTest extends TestCase
/** @test */
public function it_creates_a_new_module_directory()
{
$commandTester = new CommandTester(new GenerateDrupal7Command());
$finder = new Finder();
$command = new GenerateDrupal7Command($finder);
$commandTester = new CommandTester($command);
$commandTester->execute([
'module-name' => 'test_module',
]);
$this->assertTrue(is_dir('test_module'));
}
/** @test */
public function it_generates_an_info_file()
{
$finder = new Finder();
$command = new GenerateDrupal7Command($finder);
$commandTester = new CommandTester($command);
$commandTester->execute([
'module-name' => 'test_module',
]);
$this->assertTrue(is_dir('my-new-drupal-module'));
$this->assertTrue(is_file('test_module/test_module.info'));
rmdir('my-new-drupal-module');
$contents = file_get_contents('test_module/test_module.info');
$this->assertStringContainsString('name = test_module', $contents);
$this->assertStringContainsString('description = The description for test_module.', $contents);
}
}