From 7d5cceedf13ea4262bc8661f68ee9c86caf45eb9 Mon Sep 17 00:00:00 2001 From: Ralf Eggert Date: Sun, 26 Nov 2017 19:45:48 +0100 Subject: [PATCH] Add Hint directive --- .../Directives/Display/RenderTemplate.php | 5 +- src/Response/Directives/Hint/Hint.php | 64 +++++++++++++++++++ .../Directives/Display/RenderTemplateTest.php | 10 --- .../Directives/Display/TextContentTest.php | 10 --- test/Response/Directives/Hint/HintTest.php | 41 ++++++++++++ 5 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 src/Response/Directives/Hint/Hint.php create mode 100644 test/Response/Directives/Hint/HintTest.php diff --git a/src/Response/Directives/Display/RenderTemplate.php b/src/Response/Directives/Display/RenderTemplate.php index 39b44f9..11d25b8 100644 --- a/src/Response/Directives/Display/RenderTemplate.php +++ b/src/Response/Directives/Display/RenderTemplate.php @@ -72,8 +72,9 @@ class RenderTemplate implements DirectivesInterface /** * RenderTemplate constructor. * - * @param string $type - * @param string $token + * @param string $type + * @param string $token + * @param TextContent $textContent */ public function __construct(string $type, string $token, TextContent $textContent) { diff --git a/src/Response/Directives/Hint/Hint.php b/src/Response/Directives/Hint/Hint.php new file mode 100644 index 0000000..290f398 --- /dev/null +++ b/src/Response/Directives/Hint/Hint.php @@ -0,0 +1,64 @@ + + * @license http://opensource.org/licenses/MIT The MIT License (MIT) + * @link https://github.com/travello-gmbh/amazon-alexa-skill-library + * @link https://www.travello.audio/ + * + */ + +namespace TravelloAlexaLibrary\Response\Directives\Hint; + +use TravelloAlexaLibrary\Response\Directives\DirectivesInterface; + +/** + * Class Hint + * + * @package TravelloAlexaLibrary\Response\Directives\Hint + */ +class Hint implements DirectivesInterface +{ + /** Type of directive */ + const DIRECTIVE_TYPE = 'Hint'; + + /** @var string */ + private $text; + + /** + * Hint constructor. + * + * @param string $text + */ + public function __construct(string $text) + { + $this->text = $text; + } + + /** + * Get the directive type + * + * @return string + */ + public function getType(): string + { + return self::DIRECTIVE_TYPE; + } + + /** + * Render the directives object to an array + * + * @return array + */ + public function toArray(): array + { + return [ + 'type' => self::DIRECTIVE_TYPE, + 'hint' => [ + 'type' => 'PlainText', + 'text' => $this->text, + ], + ]; + } +} diff --git a/test/Response/Directives/Display/RenderTemplateTest.php b/test/Response/Directives/Display/RenderTemplateTest.php index b4d1eca..289d795 100644 --- a/test/Response/Directives/Display/RenderTemplateTest.php +++ b/test/Response/Directives/Display/RenderTemplateTest.php @@ -9,16 +9,6 @@ * */ -/** - * PHP Library for Amazon Alexa Skills - * - * @author Ralf Eggert - * @license http://opensource.org/licenses/MIT The MIT License (MIT) - * @link https://github.com/travello-gmbh/amazon-alexa-skill-library - * @link https://www.travello.audio/ - * - */ - namespace TravelloAlexaLibraryTest\Response\Directives\Display; use PHPUnit\Framework\TestCase; diff --git a/test/Response/Directives/Display/TextContentTest.php b/test/Response/Directives/Display/TextContentTest.php index 3224ef5..9fbfdcd 100644 --- a/test/Response/Directives/Display/TextContentTest.php +++ b/test/Response/Directives/Display/TextContentTest.php @@ -9,16 +9,6 @@ * */ -/** - * PHP Library for Amazon Alexa Skills - * - * @author Ralf Eggert - * @license http://opensource.org/licenses/MIT The MIT License (MIT) - * @link https://github.com/travello-gmbh/amazon-alexa-skill-library - * @link https://www.travello.audio/ - * - */ - namespace TravelloAlexaLibraryTest\Response\Directives\Display; use PHPUnit\Framework\TestCase; diff --git a/test/Response/Directives/Hint/HintTest.php b/test/Response/Directives/Hint/HintTest.php new file mode 100644 index 0000000..ede2d61 --- /dev/null +++ b/test/Response/Directives/Hint/HintTest.php @@ -0,0 +1,41 @@ + + * @license http://opensource.org/licenses/MIT The MIT License (MIT) + * @link https://github.com/travello-gmbh/amazon-alexa-skill-library + * @link https://www.travello.audio/ + * + */ + +namespace TravelloAlexaLibraryTest\Response\Directives\Hint; + +use PHPUnit\Framework\TestCase; +use TravelloAlexaLibrary\Response\Directives\Hint\Hint; + +/** + * Class HintTest + * + * @package TravelloAlexaLibraryTest\Response\Directives\Hint; + */ +class HintTest extends TestCase +{ + /** + * + */ + public function testWithMandatoryOnly() + { + $hint = new Hint('this is a text'); + + $expected = [ + 'type' => 'Hint', + 'hint' => [ + 'type' => 'PlainText', + 'text' => 'this is a text', + ], + ]; + + $this->assertEquals($expected, $hint->toArray()); + } +}