drupal-module-generator/tests/Command/GenerateDrupal7ModuleCommandTest.php

85 lines
2.5 KiB
PHP
Raw Normal View History

<?php
namespace Opdavies\Tests\DrupalModuleGenerator\Command;
use Opdavies\DrupalModuleGenerator\Command\GenerateDrupal7Command;
use Opdavies\DrupalModuleGenerator\Exception\CannotCreateModuleException;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit\Framework\TestCase;
2020-02-09 13:32:21 +00:00
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
class GenerateDrupal7ModuleCommandTest extends TestCase
{
protected function tearDown(): void
{
2020-02-09 13:32:21 +00:00
(new Filesystem())->remove('test_module');
}
/** @test */
public function it_throws_an_exception_if_the_directory_already_exists() {
mkdir('test_module');
$this->expectExceptionObject(CannotCreateModuleException::directoryAlreadyExists());
2020-02-09 13:32:21 +00:00
$finder = new Finder();
$command = new GenerateDrupal7Command($finder);
$commandTester = new CommandTester($command);
$commandTester->execute([
'module-name' => 'test_module'
]);
}
2020-02-09 12:24:28 +00:00
/** @test */
public function it_creates_a_new_module_directory()
{
2020-02-09 13:32:21 +00:00
$finder = new Finder();
$command = new GenerateDrupal7Command($finder);
$commandTester = new CommandTester($command);
2020-02-09 12:24:28 +00:00
$commandTester->execute([
'module-name' => 'test_module',
]);
$this->assertTrue(is_dir('test_module'));
}
2020-02-09 13:32:21 +00:00
/** @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',
2020-02-09 12:24:28 +00:00
]);
2020-02-09 13:32:21 +00:00
$this->assertTrue(is_file('test_module/test_module.info'));
$contents = file_get_contents('test_module/test_module.info');
2020-02-09 12:24:28 +00:00
2020-02-09 13:32:21 +00:00
$this->assertStringContainsString('name = test_module', $contents);
$this->assertStringContainsString('description = The description for test_module.', $contents);
2020-02-09 12:24:28 +00:00
}
2020-02-09 13:55:11 +00:00
/** @test */
public function it_generates_a_module_file()
{
$finder = new Finder();
$command = new GenerateDrupal7Command($finder);
$commandTester = new CommandTester($command);
$commandTester->execute([
'module-name' => 'test_module',
]);
$this->assertTrue(is_file('test_module/test_module.module'));
$contents = file_get_contents('test_module/test_module.module');
$this->assertStringContainsString('The main module file for test_module.', $contents);
}
}