Merge pull request #1322 from bburnichon/feature/task-manager-start

task manager start
This commit is contained in:
Benoît Burnichon
2015-03-26 09:52:10 +01:00
16 changed files with 558 additions and 1202 deletions

View File

@@ -1,9 +1,9 @@
{ {
"name" : "phraseanet/phraseanet", "name": "phraseanet/phraseanet",
"description" : "Phraseanet", "description": "Phraseanet",
"license" : "GPL-3.0", "license": "GPL-3.0",
"config": { "config": {
"bin-dir" : "bin/" "bin-dir": "bin/"
}, },
"repositories": [ "repositories": [
{ {
@@ -28,75 +28,69 @@
} }
], ],
"require": { "require": {
"php" : ">=5.5", "php": ">=5.5",
"alchemy/oauth2php" : "1.0.0",
"alchemy/phlickr" : "0.2.9", "alchemy-fr/tcpdf-clone": "~6.0",
"alchemy/task-manager" : "2.0.x-dev@dev", "alchemy/geonames-api-consumer": "~0.1.0",
"alchemy/zippy" : "0.2.x-dev@dev", "alchemy/google-plus-api-client": "~0.6.2",
"dailymotion/sdk" : "~1.5", "alchemy/oauth2php": "1.0.0",
"data-uri/data-uri" : "~0.1.0", "alchemy/phlickr": "0.2.9",
"doctrine/orm" : "~2.4.0", "alchemy/task-manager": "2.0.x-dev@dev",
"doctrine/dbal" : "~2.4.0", "alchemy/zippy": "0.2.x-dev@dev",
"elasticsearch/elasticsearch" : "~1.0", "dailymotion/sdk": "~1.5",
"facebook/php-sdk" : "~3.0", "data-uri/data-uri": "~0.1.0",
"gedmo/doctrine-extensions" : "~2.3.0", "dflydev/doctrine-orm-service-provider": "~1.0",
"alchemy/google-plus-api-client" : "~0.6.2", "doctrine/dbal": "~2.4.0",
"alchemy/geonames-api-consumer" : "~0.1.0", "doctrine/migrations": "1.0.x-dev@dev",
"goodby/csv" : "dev-master", "doctrine/orm": "~2.4.0",
"guzzle/guzzle" : "~3.0", "elasticsearch/elasticsearch": "~1.0",
"imagine/imagine" : "dev-alchemy-0.6.2 as 0.6.2", "facebook/php-sdk": "~3.0",
"igorw/get-in" : "~1.0", "gedmo/doctrine-extensions": "~2.3.0",
"ircmaxell/random-lib" : "~1.0", "goodby/csv": "dev-master",
"jms/serializer" : "~0.10", "guzzle/guzzle": "~3.0",
"jms/translation-bundle" : "dev-master as 1.1.0",
"justinrainbow/json-schema" : "~1.3",
"mediavorus/mediavorus" : "~0.4.0",
"media-alchemyst/media-alchemyst" : "~0.4",
"monolog/monolog" : "~1.3",
"mrclay/minify" : "~2.1.6",
"neutron/process-manager" : "2.0.x-dev@dev",
"neutron/silex-imagine-provider" : "~0.1.0",
"neutron/silex-filesystem-provider": "~1.0",
"neutron/sphinxsearch-api" : "~2.0.6",
"neutron/recaptcha" : "~0.1.0",
"neutron/temporary-filesystem" : "~2.1",
"php-ffmpeg/php-ffmpeg" : "~0.5.0",
"php-xpdf/php-xpdf" : "~0.2.1",
"phpexiftool/phpexiftool" : "dev-0.4.1-mwg-metadata-copy as 0.4.1",
"rhumsaa/uuid" : "~2.7",
"silex/silex" : "1.1.x-dev@dev",
"silex/web-profiler" : "~1.0.0@dev",
"sorien/silex-dbal-profiler" : "~1.0.0",
"swiftmailer/swiftmailer" : "~5.3.0",
"symfony/symfony" : "~2.4",
"alchemy-fr/tcpdf-clone" : "~6.0",
"themattharris/tmhoauth" : "~0.7",
"twig/twig" : "~1.14, >=1.14.2",
"twig/extensions" : "~1.0",
"vierbergenlars/php-semver" : "~2.1",
"zend/gdata" : "~1.12.1",
"doctrine/migrations" : "1.0.x-dev@dev",
"willdurand/negotiation" : "~1.3",
"hoa/compiler": "2.14.09.23", "hoa/compiler": "2.14.09.23",
"dflydev/doctrine-orm-service-provider" : "~1.0", "igorw/get-in": "~1.0",
"roave/security-advisories": "dev-master" "imagine/imagine": "dev-alchemy-0.6.2 as 0.6.2",
"ircmaxell/random-lib": "~1.0",
"jms/serializer": "~0.10",
"jms/translation-bundle": "dev-master as 1.1.0",
"justinrainbow/json-schema": "~1.3",
"media-alchemyst/media-alchemyst": "~0.4",
"mediavorus/mediavorus": "~0.4.0",
"monolog/monolog": "~1.3",
"mrclay/minify": "~2.1.6",
"neutron/process-manager": "2.0.x-dev@dev",
"neutron/recaptcha": "~0.1.0",
"neutron/silex-filesystem-provider": "~1.0",
"neutron/silex-imagine-provider": "~0.1.0",
"neutron/sphinxsearch-api": "~2.0.6",
"neutron/temporary-filesystem": "~2.1",
"php-ffmpeg/php-ffmpeg": "~0.5.0",
"php-xpdf/php-xpdf": "~0.2.1",
"phpexiftool/phpexiftool": "dev-0.4.1-mwg-metadata-copy as 0.4.1",
"rhumsaa/uuid": "~2.7",
"roave/security-advisories": "dev-master",
"silex/silex": "~1.2",
"silex/web-profiler": "~1.0",
"sorien/silex-dbal-profiler": "~1.0.0",
"swiftmailer/swiftmailer": "~5.3.0",
"symfony/symfony": "~2.4",
"themattharris/tmhoauth": "~0.7",
"twig/extensions": "~1.0",
"twig/twig": "~1.14, >=1.14.2",
"vierbergenlars/php-semver": "~2.1",
"willdurand/negotiation": "~1.3",
"zend/gdata": "~1.12.1"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit" : "~4.5", "hoa/console": "2.14.09.23",
"behat/behat" : "2.5.x-dev@dev",
"behat/gherkin" : "2.3.x-dev@dev",
"behat/mink" : "~1.4",
"behat/mink-extension" : "~1.0",
"behat/mink-goutte-driver" : "~1.0",
"behat/mink-selenium2-driver" : "~1.0",
"fabpot/goutte" : "~1.0",
"hoa/dispatcher": "0.14.09.23", "hoa/dispatcher": "0.14.09.23",
"hoa/console": "2.14.09.23" "phpunit/phpunit": "~4.5"
}, },
"autoload": { "autoload": {
"psr-0": { "psr-0": {
"" : "lib/classes", "Alchemy\\": "lib",
"Alchemy" : "lib" "": "lib/classes"
} }
}, },
"include-path": ["vendor/zend/gdata/library"], "include-path": ["vendor/zend/gdata/library"],

1296
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Command\Task; namespace Alchemy\Phrasea\Command\Task;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\TaskManager\TaskManagerStatus; use Alchemy\Phrasea\TaskManager\TaskManagerStatus;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;

View File

@@ -12,6 +12,7 @@
namespace Alchemy\Phrasea\Command\Task; namespace Alchemy\Phrasea\Command\Task;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\TaskManager\TaskManagerStatus; use Alchemy\Phrasea\TaskManager\TaskManagerStatus;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;

View File

@@ -11,11 +11,10 @@
namespace Alchemy\Phrasea\Command\Task; namespace Alchemy\Phrasea\Command\Task;
use Alchemy\TaskManager\TaskManager;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\TaskManager\Event\TaskManagerSubscriber\LockFileSubscriber; use Alchemy\TaskManager\Event\TaskManagerSubscriber\LockFileSubscriber;
use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;

View File

@@ -12,10 +12,11 @@
namespace Alchemy\Phrasea\Command\Task; namespace Alchemy\Phrasea\Command\Task;
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\Task;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class SchedulerState extends Command class SchedulerState extends Command
{ {

View File

@@ -12,13 +12,16 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Form\TaskForm; use Alchemy\Phrasea\Form\TaskForm;
use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\Task;
use Alchemy\Phrasea\Exception\RuntimeException; use Alchemy\Phrasea\TaskManager\LiveInformation;
use Alchemy\Phrasea\Exception\XMLParseErrorException;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Process\Process;
class TaskManager implements ControllerProviderInterface class TaskManager implements ControllerProviderInterface
{ {
@@ -126,6 +129,25 @@ class TaskManager implements ControllerProviderInterface
{ {
$app['task-manager.status']->start(); $app['task-manager.status']->start();
$cmdLine = sprintf(
'%s %s %s',
$app['conf']->get(['main', 'binaries', 'php_binary']),
realpath(__DIR__ . '/../../../../../bin/console'),
'task-manager:scheduler:run'
);
/** @var EventDispatcherInterface $dispatcher */
$dispatcher = $app['dispatcher'];
$dispatcher->addListener(KernelEvents::TERMINATE, function () use ($cmdLine) {
$process = new Process($cmdLine);
$process->setTimeout(0);
$process->disableOutput();
set_time_limit(0);
ignore_user_abort(true);
$process->run();
}, -1000);
return $app->redirectPath('admin_tasks_list'); return $app->redirectPath('admin_tasks_list');
} }
@@ -133,6 +155,17 @@ class TaskManager implements ControllerProviderInterface
{ {
$app['task-manager.status']->stop(); $app['task-manager.status']->stop();
/** @var LiveInformation $info */
$info = $app['task-manager.live-information'];
$data = $info->getManager();
if (null !== $pid = $data['process-id']) {
if (substr(php_uname(), 0, 7) == "Windows"){
exec(sprintf('TaskKill /PID %d', $pid));
} else {
exec(sprintf('kill %d', $pid));
}
}
return $app->redirectPath('admin_tasks_list'); return $app->redirectPath('admin_tasks_list');
} }

View File

@@ -14,6 +14,9 @@ namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Configuration\SessionHandlerFactory; use Alchemy\Phrasea\Core\Configuration\SessionHandlerFactory;
use Silex\Application; use Silex\Application;
use Silex\ServiceProviderInterface; use Silex\ServiceProviderInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class SessionHandlerServiceProvider implements ServiceProviderInterface class SessionHandlerServiceProvider implements ServiceProviderInterface
{ {
@@ -27,10 +30,24 @@ class SessionHandlerServiceProvider implements ServiceProviderInterface
}); });
} }
public function onKernelResponse(FilterResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
$session = $event->getRequest()->getSession();
if ($session && $session->isStarted()) {
$session->save();
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function boot(Application $app) public function boot(Application $app)
{ {
// Priority should be lower than test session mock listener
$app['dispatcher']->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'), -129);
} }
} }

View File

@@ -25,7 +25,7 @@ class NginxMode extends AbstractServerMode implements ModeInterface
$xAccelMapping = []; $xAccelMapping = [];
foreach ($this->mapping as $entry) { foreach ($this->mapping as $entry) {
$xAccelMapping[] = sprintf('%s=%s', $entry['mount-point'], $entry['directory']); $xAccelMapping[] = sprintf('%s=%s', $entry['directory'], $entry['mount-point']);
} }
if (count($xAccelMapping) > 0 ) { if (count($xAccelMapping) > 0 ) {

View File

@@ -23,10 +23,12 @@
<filter> <filter>
<blacklist> <blacklist>
<directory>lib/vendor</directory>
<directory>tests</directory> <directory>tests</directory>
<directory>vendor</directory> <directory>vendor</directory>
</blacklist> </blacklist>
<whitelist>
<directory suffix=".php">lib</directory>
</whitelist>
</filter> </filter>
<!--<listeners>--> <!--<listeners>-->

View File

@@ -4,6 +4,8 @@ namespace Alchemy\Tests\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\Task;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class TaskManagerTest extends \PhraseanetAuthenticatedWebTestCase class TaskManagerTest extends \PhraseanetAuthenticatedWebTestCase
{ {
@@ -63,6 +65,11 @@ class TaskManagerTest extends \PhraseanetAuthenticatedWebTestCase
->getMock(); ->getMock();
self::$DI['app']['task-manager.status']->expects($this->once()) self::$DI['app']['task-manager.status']->expects($this->once())
->method('start'); ->method('start');
// Prevent actual start of process scheduler
self::$DI['app']['dispatcher']->addListener(KernelEvents::TERMINATE, function (PostResponseEvent $event) {
$event->stopPropagation();
}, -999);
self::$DI['client']->request('POST', '/admin/task-manager/scheduler/start'); self::$DI['client']->request('POST', '/admin/task-manager/scheduler/start');
$this->assertEquals(302, self::$DI['client']->getResponse()->getStatusCode()); $this->assertEquals(302, self::$DI['client']->getResponse()->getStatusCode());
$this->assertEquals('/admin/task-manager/tasks', self::$DI['client']->getResponse()->headers->get('location')); $this->assertEquals('/admin/task-manager/tasks', self::$DI['client']->getResponse()->headers->get('location'));

View File

@@ -102,7 +102,7 @@ class UploadTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($record->get_thumbnail()->is_physically_present()); $this->assertTrue($record->get_thumbnail()->is_physically_present());
$fields = $record->get_caption()->get_fields(['FileName']); $fields = $record->get_caption()->get_fields(['FileName']);
$field = array_pop($fields); $field = array_pop($fields);
$this->assertEquals($field->get_serialized_values(), 'KIKOO'); $this->assertEquals('KIKOO.JPG', $field->get_serialized_values());
} }
} }

View File

@@ -32,7 +32,7 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($client->getResponse()->isRedirect()); $this->assertTrue($client->getResponse()->isRedirect());
$this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session')); $this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session'));
$this->assertNotNUll($client->getResponse()->headers->get('location')); $this->assertNotNUll($client->getResponse()->headers->get('location'));
$this->assertEquals('/login?redirect=..%2Fprod', $client->getResponse()->headers->get('location')); $this->assertRegExp('#/login\?redirect=..(?:%2F|/)prod#', $client->getResponse()->headers->get('location'));
} }
public function testEndSessionXmlXhttpRequest() public function testEndSessionXmlXhttpRequest()
@@ -132,7 +132,7 @@ class SessionManagerSubscriberTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue($client->getResponse()->isRedirect()); $this->assertTrue($client->getResponse()->isRedirect());
$this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session')); $this->assertNotNUll($client->getResponse()->headers->get('x-phraseanet-end-session'));
$this->assertNotNUll($client->getResponse()->headers->get('location')); $this->assertNotNUll($client->getResponse()->headers->get('location'));
$this->assertEquals('/login?redirect=..%2Fprod', $client->getResponse()->headers->get('location')); $this->assertRegExp('#/login\?redirect=..(?:%2F|/)prod#', $client->getResponse()->headers->get('location'));
} }
public function testEndSessionAuthenticatedWithOutdatedIdleXmlHttpRequest() public function testEndSessionAuthenticatedWithOutdatedIdleXmlHttpRequest()

View File

@@ -5,17 +5,31 @@ namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Core\Provider\SessionHandlerServiceProvider; use Alchemy\Phrasea\Core\Provider\SessionHandlerServiceProvider;
use Alchemy\Tests\Phrasea\MockArrayConf; use Alchemy\Tests\Phrasea\MockArrayConf;
use Silex\Application as SilexApp; use Silex\Application;
use Silex\Provider\SessionServiceProvider; use Silex\Provider\SessionServiceProvider;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class SessionHandlerServiceProviderTest extends \PhraseanetTestCase class SessionHandlerServiceProviderTest extends \PHPUnit_Framework_TestCase
{ {
/** /** @var SessionHandlerServiceProvider */
* @dataProvider provideVariousConfs private $sut;
*/
public function testWithVariousConf($sessionConf, $expectedInstance, $method = null, $options = null, $mock = null) protected function setUp()
{ {
$app = new SilexApp(); $this->sut = new SessionHandlerServiceProvider();
}
/**
* @dataProvider provideVariousConfigurations
*/
public function testWithVariousConfigurations($sessionConf, $expectedInstance, $method = null, $options = null, $mock = null)
{
$app = new Application();
$app['root.path'] = __DIR__ . '/../../../../../..'; $app['root.path'] = __DIR__ . '/../../../../../..';
$app->register(new SessionServiceProvider()); $app->register(new SessionServiceProvider());
$app->register(new SessionHandlerServiceProvider()); $app->register(new SessionHandlerServiceProvider());
@@ -35,60 +49,9 @@ class SessionHandlerServiceProviderTest extends \PhraseanetTestCase
$this->assertInstanceOf($expectedInstance, $handler); $this->assertInstanceOf($expectedInstance, $handler);
} }
public function provideVariousConfs() public function provideVariousConfigurations()
{ {
$memcache = $this->getMockBuilder('Memcache') $configurations = [
->disableOriginalConstructor()
->getMock();
@$memcached = $this->getMockBuilder('Memcached')
->disableOriginalConstructor()
->getMock();
$redis = $this->getMockBuilder('Redis')
->disableOriginalConstructor()
->getMock();
return [
[
[
'type' => 'memcache',
'options' => [
'host' => 'localhost',
'port' => '11211',
]
],
'Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler',
'getMemcacheConnection',
['host' => 'localhost', 'port' => 11211],
$memcache
],
[
[
'type' => 'memcached',
'options' => [
'host' => 'localhost',
'port' => '11211',
]
],
'Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler',
'getMemcachedConnection',
['host' => 'localhost', 'port' => 11211],
$memcached
],
[
[
'type' => 'redis',
'options' => [
'host' => '127.0.0.1',
'port' => '6379',
]
],
'Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler',
'getRedisConnection',
['host' => '127.0.0.1', 'port' => 6379],
$redis
],
[ [
[ [
'main' => [ 'main' => [
@@ -100,5 +63,129 @@ class SessionHandlerServiceProviderTest extends \PhraseanetTestCase
'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler' 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler'
] ]
]; ];
if (class_exists('Memcache')) {
$memcache = $this->getMockBuilder('Memcache')
->disableOriginalConstructor()
->getMock();
$configurations[] = [
[
'type' => 'memcache',
'options' => [
'host' => 'localhost',
'port' => '11211',
]
],
'Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler',
'getMemcacheConnection',
['host' => 'localhost', 'port' => 11211],
$memcache
];
}
if (class_exists('Memcached')) {
// Error suppressor due to Memcached having now obsolete by reference declarations
@$memcached = $this->getMockBuilder('Memcached')
->disableOriginalConstructor()
->getMock();
$configurations[] = [
[
'type' => 'memcached',
'options' => [
'host' => 'localhost',
'port' => '11211',
]
],
'Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler',
'getMemcachedConnection',
['host' => 'localhost', 'port' => 11211],
$memcached
];
}
if (class_exists('Redis')) {
$redis = $this->getMockBuilder('Redis')
->disableOriginalConstructor()
->getMock();
$configurations[] = [
[
'type' => 'redis',
'options' => [
'host' => '127.0.0.1',
'port' => '6379',
]
],
'Symfony\Component\HttpFoundation\Session\Storage\Handler\WriteCheckSessionHandler',
'getRedisConnection',
['host' => '127.0.0.1', 'port' => 6379],
$redis
];
}
return $configurations;
}
public function testItIgnoresSubRequests()
{
$event = $this->getMockBuilder(FilterResponseEvent::class)
->disableOriginalConstructor()
->getMock();
$event->expects($this->once())
->method('getRequestType')
->willReturn(HttpKernelInterface::SUB_REQUEST)
;
$this->sut->onKernelResponse($event);
}
public function testItSavesSessionAtKernelResponseEvent()
{
$session = $this->getMock(SessionInterface::class);
$session
->expects($this->once())
->method('isStarted')
->willReturn(true)
;
$session
->expects($this->once())
->method('save')
;
$request = new Request();
$request->setSession($session);
$event = $this->getMockBuilder(FilterResponseEvent::class)
->disableOriginalConstructor()
->getMock();
$event->expects($this->once())
->method('getRequestType')
->willReturn(HttpKernelInterface::MASTER_REQUEST)
;
$event
->expects($this->once())
->method('getRequest')
->willReturn($request)
;
$this->sut->onKernelResponse($event);
}
public function testItAddsFilterResponseAtBoot()
{
$dispatcher = $this->getMock(EventDispatcherInterface::class);
$dispatcher
->expects($this->once())
->method('addListener')
->with(KernelEvents::RESPONSE, [$this->sut, 'onKernelResponse'], -129);
$app = new Application();
$app['dispatcher'] = $dispatcher;
$this->sut->boot($app);
} }
} }

View File

@@ -23,7 +23,7 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg'); $response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg');
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('inline; filename="cestlafete.jpg"', $response->headers->get('content-disposition')); $this->assertEquals('inline; filename="cestlafete.jpg"', $response->headers->get('content-disposition'));
$this->assertEquals(0, $response->getMaxAge()); $this->assertEquals(0, $response->getMaxAge());
$response->setPrivate(); $response->setPrivate();
@@ -45,7 +45,7 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg'); $response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg');
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('inline; filename="toto.jpg"', $response->headers->get('content-disposition')); $this->assertEquals('inline; filename="toto.jpg"', $response->headers->get('content-disposition'));
} }
@@ -55,7 +55,7 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment'); $response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment');
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition')); $this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition'));
} }
@@ -77,7 +77,7 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment'); $response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment');
$response->prepare($request); $response->prepare($request);
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition')); $this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition'));
$this->assertEquals('/protected/cestlafete.jpg', $response->headers->get('x-accel-redirect')); $this->assertEquals('/protected/cestlafete.jpg', $response->headers->get('x-accel-redirect'));
} }
@@ -100,7 +100,7 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment'); $response = $this->factory->deliverFile(__DIR__ . '/../../../../files/cestlafete.jpg', 'toto.jpg', 'attachment');
$response->prepare($request); $response->prepare($request);
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition')); $this->assertEquals('attachment; filename="toto.jpg"', $response->headers->get('content-disposition'));
$this->assertEquals('/protected/cestlafete.jpg', $response->headers->get('x-accel-redirect')); $this->assertEquals('/protected/cestlafete.jpg', $response->headers->get('x-accel-redirect'));
} }
@@ -136,7 +136,7 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$response = $this->factory->deliverFile($file, 'PhraseanetTestCase.php', 'attachment'); $response = $this->factory->deliverFile($file, 'PhraseanetTestCase.php', 'attachment');
$response->prepare($request); $response->prepare($request);
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('attachment; filename="PhraseanetTestCase.php"', $response->headers->get('content-disposition')); $this->assertEquals('attachment; filename="PhraseanetTestCase.php"', $response->headers->get('content-disposition'));
$this->assertEquals(realpath($file), $response->headers->get('x-accel-redirect')); $this->assertEquals(realpath($file), $response->headers->get('x-accel-redirect'));
} }
@@ -152,7 +152,7 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$response = $this->factory->deliverData($data, 'data.csv', 'text/csv', 'attachment'); $response = $this->factory->deliverData($data, 'data.csv', 'text/csv', 'attachment');
$this->assertInstanceOf("Symfony\Component\HttpFoundation\Response", $response); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('attachment; filename="data.csv"', $response->headers->get('content-disposition')); $this->assertEquals('attachment; filename="data.csv"', $response->headers->get('content-disposition'));
$this->assertEquals('text/csv', $response->headers->get('content-type')); $this->assertEquals('text/csv', $response->headers->get('content-type'));
$this->assertEquals($data, $response->getContent()); $this->assertEquals($data, $response->getContent());

View File

@@ -5,7 +5,7 @@ namespace Alchemy\Tests\Phrasea\Http\XSendFile;
use Alchemy\Phrasea\Http\XSendFile\NginxMode; use Alchemy\Phrasea\Http\XSendFile\NginxMode;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
class NginxModeTest extends \PhraseanetTestCase class NginxModeTest extends \PHPUnit_Framework_TestCase
{ {
public function testGetVirtualHost() public function testGetVirtualHost()
{ {
@@ -43,7 +43,7 @@ class NginxModeTest extends \PhraseanetTestCase
$mode->setHeaders($request); $mode->setHeaders($request);
$this->assertArrayHasKey('x-sendfile-type', $request->headers->all()); $this->assertArrayHasKey('x-sendfile-type', $request->headers->all());
$this->assertArrayHasKey('x-accel-mapping', $request->headers->all()); $this->assertArrayHasKey('x-accel-mapping', $request->headers->all());
$this->assertEquals('/protected='.realpath($protected).',/uploads='.realpath($upload), $request->headers->get('X-Accel-Mapping')); $this->assertEquals(realpath($protected).'=/protected,'.realpath($upload).'=/uploads', $request->headers->get('X-Accel-Mapping'));
} }
public function testSetInvalidHeaders() public function testSetInvalidHeaders()