-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
281 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
all: install test | ||
|
||
install: | ||
docker-compose up -d | ||
|
||
docker exec -ti sandstone sh -c "composer install" | ||
|
||
update: | ||
docker-compose up -d | ||
|
||
docker exec -ti sandstone sh -c "composer update" | ||
|
||
test: | ||
docker-compose up -d | ||
|
||
docker exec -ti sandstone sh -c "vendor/bin/phpunit -c ." | ||
docker exec -ti sandstone sh -c "vendor/bin/phpcs src --standard=phpcs.xml" | ||
|
||
logs: | ||
docker-compose logs -ft | ||
|
||
bash: | ||
docker exec -ti sandstone bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
version: '2' | ||
|
||
services: | ||
php-fpm: | ||
container_name: sandstone | ||
build: docker/php-fpm | ||
volumes: | ||
- .:/var/www/html/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
version: '2' | ||
|
||
services: | ||
php-fpm: | ||
build: docker/php-fpm-rpi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
FROM alcalyn/rpi-php7-fpm-zmq | ||
|
||
# install PHP extensions & PECL modules with dependencies | ||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
bzip2 git wget \ | ||
zlib1g-dev \ | ||
libicu-dev \ | ||
&& apt-get clean \ | ||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* | ||
|
||
RUN docker-php-ext-install intl \ | ||
&& docker-php-ext-install pdo_mysql mysqli \ | ||
&& docker-php-ext-install zip | ||
|
||
# install composer | ||
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \ | ||
&& php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \ | ||
&& php composer-setup.php --filename=composer \ | ||
&& php -r "unlink('composer-setup.php');" \ | ||
&& mv composer /usr/local/bin/composer | ||
|
||
WORKDIR "/var/www/html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM phpdockerio/php71-fpm | ||
|
||
RUN apt-get update \ | ||
&& apt-get -y --no-install-recommends install php7.1-mysql php-zmq \ | ||
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/* | ||
|
||
WORKDIR "/var/www/html" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Eole\Sandstone\Tests\Integration\App; | ||
|
||
use Symfony\Component\Console\Application as ConsoleApplication; | ||
use Eole\Sandstone\Tests\Integration\App\App as SilexApplication; | ||
|
||
class Console extends ConsoleApplication | ||
{ | ||
/** | ||
* @var SilexApplication | ||
*/ | ||
private $silexApplication; | ||
|
||
/** | ||
* Console application constructor. | ||
* | ||
* @param SilexApplication $silexApplication | ||
*/ | ||
public function __construct(SilexApplication $silexApplication) | ||
{ | ||
parent::__construct('My Sandstone application'); | ||
|
||
$this->silexApplication = $silexApplication; | ||
$this->silexApplication->boot(); | ||
|
||
$this->addCommands([ | ||
new PushMessageCommand($this->silexApplication['dispatcher']), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Eole\Sandstone\Tests\Integration\App; | ||
|
||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Eole\Sandstone\Tests\Integration\App\ArticleCreatedEvent; | ||
|
||
class PushMessageCommand extends Command | ||
{ | ||
/** | ||
* @var EventDispatcherInterface | ||
*/ | ||
private $dispatcher; | ||
|
||
/** | ||
* @param EventDispatcherInterface $dispatcher | ||
*/ | ||
public function __construct(EventDispatcherInterface $dispatcher) | ||
{ | ||
parent::__construct('sandstone:test:push'); | ||
|
||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
/** | ||
* {@InheritDoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
|
||
$this | ||
->setDescription('Dispatch an event which should push an event.') | ||
; | ||
} | ||
|
||
/** | ||
* {@InheritDoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$id = 42; | ||
$title = 'Unicorns spotted in Alaska'; | ||
$url = 'http://unicorn.com/articles/unicorns-spotted-alaska'; | ||
|
||
$event = new ArticleCreatedEvent($id, $title, $url); | ||
|
||
$this->dispatcher->dispatch('article.created', $event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Eole\Sandstone\Tests\Integration; | ||
|
||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Eole\Sandstone\Push\PushServerInterface; | ||
use Eole\Sandstone\Tests\Integration\App\ArticleCreatedEvent; | ||
|
||
class PushOnConsoleCommandTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testDispatchingEventFromConsoleCommandTriggersPushEvent() | ||
{ | ||
$pushServerMock = $this->getMockForAbstractClass(PushServerInterface::class); | ||
|
||
$app = new App\AppRestApi([ | ||
'debug' => true, | ||
'sandstone.push' => function () use ($pushServerMock) { | ||
return $pushServerMock; | ||
}, | ||
]); | ||
|
||
$pushServerMock | ||
->expects($this->once()) | ||
->method('send') | ||
->with($this->callback(function ($message) { | ||
$decodedMessage = unserialize($message); | ||
$serializedEvent = '{"propagation_stopped":false,"id":42,"title":"Unicorns spotted in Alaska","url":"http:\/\/unicorn.com\/articles\/unicorns-spotted-alaska"}'; | ||
|
||
return | ||
ArticleCreatedEvent::ARTICLE_CREATED_EVENT === $decodedMessage['name'] && | ||
ArticleCreatedEvent::class === $decodedMessage['class'] && | ||
$serializedEvent === $decodedMessage['event'] | ||
; | ||
})) | ||
; | ||
|
||
$console = new App\Console($app); | ||
$input = new ArrayInput(['sandstone:test:push']); | ||
$console->find('sandstone:test:push')->run($input, new NullOutput()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/Unit/EventForwarderTest.php → tests/Unit/Push/EventForwarderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Eole\Sandstone\Tests\Unit\Websocket; | ||
|
||
use Eole\Sandstone\Serializer\ServiceProvider as SerializerServiceProvider; | ||
use Eole\Sandstone\Websocket\Routing\TopicRouter; | ||
use Eole\Sandstone\Websocket\Application as WebsocketApplication; | ||
use Eole\Sandstone\Application; | ||
|
||
class ApplicationTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testLoadTopicThrowExceptionWhenImplementingTheWrongEventDispatcherInterface() | ||
{ | ||
$app = new Application(); | ||
$websocketAppClass = new \ReflectionClass(WebsocketApplication::class); | ||
$method = $websocketAppClass->getMethod('loadTopic'); | ||
$method->setAccessible(true); | ||
$websocketApp = $websocketAppClass->newInstance($app); | ||
|
||
$app->register(new SerializerServiceProvider()); | ||
|
||
$app['sandstone.websocket.router'] = function () { | ||
$wrongTopic = new WrongTopic('my-topic'); | ||
$topicRouterMock = $this->getMockBuilder(TopicRouter::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$topicRouterMock | ||
->method('loadTopic') | ||
->willReturn($wrongTopic) | ||
; | ||
|
||
return $topicRouterMock; | ||
}; | ||
|
||
$this->setExpectedExceptionRegExp( | ||
\LogicException::class, | ||
'/WrongTopic seems to implements the wrong EventSubscriberInterface/' | ||
); | ||
|
||
$method->invokeArgs($websocketApp, ['my-topic']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Eole\Sandstone\Tests\Unit\Websocket; | ||
|
||
use JMS\Serializer\EventDispatcher\EventSubscriberInterface; | ||
use Eole\Sandstone\Websocket\Topic; | ||
|
||
class WrongTopic extends Topic implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents() | ||
{ | ||
return []; | ||
} | ||
} |