From 4a66016a3256d9744b2fb99c2ac34429fda19c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Mon, 29 Jul 2019 19:21:03 +0200 Subject: [PATCH] Added support for displayName in the methods --- src/Method.php | 35 +++++++++++++++++++++++++++++++++++ tests/MethodTest.php | 14 ++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/Method.php b/src/Method.php index ab12d13e..f52104b1 100644 --- a/src/Method.php +++ b/src/Method.php @@ -26,6 +26,15 @@ class Method implements ArrayInstantiationInterface, MessageSchemaInterface */ private $type; + /** + * The display name (optional) + * + * @see http://raml.org/spec.html#displayname + * + * @var string|null + */ + private $displayName; + /** * The description of the method (optional) * @@ -149,6 +158,10 @@ public static function createFromArray($method, array $data = [], ApiDefinition } } + if (isset($data['displayName'])) { + $method->setDisplayName($data['displayName']); + } + if (isset($data['description'])) { $method->setDescription($data['description']); } @@ -243,6 +256,28 @@ public function setDescription($description) // -- + /** + * Get the display name + * + * @return string|null + */ + public function getDisplayName() + { + return $this->displayName; + } + + /** + * Set the display name + * + * @param string|null $displayName + */ + public function setDisplayName($displayName) + { + $this->displayName = $displayName; + } + + // -- + /** * Get the base uri parameters * diff --git a/tests/MethodTest.php b/tests/MethodTest.php index 4610797d..2f09917e 100644 --- a/tests/MethodTest.php +++ b/tests/MethodTest.php @@ -41,6 +41,20 @@ public function shouldGetTheDescriptionIfPassedInTheDataArray() $this->assertNull($method->getDescription()); } + /** + * @test + */ + public function shouldGetTheDisplayNameIfPassedInTheDataArray() + { + $apiDefinition = new ApiDefinition('The title'); + + $method = Method::createFromArray('get', ['displayName' => 'A dummy name'], $apiDefinition); + $this->assertSame('A dummy name', $method->getDisplayName()); + + $method = Method::createFromArray('get', [], $apiDefinition); + $this->assertNull($method->getDisplayName()); + } + /** * @test */