Skip to content

Commit

Permalink
Merge pull request #8 from travello-gmbh/7-integrate-session-container
Browse files Browse the repository at this point in the history
Updates for libararies
  • Loading branch information
Ralf Eggert committed Oct 8, 2017
2 parents a07b94f + 1476452 commit 2211ff6
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 364 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"require": {
"php": "^7.0",
"roave/security-advisories": "dev-master",
"travello-gmbh/amazon-alexa-skill-zf": "^2.0.0",
"travello-gmbh/amazon-alexa-skill-zf": "^2.1.0",
"zendframework/zend-component-installer": "^1.0 || ^0.7.0",
"zendframework/zend-config-aggregator": "^0.2.0",
"zendframework/zend-expressive": "^2.0",
Expand Down
1 change: 1 addition & 0 deletions module/Application/src/Config/PipelineDelegatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;
use Zend\Stratigility\Middleware\ErrorHandler;
use Zend\Stratigility\Middleware\OriginalMessages;
use Zend\Stratigility\MiddlewareInterface;

/**
* Class PipelineDelegatorFactory
Expand Down
106 changes: 106 additions & 0 deletions module/Application/test/Config/PipelineDelegatorFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* PHP skeleton application for Amazon Alexa Skills
*
* @author Ralf Eggert <ralf@travello.audio>
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://github.com/travello-gmbh/amazon-alexa-skill-skeleton
* @link https://www.travello.audio/
*/

namespace ApplicationTest\Config;

use Application\Config\PipelineDelegatorFactory;
use Interop\Container\ContainerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use TravelloAlexaZf\Middleware\CheckApplicationMiddleware;
use TravelloAlexaZf\Middleware\ConfigureSkillMiddleware;
use TravelloAlexaZf\Middleware\LogAlexaRequestMiddleware;
use TravelloAlexaZf\Middleware\SetLocaleMiddleware;
use TravelloAlexaZf\Middleware\ValidateCertificateMiddleware;
use Zend\Expressive\Application;
use Zend\Expressive\Middleware\ImplicitHeadMiddleware;
use Zend\Expressive\Middleware\ImplicitOptionsMiddleware;
use Zend\Expressive\Middleware\NotFoundHandler;
use Zend\Stratigility\Middleware\ErrorHandler;
use Zend\Stratigility\Middleware\OriginalMessages;

/**
* Class PipelineDelegatorFactoryTest
*
* @package ApplicationTest\Config
*/
class PipelineDelegatorFactoryTest extends TestCase
{
/**
*
*/
public function testFactory()
{
/** @var ContainerInterface|ObjectProphecy $container */
$container = $this->prophesize(ContainerInterface::class);

/** @var Application|ObjectProphecy $application */
$application = $this->prophesize(Application::class);

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(OriginalMessages::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(ErrorHandler::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipeRoutingMiddleware();
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(ConfigureSkillMiddleware::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(LogAlexaRequestMiddleware::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(CheckApplicationMiddleware::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(ValidateCertificateMiddleware::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(SetLocaleMiddleware::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(ImplicitHeadMiddleware::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(ImplicitOptionsMiddleware::class);
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipeDispatchMiddleware();
$pipeMethod->shouldBeCalled();

/** @var MethodProphecy $pipeMethod */
$pipeMethod = $application->pipe(NotFoundHandler::class);
$pipeMethod->shouldBeCalled();

$callable = function () use ($application) {
return $application->reveal();
};

$factory = new PipelineDelegatorFactory();

$applicationReturn = $factory($container->reveal(), Application::class, $callable);

$this->assertEquals($applicationReturn, $application->reveal());
}
}
62 changes: 62 additions & 0 deletions module/Application/test/Config/RouterDelegatorFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* PHP skeleton application for Amazon Alexa Skills
*
* @author Ralf Eggert <ralf@travello.audio>
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://github.com/travello-gmbh/amazon-alexa-skill-skeleton
* @link https://www.travello.audio/
*/

/**
* PHP skeleton application for Amazon Alexa Skills
*
* @author Ralf Eggert <ralf@travello.audio>
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @link https://github.com/travello-gmbh/amazon-alexa-skill-skeleton
* @link https://www.travello.audio/
*/

namespace ApplicationTest\Config;

use Application\Action\HomePageAction;
use Application\Config\RouterDelegatorFactory;
use Interop\Container\ContainerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Zend\Expressive\Application;

/**
* Class RouterDelegatorFactoryTest
*
* @package ApplicationTest\Config
*/
class RouterDelegatorFactoryTest extends TestCase
{
/**
*
*/
public function testFactory()
{
/** @var ContainerInterface|ObjectProphecy $container */
$container = $this->prophesize(ContainerInterface::class);

/** @var Application|ObjectProphecy $application */
$application = $this->prophesize(Application::class);

/** @var MethodProphecy $getMethod */
$getMethod = $application->route('/', HomePageAction::class, ['GET', 'POST'], 'home');
$getMethod->shouldBeCalled();

$callable = function () use ($application) {
return $application->reveal();
};

$factory = new RouterDelegatorFactory();

$applicationReturn = $factory($container->reveal(), Application::class, $callable);

$this->assertEquals($applicationReturn, $application->reveal());
}
}
51 changes: 0 additions & 51 deletions module/Hello/src/Application/HelloApplication.php

This file was deleted.

4 changes: 2 additions & 2 deletions module/Hello/src/Config/RouterDelegatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Hello\Config;

use Hello\Application\HelloApplication;
use Hello\ConfigProvider;
use Interop\Container\ContainerInterface;
use TravelloAlexaZf\Action\HtmlPageAction;
use TravelloAlexaZf\Action\SkillAction;
Expand Down Expand Up @@ -38,7 +38,7 @@ public function __invoke(ContainerInterface $container, $name, callable $callbac
$application = $callback();

$application->post('/hello', SkillAction::class, 'hello')
->setOptions(['defaults' => ['skillName' => HelloApplication::NAME]]);
->setOptions(['defaults' => ['skillName' => ConfigProvider::NAME]]);

$application->get('/hello/privacy', HtmlPageAction::class, 'hello-privacy')
->setOptions(['defaults' => ['template' => 'hello::privacy']]);
Expand Down
16 changes: 9 additions & 7 deletions module/Hello/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

namespace Hello;

use Hello\Application\HelloApplication;
use Hello\Config\RouterDelegatorFactory;
use Hello\Intent\HelloIntent;
use TravelloAlexaZf\Application\AlexaApplicationFactory;
use TravelloAlexaLibrary\Application\AlexaApplication;
use TravelloAlexaZf\Intent\AbstractIntentFactory;
use Zend\Expressive\Application;

Expand All @@ -24,6 +23,9 @@
*/
class ConfigProvider
{
/** Name of skill for configuration */
const NAME = 'hello-skill';

/**
* @return array
*/
Expand All @@ -47,9 +49,6 @@ public function getDependencies(): array
RouterDelegatorFactory::class,
],
],
'factories' => [
HelloApplication::class => AlexaApplicationFactory::class,
],
];
}

Expand All @@ -71,9 +70,12 @@ public function getTemplates(): array
public function getSkills(): array
{
return [
HelloApplication::NAME => [
self::NAME => [
'applicationId' => 'amzn1.ask.skill.place-your-skill-id-here',
'applicationClass' => HelloApplication::class,
'applicationClass' => AlexaApplication::class,
'sessionDefaults' => [
'count' => 0,
],
'smallImageUrl' => 'https://www.travello.audio/cards/hello-480x480.png',
'largeImageUrl' => 'https://www.travello.audio/cards/hello-800x800.png',
'intents' => [
Expand Down
8 changes: 7 additions & 1 deletion module/Hello/src/Intent/HelloIntent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ public function handle(
string $smallImageUrl,
string $largeImageUrl
): AlexaResponse {
$sessionContainer = $this->getAlexaResponse()->getSessionContainer();

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

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

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

$this->getAlexaResponse()->setOutputSpeech(
new SSML($message)
Expand Down
Loading

0 comments on commit 2211ff6

Please sign in to comment.