mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 14:33:14 +00:00
150 lines
4.1 KiB
PHP
150 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Tests\Phrasea\TaskManager;
|
|
|
|
use Alchemy\Phrasea\TaskManager\TaskManagerStatus;
|
|
use Alchemy\Phrasea\Core\Configuration\ConfigurationInterface;
|
|
|
|
class TaskManagerStatusTest extends \PhraseanetTestCase
|
|
{
|
|
/**
|
|
* @dataProvider provideInitialData
|
|
*/
|
|
public function testStart($initialData)
|
|
{
|
|
$conf = new ConfigurationTest($initialData);
|
|
$expected = $conf->getConfig();
|
|
$expected['task-manager']['status'] = TaskManagerStatus::STATUS_STARTED;
|
|
|
|
$status = new TaskManagerStatus($conf);
|
|
$status->start();
|
|
|
|
$this->assertEquals($expected, $conf->getConfig());
|
|
}
|
|
|
|
public function provideInitialData()
|
|
{
|
|
return [
|
|
[[]],
|
|
[['task-manager' => []]],
|
|
[['task-manager' => ['status' => TaskManagerStatus::STATUS_STARTED]]],
|
|
[['task-manager' => ['status' => TaskManagerStatus::STATUS_STOPPED]]],
|
|
[['key1' => 'value1']],
|
|
[['task-manager' => [], 'key2' => 'value2']],
|
|
[['task-manager' => ['status' => TaskManagerStatus::STATUS_STARTED, 'key3' => 'value3'], 'key4' => 'value4']],
|
|
[['task-manager' => ['status' => TaskManagerStatus::STATUS_STOPPED, 'key5' => 'value5'], 'key6' => 'value6']],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideInitialData
|
|
*/
|
|
public function testStop($initialData)
|
|
{
|
|
$conf = new ConfigurationTest($initialData);
|
|
$expected = $conf->getConfig();
|
|
$expected['task-manager']['status'] = TaskManagerStatus::STATUS_STOPPED;
|
|
|
|
$status = new TaskManagerStatus($conf);
|
|
$status->stop();
|
|
|
|
$this->assertEquals($expected, $conf->getConfig());
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideConfAndStatusData
|
|
*/
|
|
public function testIsRunning($data, $expectedStatus, $isRunning)
|
|
{
|
|
$conf = new ConfigurationTest($data);
|
|
$status = new TaskManagerStatus($conf);
|
|
$this->assertEquals($isRunning, $status->isRunning());
|
|
}
|
|
|
|
public function provideConfAndStatusData()
|
|
{
|
|
return [
|
|
[[], TaskManagerStatus::STATUS_STARTED, true],
|
|
[['task-manager' => []], TaskManagerStatus::STATUS_STARTED, true],
|
|
[['task-manager' => ['status' => TaskManagerStatus::STATUS_STOPPED]], TaskManagerStatus::STATUS_STOPPED, false],
|
|
[['task-manager' => ['status' => TaskManagerStatus::STATUS_STARTED]], TaskManagerStatus::STATUS_STARTED, true],
|
|
[['task-manager' => ['status' => 'unknown']], TaskManagerStatus::STATUS_STARTED, true],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideConfAndStatusData
|
|
*/
|
|
public function testGetStatus($data, $expectedStatus, $isRunning)
|
|
{
|
|
$conf = new ConfigurationTest($data);
|
|
$status = new TaskManagerStatus($conf);
|
|
$this->assertEquals($expectedStatus, $status->getStatus());
|
|
}
|
|
}
|
|
|
|
class ConfigurationTest implements ConfigurationInterface
|
|
{
|
|
private $data = [];
|
|
|
|
public function __construct(array $data)
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
|
|
public function offsetGet($key)
|
|
{
|
|
return $this->data[$key];
|
|
}
|
|
|
|
public function offsetSet($key, $value)
|
|
{
|
|
$this->data[$key] = $value;
|
|
}
|
|
|
|
public function offsetExists($key)
|
|
{
|
|
return isset($this->data[$key]);
|
|
}
|
|
|
|
public function offsetUnset($key)
|
|
{
|
|
unset($this->data[$key]);
|
|
}
|
|
|
|
public function getConfig()
|
|
{
|
|
return $this->data;
|
|
}
|
|
|
|
public function initialize()
|
|
{
|
|
throw new \RuntimeException('This method should not be used here');
|
|
}
|
|
|
|
public function delete()
|
|
{
|
|
throw new \RuntimeException('This method should not be used here');
|
|
}
|
|
|
|
public function isSetup()
|
|
{
|
|
throw new \RuntimeException('This method should not be used here');
|
|
}
|
|
|
|
public function setDefault($name)
|
|
{
|
|
throw new \RuntimeException('This method should not be used here');
|
|
}
|
|
|
|
public function setConfig(array $config)
|
|
{
|
|
throw new \RuntimeException('This method should not be used here');
|
|
}
|
|
|
|
public function compileAndWrite()
|
|
{
|
|
throw new \RuntimeException('This method should not be used here');
|
|
}
|
|
}
|