From 4073642879b6fe5139e1ba41aac4bcccc1da84cd Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Mon, 19 Feb 2024 09:54:50 +0700 Subject: [PATCH] refactor: Move description to trait --- src/PhpPact/Consumer/Model/Interaction.php | 17 +++------------- .../Model/Interaction/DescriptionTrait.php | 20 +++++++++++++++++++ src/PhpPact/Consumer/Model/Message.php | 16 ++------------- 3 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 src/PhpPact/Consumer/Model/Interaction/DescriptionTrait.php diff --git a/src/PhpPact/Consumer/Model/Interaction.php b/src/PhpPact/Consumer/Model/Interaction.php index 5cc23cab..ec402fb0 100644 --- a/src/PhpPact/Consumer/Model/Interaction.php +++ b/src/PhpPact/Consumer/Model/Interaction.php @@ -2,31 +2,20 @@ namespace PhpPact\Consumer\Model; +use PhpPact\Consumer\Model\Interaction\DescriptionTrait; + /** * Request/Response Pair to be posted to the Mock Server for PACT tests. */ class Interaction { use ProviderStates; - - private string $description; + use DescriptionTrait; private ConsumerRequest $request; private ProviderResponse $response; - public function getDescription(): string - { - return $this->description; - } - - public function setDescription(string $description): self - { - $this->description = $description; - - return $this; - } - public function getRequest(): ConsumerRequest { return $this->request; diff --git a/src/PhpPact/Consumer/Model/Interaction/DescriptionTrait.php b/src/PhpPact/Consumer/Model/Interaction/DescriptionTrait.php new file mode 100644 index 00000000..dabd9a80 --- /dev/null +++ b/src/PhpPact/Consumer/Model/Interaction/DescriptionTrait.php @@ -0,0 +1,20 @@ +description; + } + + public function setDescription(string $description): self + { + $this->description = $description; + + return $this; + } +} diff --git a/src/PhpPact/Consumer/Model/Message.php b/src/PhpPact/Consumer/Model/Message.php index 4ee117d8..efce790e 100644 --- a/src/PhpPact/Consumer/Model/Message.php +++ b/src/PhpPact/Consumer/Model/Message.php @@ -8,6 +8,7 @@ use PhpPact\Consumer\Model\Body\Binary; use PhpPact\Consumer\Model\Body\Multipart; use PhpPact\Consumer\Model\Body\Text; +use PhpPact\Consumer\Model\Interaction\DescriptionTrait; /** * Message metadata and contents to be posted to the Mock Server for PACT tests. @@ -15,8 +16,7 @@ class Message { use ProviderStates; - - private string $description; + use DescriptionTrait; /** * @var array @@ -25,18 +25,6 @@ class Message private Text|Binary|null $contents = null; - public function getDescription(): string - { - return $this->description; - } - - public function setDescription(string $description): self - { - $this->description = $description; - - return $this; - } - /** * @return array */