Skip to content

Commit

Permalink
Merge pull request #10 from travello-gmbh/9--library-updates
Browse files Browse the repository at this point in the history
updates for new 2.4.0 libraries
  • Loading branch information
Ralf Eggert committed Nov 26, 2017
2 parents e7675ff + 19c3419 commit 4750703
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
12 changes: 5 additions & 7 deletions module/Hello/src/Intent/HelloIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@ class HelloIntent extends AbstractIntent
const NAME = 'HelloIntent';

/**
* @param string $smallImageUrl
* @param string $largeImageUrl
*
* @return AlexaResponse
*/
public function handle(
string $smallImageUrl,
string $largeImageUrl
): AlexaResponse {
public function handle(): AlexaResponse
{
$sessionContainer = $this->getAlexaResponse()->getSessionContainer();

$count = $sessionContainer->getAttribute('count') + 1;

$sessionContainer->setAttribute('count', $count);

$smallImageUrl = $this->getSkillConfiguration()->getSmallImageUrl();
$largeImageUrl = $this->getSkillConfiguration()->getLargeImageUrl();

$title = $this->getTextHelper()->getHelloTitle();
$message = $this->getTextHelper()->getHelloMessage() . ' (' . $count . ')';

Expand Down
24 changes: 14 additions & 10 deletions module/Hello/test/Intent/HelloIntentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Hello\Intent\HelloIntent;
use PHPUnit\Framework\TestCase;
use TravelloAlexaLibrary\Configuration\SkillConfiguration;
use TravelloAlexaLibrary\Intent\AbstractIntent;
use TravelloAlexaLibrary\Intent\IntentInterface;
use TravelloAlexaLibrary\Request\RequestType\RequestTypeFactory;
Expand Down Expand Up @@ -50,11 +51,12 @@ public function testInstantiation()
],
];

$alexaRequest = RequestTypeFactory::createFromData(json_encode($data));
$alexaResponse = new AlexaResponse();
$textHelper = new TextHelper();
$alexaRequest = RequestTypeFactory::createFromData(json_encode($data));
$alexaResponse = new AlexaResponse();
$textHelper = new TextHelper();
$skillConfiguration = new SkillConfiguration();

$helloIntent = new HelloIntent($alexaRequest, $alexaResponse, $textHelper);
$helloIntent = new HelloIntent($alexaRequest, $alexaResponse, $textHelper, $skillConfiguration);

$this->assertTrue($helloIntent instanceof AbstractIntent);
$this->assertTrue($helloIntent instanceof IntentInterface);
Expand Down Expand Up @@ -94,16 +96,18 @@ public function testHandle()

$sessionContainer = new SessionContainer(['foo' => 'bar', 'count' => 17,]);

$alexaRequest = RequestTypeFactory::createFromData(json_encode($data));
$textHelper = new TextHelper();
$alexaRequest = RequestTypeFactory::createFromData(json_encode($data));
$textHelper = new TextHelper();

$alexaResponse = new AlexaResponse();
$alexaResponse->setSessionContainer($sessionContainer);

$smallImageUrl = 'https://image.server/small.png';
$largeImageUrl = 'https://image.server/large.png';
$skillConfiguration = new SkillConfiguration();
$skillConfiguration->setSmallImageUrl('https://image.server/small.png');
$skillConfiguration->setLargeImageUrl('https://image.server/large.png');

$helloIntent = new HelloIntent($alexaRequest, $alexaResponse, $textHelper);
$helloIntent->handle($smallImageUrl, $largeImageUrl);
$helloIntent = new HelloIntent($alexaRequest, $alexaResponse, $textHelper, $skillConfiguration);
$helloIntent->handle();

$expected = [
'version' => '1.0',
Expand Down

0 comments on commit 4750703

Please sign in to comment.