From 9d1cbdeffd5166e05c2da6a248bca1961a32212a Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 21 Apr 2021 00:13:54 +0100 Subject: [PATCH] Use convertPostToTweet within the test Use the convertPostToTweet action within the tests rather than calling the toTweet() method, and delegate the Action to using the toTweet() functionality. --- web/modules/custom/blog/src/Action/ConvertPostToTweet.php | 4 ++++ .../custom/blog/tests/src/Kernel/Entity/Node/PostTest.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/web/modules/custom/blog/src/Action/ConvertPostToTweet.php b/web/modules/custom/blog/src/Action/ConvertPostToTweet.php index 1f6ddc5..4e64980 100644 --- a/web/modules/custom/blog/src/Action/ConvertPostToTweet.php +++ b/web/modules/custom/blog/src/Action/ConvertPostToTweet.php @@ -8,4 +8,8 @@ use Drupal\opdavies_blog\Entity\Node\Post; final class ConvertPostToTweet { + public function __invoke(Post $post): string { + return $post->toTweet(); + } + } 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 dea8dfc..232248d 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 @@ -59,7 +59,7 @@ final class PostTest extends EntityKernelTestBase { #AutomatedTesting #DDEV #Drupal #Drupal8 #PHP EOF; - $this->assertSame($expected, $post->toTweet()); + $this->assertSame($expected, ($this->convertPostToTweet)($post)); } /** @test */ @@ -79,7 +79,7 @@ final class PostTest extends EntityKernelTestBase { #Drupal #PHP EOF; - $this->assertSame($expected, $post->toTweet()); + $this->assertSame($expected, ($this->convertPostToTweet)($post)); } protected function setUp() {