From a5e2fcce63168100096506f6292d7d20146f1a15 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 21 Apr 2021 00:25:12 +0100 Subject: [PATCH] Extract ConvertPostToTweetTest --- .../Kernel/Action/ConvertPostToTweetTest.php | 58 +++++++++++++++++++ .../tests/src/Kernel/Entity/Node/PostTest.php | 44 -------------- 2 files changed, 58 insertions(+), 44 deletions(-) create mode 100644 web/modules/custom/blog/tests/src/Kernel/Action/ConvertPostToTweetTest.php diff --git a/web/modules/custom/blog/tests/src/Kernel/Action/ConvertPostToTweetTest.php b/web/modules/custom/blog/tests/src/Kernel/Action/ConvertPostToTweetTest.php new file mode 100644 index 0000000..b86eb3b --- /dev/null +++ b/web/modules/custom/blog/tests/src/Kernel/Action/ConvertPostToTweetTest.php @@ -0,0 +1,58 @@ +postFactory + ->setTitle('Creating a custom PHPUnit command for DDEV') + ->withTags(['Automated testing', 'DDEV', 'Drupal', 'Drupal 8', 'PHP']) + ->create(); + + $post->save(); + + $expected = <<assertSame($expected, ($this->convertPostToTweet)($post)); + } + + public function testCertainTermsAreNotAddedAsHashtags(): void { + $post = $this->postFactory + ->setTitle('Drupal Planet should not be added as a hashtag') + ->withTags(['Drupal', 'Drupal Planet', 'PHP']) + ->create(); + + $post->save(); + + $expected = <<assertSame($expected, ($this->convertPostToTweet)($post)); + } + + protected function setUp() { + parent::setUp(); + + $this->convertPostToTweet = $this->container->get(ConvertPostToTweet::class); + $this->postFactory = $this->container->get(PostFactory::class); + } + +} diff --git a/web/modules/custom/blog/tests/src/Kernel/Entity/Node/PostTest.php b/web/modules/custom/blog/tests/src/Kernel/Entity/Node/PostTest.php index 232248d..c80c084 100644 --- a/web/modules/custom/blog/tests/src/Kernel/Entity/Node/PostTest.php +++ b/web/modules/custom/blog/tests/src/Kernel/Entity/Node/PostTest.php @@ -5,7 +5,6 @@ namespace Drupal\Tests\opdavies_blog\Kernel\Entity\Node; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; -use Drupal\opdavies_blog\Action\ConvertPostToTweet; use Drupal\opdavies_blog\Entity\Node\Post; use Drupal\opdavies_blog_test\Factory\PostFactory; @@ -27,8 +26,6 @@ final class PostTest extends EntityKernelTestBase { private PostFactory $postFactory; - private ConvertPostToTweet $convertPostToTweet; - /** @test */ public function it_can_determine_if_a_post_contains_a_tweet(): void { $post = $this->postFactory->create(); @@ -42,51 +39,10 @@ final class PostTest extends EntityKernelTestBase { $this->assertTrue($post->hasTweet()); } - /** @test */ - public function it_converts_a_post_to_a_tweet(): void { - $post = $this->postFactory - ->setTitle('Creating a custom PHPUnit command for DDEV') - ->withTags(['Automated testing', 'DDEV', 'Drupal', 'Drupal 8', 'PHP']) - ->create(); - - $post->save(); - - $expected = <<assertSame($expected, ($this->convertPostToTweet)($post)); - } - - /** @test */ - public function certain_terms_are_not_added_as_hashtags(): void { - $post = $this->postFactory - ->setTitle('Drupal Planet should not be added as a hashtag') - ->withTags(['Drupal', 'Drupal Planet', 'PHP']) - ->create(); - - $post->save(); - - $expected = <<assertSame($expected, ($this->convertPostToTweet)($post)); - } - protected function setUp() { parent::setUp(); $this->postFactory = $this->container->get(PostFactory::class); - $this->convertPostToTweet = $this->container->get(ConvertPostToTweet::class); $this->installEntitySchema('taxonomy_term');