From 000716d67072dbdb6cd3d64275ab585a7b7a5cbe Mon Sep 17 00:00:00 2001 From: Oliver Davies <oliver@oliverdavies.uk> Date: Sun, 9 Feb 2020 12:30:28 +0000 Subject: [PATCH] Refactor Use tearDown, update module name --- .../GenerateDrupal7ModuleCommandTest.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/Command/GenerateDrupal7ModuleCommandTest.php b/tests/Command/GenerateDrupal7ModuleCommandTest.php index 2bb5749..1540b8e 100644 --- a/tests/Command/GenerateDrupal7ModuleCommandTest.php +++ b/tests/Command/GenerateDrupal7ModuleCommandTest.php @@ -9,20 +9,21 @@ use PHPUnit\Framework\TestCase; class GenerateDrupal7ModuleCommandTest extends TestCase { + protected function tearDown(): void + { + rmdir('test_module'); + } + /** @test */ public function it_throws_an_exception_if_the_directory_already_exists() { - mkdir('my-existing-drupal-module'); + mkdir('test_module'); - try { - $commandTester = new CommandTester(new GenerateDrupal7Command()); - $commandTester->execute([ - 'module-name' => 'my-existing-drupal-module', - ]); - } catch (CannotCreateModuleException $e) { - $this->addToAssertionCount(1); - } + $this->expectExceptionObject(CannotCreateModuleException::directoryAlreadyExists()); - rmdir('my-existing-drupal-module'); + $commandTester = new CommandTester(new GenerateDrupal7Command()); + $commandTester->execute([ + 'module-name' => 'test_module' + ]); } /** @test */ @@ -30,7 +31,11 @@ class GenerateDrupal7ModuleCommandTest extends TestCase { $commandTester = new CommandTester(new GenerateDrupal7Command()); $commandTester->execute([ - 'module-name' => 'my-new-drupal-module', + 'module-name' => 'test_module', + ]); + + $this->assertTrue(is_dir('test_module')); + } ]); $this->assertTrue(is_dir('my-new-drupal-module'));