Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Command/NodeJsServerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$process->setIdleTimeout(false);
$process->setTimeout(null);
$process->run();

return 0;
}
}
10 changes: 2 additions & 8 deletions DependencyInjection/SocketIoConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\HttpKernel\Kernel;

/**
* Class SocketIoConfiguration.
Expand All @@ -23,13 +22,8 @@ class SocketIoConfiguration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
if (Kernel::VERSION_ID >= 40300) {
$treeBuilder = new TreeBuilder('sfcod_socketio');
$rootNode = $treeBuilder->getRootNode();
} else {
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sfcod_socketio');
}
$treeBuilder = new TreeBuilder('sfcod_socketio');
$rootNode = $treeBuilder->getRootNode();

$this->addNamespaces($rootNode);

Expand Down
9 changes: 8 additions & 1 deletion Service/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ private function inWork()
*/
private function push(string $handle, array $data): \Symfony\Component\Process\Process
{
$cmd = sprintf('php %s socket-io:process --handler=%s --data=%s --env=%s', $this->scriptName, escapeshellarg($handle), escapeshellarg(serialize($data)), getenv('APP_ENV'));
$cmd = [
'php',
$this->scriptName,
'socket-io:process',
'--handler=' . escapeshellarg($handle),
'--data=' . escapeshellarg(serialize($data)),
'--env=prod',
];

$process = new \Symfony\Component\Process\Process($cmd, $this->binPath);
$process->setTimeout(10);
Expand Down
12 changes: 2 additions & 10 deletions Tests/Data/LoadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,18 @@
use Psr\Log\LoggerInterface;
use SfCod\SocketIoBundle\DependencyInjection\SocketIoExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Dotenv\Exception\PathException;

trait LoadTrait
{
protected $container;

protected function configure()
{
$dotenv = new Dotenv();
try {
$dotenv->load(__DIR__ . '/../../.env');
} catch (PathException $e) {
// Nothing
}

$extension = new SocketIoExtension();
$container = new ContainerBuilder();
$container->setParameter('kernel.project_dir', getenv('KERNEL_PROJECT_DIR'));
$container->setParameter('kernel.project_dir', '');
$container->setParameter('kernel.root_dir', realpath(__DIR__ . '/../../../../SfCod/'));
$container->setParameter('kernel.bundles', []);
$container->set(LoggerInterface::class, new Logger('test'));

$extension->load([
Expand Down
59 changes: 35 additions & 24 deletions Tests/Service/BroadcastTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

namespace SfCod\SocketIoBundle\Tests;
namespace SfCod\SocketIoBundle\Tests\Service;

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use SfCod\SocketIoBundle\Events\EventInterface;
use SfCod\SocketIoBundle\Events\EventPublisherInterface;
use SfCod\SocketIoBundle\Events\EventSubscriberInterface;
use SfCod\SocketIoBundle\Service\Broadcast;
use SfCod\SocketIoBundle\Service\EventManager;
use SfCod\SocketIoBundle\Service\RedisDriver;
use SfCod\SocketIoBundle\Tests\Data\LoadTrait;
use SfCod\SocketIoBundle\Tests\Data\MarkAsReadSubscriber;
use Symfony\Component\Process\Process;
Expand All @@ -26,15 +29,23 @@ class BroadcastTest extends TestCase
* @var Broadcast
*/
private $broadcast;
private $eventManagerMock;
private $processMock;

/**
* Set up test.
*/
protected function setUp()
{
$this->configure();
$redisDriverMock = $this->createMock(RedisDriver::class);
$eventManagerMock = $this->createMock(EventManager::class);
$this->eventManagerMock = $eventManagerMock;
$loggerMock = $this->createMock(LoggerInterface::class);
$processMock = $this->createMock(\SfCod\SocketIoBundle\Service\Process::class);
$this->processMock = $processMock;

$this->broadcast = $this->container->get(Broadcast::class);
$this->broadcast = new Broadcast($redisDriverMock, $eventManagerMock, $loggerMock, $processMock);
}

/**
Expand All @@ -44,9 +55,10 @@ protected function setUp()
*/
public function testOn()
{
$this->processMock->method('run')->willReturn(new Process([]));
$result = $this->broadcast->on(MarkAsReadSubscriber::name(), []);

$this->assertInstanceOf(Process::class, $result);
self::assertInstanceOf(Process::class, $result);
}

/**
Expand All @@ -58,35 +70,34 @@ public function testProcess()

$handler = $this->getMockBuilder([EventInterface::class, EventSubscriberInterface::class])->getMock();
$handler
->expects($this->once())
->expects(self::once())
->method('setPayload')
->with($data);
$handler
->expects($this->once())
->expects(self::once())
->method('handle');

$this->container->set(sprintf('socketio.%s', get_class($handler)), $handler);
$this->eventManagerMock->method('resolve')->willReturn($handler);
$this->broadcast->process(get_class($handler), $data);
}

// /**
// */
// public function testEmit()
// {
// $data = range(1, 10);
//
// $handler = $this->getMockBuilder([EventInterface::class, EventPublisherInterface::class])->getMock();
// $handler
// ->expects($this->once())
// ->method('setPayload')
// ->with($data);
// $handler
// ->expects($this->once())
// ->method('fire');
//
// $this->container->set(sprintf('socketio.%s', get_class($handler)), $handler);
// $this->broadcast->emit(get_class($handler), $data);
// }
/**
*/
public function testEmit()
{
$data = range(1, 10);

$handler = $this->getMockBuilder([EventInterface::class, EventPublisherInterface::class])->getMock();
$handler
->expects(self::once())
->method('setPayload')
->with($data);
$handler
->expects(self::once())
->method('fire');
$this->eventManagerMock->method('resolve')->willReturn($handler);
$this->broadcast->emit(get_class($handler), $data);
}

// /**
// */
Expand Down
2 changes: 1 addition & 1 deletion Tests/Service/RedisDriverTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SfCod\SocketIoBundle\Tests;
namespace SfCod\SocketIoBundle\Tests\Service;

use PHPUnit\Framework\TestCase;
use Predis\Client;
Expand Down
21 changes: 15 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,30 @@
}
],
"require": {
"php": "^7.0",
"symfony/framework-bundle": "^4.0|^5.0",
"php": "^7.1",
"symfony/framework-bundle": "^4.4 || ^5.0",
"predis/predis": "^1.1",
"symfony/monolog-bundle": "^3.1",
"ezyang/htmlpurifier": "^4.0",
"symfony/dotenv": "^4.0|^5.0",
"symfony/process": "^4.0|^5.0"
"symfony/dotenv": "^4.4 || ^5.0",
"symfony/process": "^4.4 || ^5.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^4.0|^5.0",
"friendsofphp/php-cs-fixer": "^2.8"
"symfony/phpunit-bridge": "^4.4 || ^5.0",
"friendsofphp/php-cs-fixer": "^2.8",
"phpunit/phpunit": "^7.5"
},
"autoload": {
"psr-4": {
"SfCod\\SocketIoBundle\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"autoload-dev": {
"psr-4": {
"SfCod\\QueueBundle\\Tests\\": "/Tests/"
}
}
}
11 changes: 10 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand All @@ -17,6 +16,16 @@
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>

<php>
<ini name="error_reporting" value="-1" />
</php>
Expand Down