Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
df7ab092cc | ||
|
8cafda3f26 | ||
|
b9d27d9aa2 | ||
|
728fce1b78 | ||
|
c302c4653a | ||
|
c2e181aa75 | ||
|
00d0ea624f |
@@ -17,7 +17,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5",
|
"php": ">=5.5",
|
||||||
"sabre/dav" : "~4.0.2",
|
"sabre/dav" : "~4.1.0",
|
||||||
"sabre/vobject": "^4.0",
|
"sabre/vobject": "^4.0",
|
||||||
"nesbot/carbon": "^2.0.0",
|
"nesbot/carbon": "^2.0.0",
|
||||||
"laminas/laminas-validator": "^2.13",
|
"laminas/laminas-validator": "^2.13",
|
||||||
|
@@ -6,6 +6,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
|
|||||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||||
use Symfony\Component\Config\Definition\Processor;
|
use Symfony\Component\Config\Definition\Processor;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
use Carbon\CarbonTimeZone;
|
||||||
|
|
||||||
class ConfigBuilder implements ConfigurationInterface {
|
class ConfigBuilder implements ConfigurationInterface {
|
||||||
private $configs = [];
|
private $configs = [];
|
||||||
@@ -24,6 +25,8 @@ class ConfigBuilder implements ConfigurationInterface {
|
|||||||
$treeBuilder = new TreeBuilder();
|
$treeBuilder = new TreeBuilder();
|
||||||
$rootNode = $treeBuilder->root('configs');
|
$rootNode = $treeBuilder->root('configs');
|
||||||
$ref = $rootNode->children()
|
$ref = $rootNode->children()
|
||||||
|
->arrayNode('general')
|
||||||
|
->children()
|
||||||
->arrayNode('logger')
|
->arrayNode('logger')
|
||||||
->canBeEnabled()
|
->canBeEnabled()
|
||||||
->children()
|
->children()
|
||||||
@@ -36,8 +39,18 @@ class ConfigBuilder implements ConfigurationInterface {
|
|||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->end()
|
->end()
|
||||||
->end();
|
->end()
|
||||||
|
->scalarNode('timezone')
|
||||||
|
->defaultValue('UTC')
|
||||||
|
->validate()
|
||||||
|
->IfNotInArray(CarbonTimeZone::listIdentifiers())
|
||||||
|
->thenInvalid('Invalid timezone identifier %s')
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
|
->arrayNode('storages')
|
||||||
|
->children();
|
||||||
foreach ($this->configs as $config) {
|
foreach ($this->configs as $config) {
|
||||||
$ref = $ref->append($config->get());
|
$ref = $ref->append($config->get());
|
||||||
}
|
}
|
||||||
|
@@ -23,16 +23,15 @@ class Console extends AbstractConsole {
|
|||||||
$stdin = array_merge($stdin, $this->defaultArgs, $args);
|
$stdin = array_merge($stdin, $this->defaultArgs, $args);
|
||||||
|
|
||||||
if (isset($input)) {
|
if (isset($input)) {
|
||||||
$stdin[] = $this->convertToString($input);
|
$input = $this->convertToString($input);
|
||||||
}
|
}
|
||||||
$process = new Process(implode(' ', $stdin), $input, $envs);
|
$process = new Process(implode(' ', $stdin), null, $envs, $input);
|
||||||
$process->inheritEnvironmentVariables();
|
$process->inheritEnvironmentVariables();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$process->mustRun();
|
$process->mustRun();
|
||||||
return $process->getOutput();
|
return $process->getOutput();
|
||||||
} catch (ProcessFailedException $error) {
|
} catch (ProcessFailedException $error) {
|
||||||
echo $error->getMessage();
|
|
||||||
throw $error;
|
throw $error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,16 +9,25 @@ class Logger {
|
|||||||
private $configs = ['enabled' => false];
|
private $configs = ['enabled' => false];
|
||||||
|
|
||||||
function __construct($configs, $tag) {
|
function __construct($configs, $tag) {
|
||||||
if (isset($configs['logger'])) {
|
if (isset($configs['general']) && isset($configs['general']['logger'])) {
|
||||||
$this->configs = $configs['logger'];
|
$this->configs = $configs['general']['logger'];
|
||||||
}
|
}
|
||||||
if ($this->configs['enabled']) {
|
if ($this->configs['enabled']) {
|
||||||
|
$this->createLoggerFile();
|
||||||
$this->logger = new Monolog($tag);
|
$this->logger = new Monolog($tag);
|
||||||
$logLevel = Monolog::getLevels()[$this->configs['level']];
|
$logLevel = Monolog::getLevels()[$this->configs['level']];
|
||||||
$this->logger->pushHandler(new StreamHandler($this->configs['file'], $logLevel));
|
$this->logger->pushHandler(new StreamHandler($this->configs['file'], $logLevel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function createLoggerFile() {
|
||||||
|
if (!file_exists($this->configs['file'])) {
|
||||||
|
if (!fopen($this->configs['file'], 'w')) {
|
||||||
|
throw new \Exception(sprintf('Could not create logger file %s', $this->configs['file']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function debug($message) {
|
public function debug($message) {
|
||||||
if ($this->configs['enabled']) {
|
if ($this->configs['enabled']) {
|
||||||
$this->logger->debug($message);
|
$this->logger->debug($message);
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Aerex\BaikalStorage;
|
namespace Aerex\BaikalStorage;
|
||||||
|
|
||||||
|
use Aerex\BaikalStorage\Logger;
|
||||||
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
||||||
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
||||||
use Aerex\BaikalStorage\Configs\TaskwarriorConfig;
|
use Aerex\BaikalStorage\Configs\TaskwarriorConfig;
|
||||||
@@ -33,7 +34,7 @@ class Plugin extends ServerPlugin {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the Taskwarrior plugin
|
* Creates the Storage plugin
|
||||||
*
|
*
|
||||||
* @param CalendarProcessor $TWCalManager
|
* @param CalendarProcessor $TWCalManager
|
||||||
*
|
*
|
||||||
@@ -56,7 +57,7 @@ class Plugin extends ServerPlugin {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public function initializeStorages($configs) {
|
public function initializeStorages($configs) {
|
||||||
$taskwarrior = new Taskwarrior(new Console(['rc.verbose=nothing', 'rc.hooks=off']), $configs);
|
$taskwarrior = new Taskwarrior(new Console(['rc.verbose=nothing', 'rc.hooks=off']), $configs, new Logger($configs, 'Taskwarrior'););
|
||||||
$this->storageManager->addStorage(Taskwarrior::NAME, $taskwarrior);
|
$this->storageManager->addStorage(Taskwarrior::NAME, $taskwarrior);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,7 +38,7 @@ class StorageManager {
|
|||||||
if (!isset($this->configs)) {
|
if (!isset($this->configs)) {
|
||||||
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
||||||
}
|
}
|
||||||
foreach ($this->configs as $key => $value) {
|
foreach ($this->configs['storages'] as $key => $value) {
|
||||||
$storage = $this->storages[$key];
|
$storage = $this->storages[$key];
|
||||||
if (!isset($storage)){
|
if (!isset($storage)){
|
||||||
throw new \Exception();
|
throw new \Exception();
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
namespace Aerex\BaikalStorage\Storages;
|
namespace Aerex\BaikalStorage\Storages;
|
||||||
|
|
||||||
use Sabre\VObject\Component\VCalendar as Calendar;
|
use Sabre\VObject\Component\VCalendar as Calendar;
|
||||||
use Aerex\BaikalStorage\Logger;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Carbon\CarbonTimeZone;
|
||||||
|
|
||||||
class Taskwarrior implements IStorage {
|
class Taskwarrior implements IStorage {
|
||||||
|
|
||||||
@@ -12,11 +12,13 @@ class Taskwarrior implements IStorage {
|
|||||||
private $tasks = [];
|
private $tasks = [];
|
||||||
private $configs;
|
private $configs;
|
||||||
private $logger;
|
private $logger;
|
||||||
|
private $tz;
|
||||||
|
|
||||||
public function __construct($console, $configs) {
|
public function __construct($console, $configs, $logger) {
|
||||||
$this->console = $console;
|
$this->console = $console;
|
||||||
$this->configs = $configs['taskwarrior'];
|
$this->configs = $configs['storages']['taskwarrior'];
|
||||||
$this->logger = new Logger($configs, 'Taskwarrior');
|
$this->logger = $logger;
|
||||||
|
$this->tz = new CarbonTimeZone($configs['general']['timezone']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConfig() {
|
public function getConfig() {
|
||||||
@@ -26,6 +28,13 @@ class Taskwarrior implements IStorage {
|
|||||||
public function refresh() {
|
public function refresh() {
|
||||||
$output = $this->console->execute('task', ['sync'], null,
|
$output = $this->console->execute('task', ['sync'], null,
|
||||||
['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
|
['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
|
||||||
|
$this->tasks = json_decode($this->console->execute('task', ['export'], null,
|
||||||
|
['TASKRC' => $this->configs['taskrc'], 'TASKDATA' => $this->configs['taskdata']]), true);
|
||||||
|
foreach ($this->tasks as $task) {
|
||||||
|
if (isset($task['uid'])) {
|
||||||
|
$this->tasks[$task['uid']] = $task;
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->logger->info($output);
|
$this->logger->info($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,26 +46,26 @@ class Taskwarrior implements IStorage {
|
|||||||
$task['uid'] = (string)$vtodo->UID;
|
$task['uid'] = (string)$vtodo->UID;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->SUMMARY) && !isset($vtodo->DESCRIPTION)){
|
if (isset($vtodo->SUMMARY)){
|
||||||
$task['description'] = (string)$vtodo->SUMMARY;
|
$task['description'] = (string)$vtodo->SUMMARY;
|
||||||
} else if(isset($vtodo->DESCRIPTION)) {
|
} else if(isset($vtodo->DESCRIPTION)) {
|
||||||
$task['description'] = (string)$vtodo->DESCRIPTION;
|
$task['description'] = (string)$vtodo->DESCRIPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->DTSTAMP)){
|
if (isset($vtodo->DTSTAMP)){
|
||||||
$task['entry'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C));
|
$task['entry'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->DTSTART)) {
|
if (isset($vtodo->DTSTART)) {
|
||||||
$task['start'] = new Carbon($vtodo->DTSTART->getDateTime()->format(\DateTime::W3C));
|
$task['start'] = new Carbon($vtodo->DTSTART->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->DTEND)){
|
if (isset($vtodo->DTEND)){
|
||||||
$task['end'] = new Carbon($vtodo->DTEND->getDateTime()->format(\DateTime::W3C));
|
$task['end'] = new Carbon($vtodo->DTEND->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->{'LAST-MODIFIED'})) {
|
if (isset($vtodo->{'LAST-MODIFIED'})) {
|
||||||
$task['modified'] = new Carbon($vtodo->{'LAST-MODIFIED'}->getDateTime()->format(\DateTime::W3C));
|
$task['modified'] = new Carbon($vtodo->{'LAST-MODIFIED'}->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->PRIORITY)) {
|
if (isset($vtodo->PRIORITY)) {
|
||||||
@@ -71,7 +80,7 @@ class Taskwarrior implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->DUE)){
|
if (isset($vtodo->DUE)){
|
||||||
$task['due'] = new Carbon($vtodo->DUE->getDateTime()->format(\DateTime::W3C));
|
$task['due'] = new Carbon($vtodo->DUE->getDateTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($vtodo->RRULE)) {
|
if (isset($vtodo->RRULE)) {
|
||||||
@@ -92,13 +101,13 @@ class Taskwarrior implements IStorage {
|
|||||||
case 'COMPLETED':
|
case 'COMPLETED':
|
||||||
$task['status'] = 'completed';
|
$task['status'] = 'completed';
|
||||||
if (!isset($task['end'])) {
|
if (!isset($task['end'])) {
|
||||||
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C));
|
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'CANCELED':
|
case 'CANCELED':
|
||||||
$task['status'] = 'deleted';
|
$task['status'] = 'deleted';
|
||||||
if (!isset($task['end'])) {
|
if (!isset($task['end'])) {
|
||||||
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C));
|
$task['end'] = new Carbon($vtodo->DTSTAMP->getDateTime()->format(\DateTime::W3C), $this->tz);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -108,8 +117,8 @@ class Taskwarrior implements IStorage {
|
|||||||
$task['tags'] = [];
|
$task['tags'] = [];
|
||||||
foreach ($vtodo->CATEGORIES as $category) {
|
foreach ($vtodo->CATEGORIES as $category) {
|
||||||
if (isset($this->configs['project_tag_suffix'])) {
|
if (isset($this->configs['project_tag_suffix'])) {
|
||||||
$projTagSuffixRegExp = sprintf('/^%s_/', $this->configs['project_tag_suffix']);
|
$projTagSuffixRegExp = sprintf('/^%s/', $this->configs['project_tag_suffix']);
|
||||||
if (preg_match($category, $projTagSuffixRegExp)) {
|
if (preg_match($projTagSuffixRegExp, $category)) {
|
||||||
$task['project'] = preg_replace($projTagSuffixRegExp, '', $category);
|
$task['project'] = preg_replace($projTagSuffixRegExp, '', $category);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -122,19 +131,23 @@ class Taskwarrior implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function save(Calendar $c) {
|
public function save(Calendar $c) {
|
||||||
|
try {
|
||||||
if (!isset($c->VTODO)){
|
if (!isset($c->VTODO)){
|
||||||
throw new \Exception('Calendar event does not contain VTODO');
|
throw new \Exception('Calendar event does not contain VTODO');
|
||||||
$this->logger->error('Calendar event does not contain VTODO');
|
|
||||||
}
|
}
|
||||||
$this->logger->info($c->VTODO->getJsonValue());
|
$this->logger->info(json_encode($c->jsonSerialize()));
|
||||||
$this->refresh();
|
$this->refresh();
|
||||||
$task = $this->vObjectToTask($c->VTODO);
|
$task = $this->vObjectToTask($c->VTODO);
|
||||||
$this->logger->info(json_encode($task));
|
$this->logger->info(json_encode($task));
|
||||||
$this->logger->info(
|
$this->logger->info(
|
||||||
sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], $task)
|
sprintf('Executing TASKRC = %s TASKDATA = %s task import %s', $this->configs['taskrc'], $this->configs['taskdata'], json_encode($task))
|
||||||
);
|
);
|
||||||
$output = $this->console->execute('task', ['import'], $task,
|
$output = $this->console->execute('task', ['import'], $task,
|
||||||
['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
|
['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
|
||||||
$this->logger->info($output);
|
$this->logger->info($output);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->logger->error($e->getTraceAsString());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,18 +13,21 @@ class ConfigTest extends TestCase {
|
|||||||
|
|
||||||
public $mockConfigBuilder;
|
public $mockConfigBuilder;
|
||||||
|
|
||||||
public function testLoggerConfigs() {
|
public function testGeneralLoggerConfigs() {
|
||||||
$configs = new ConfigBuilder(__DIR__ . '/Fixtures/LoggerConfig.yaml');
|
$configs = new ConfigBuilder(__DIR__ . '/Fixtures/LoggerConfig.yaml');
|
||||||
$contents = $configs->loadYaml();
|
$contents = $configs->loadYaml();
|
||||||
$this->assertEquals(sizeof($contents), 1);
|
$this->assertEquals(sizeof($contents), 1);
|
||||||
$this->assertArrayHasKey('logger', $contents, 'config missing logger property');
|
$this->assertArrayHasKey('general', $contents, 'config missing general config');
|
||||||
$this->assertArrayHasKey('file', $contents['logger'], 'config missing logger.file property');
|
$generalConfigs = $contents['general'];
|
||||||
$this->assertEquals($contents['logger']['file'], '/home/user/logger.yaml');
|
$this->assertArrayHasKey('logger', $generalConfigs, 'general config is missing logger property');
|
||||||
$this->assertArrayHasKey('level', $contents['logger'], 'config missing logger.level property');
|
$this->assertArrayHasKey('file', $generalConfigs['logger'], 'general logger config missing file property');
|
||||||
$this->assertEquals($contents['logger']['level'], 'ERROR', 'ERROR is not set as default logger level');
|
$this->assertEquals($generalConfigs['logger']['file'], '/home/user/logger.yaml');
|
||||||
$this->assertArrayHasKey('enabled', $contents['logger'], 'config missing logger.enabled property');
|
$this->assertArrayHasKey('level', $generalConfigs['logger'], 'general logger config missing level property');
|
||||||
$this->assertTrue($contents['logger']['enabled']);
|
$this->assertEquals($generalConfigs['logger']['level'], 'ERROR', 'ERROR is not set as default logger level');
|
||||||
|
$this->assertArrayHasKey('enabled', $generalConfigs['logger'], 'general config logger enabled property is missing');
|
||||||
|
$this->assertTrue($generalConfigs['logger']['enabled']);
|
||||||
|
$this->assertArrayHasKey('timezone', $generalConfigs, 'general config is missing timezone property');
|
||||||
|
$this->assertEquals($generalConfigs['timezone'], 'UTC', 'UTC is not set as default timezone');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTaskwarriorConfig() {
|
public function testTaskwarriorConfig() {
|
||||||
@@ -32,19 +35,15 @@ class ConfigTest extends TestCase {
|
|||||||
$configs->add(new TaskwarriorConfig());
|
$configs->add(new TaskwarriorConfig());
|
||||||
$contents = $configs->loadYaml();
|
$contents = $configs->loadYaml();
|
||||||
$this->assertEquals(sizeof($contents), 2);
|
$this->assertEquals(sizeof($contents), 2);
|
||||||
$this->assertArrayHasKey('logger', $contents, 'config missing logger property');
|
$this->assertArrayHasKey('storages', $contents, 'storages config missing');
|
||||||
$this->assertArrayHasKey('file', $contents['logger'], 'config missing logger.file property');
|
$this->assertArrayHasKey('taskwarrior', $contents['storages'], 'storage config missing taskwarrior property');
|
||||||
$this->assertArrayHasKey('level', $contents['logger'], 'config missing logger.level property');
|
$taskwarriorConfigs = $contents['storages']['taskwarrior'];
|
||||||
$this->assertArrayHasKey('enabled', $contents['logger'], 'config missing logger.enabled property');
|
$this->assertArrayHasKey('taskrc', $taskwarriorConfigs, 'taskwarrior config is missing taskrc property');
|
||||||
$this->assertArrayHasKey('taskwarrior', $contents, 'config missing taskwarrior property');
|
$this->assertEquals($taskwarriorConfigs['taskrc'], '/home/aerex/.taskrc');
|
||||||
$this->assertArrayHasKey('taskrc', $contents['taskwarrior'], 'config missing taskwarrior.taskrc property');
|
$this->assertArrayHasKey('taskdata', $taskwarriorConfigs, 'taskwarrior config is missing taskdata property');
|
||||||
$this->assertEquals($contents['taskwarrior']['taskrc'], '/home/aerex/.taskrc');
|
$this->assertEquals($taskwarriorConfigs['taskdata'], '/home/aerex/.task');
|
||||||
$this->assertArrayHasKey('taskdata', $contents['taskwarrior'], 'config missing taskwarrior.taskdata property');
|
$this->assertArrayHasKey('project_tag_suffix', $taskwarriorConfigs, 'taskwarrior config is missing project_tag_suffix property');
|
||||||
$this->assertEquals($contents['taskwarrior']['taskdata'], '/home/aerex/.task');
|
$this->assertEquals($taskwarriorConfigs['project_tag_suffix'], 'project_');
|
||||||
$this->assertArrayHasKey('project_tag_suffix', $contents['taskwarrior'], 'config missing taskwarrior.taskdata property');
|
|
||||||
$this->assertEquals($contents['taskwarrior']['project_tag_suffix'], 'project_');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
logger:
|
general:
|
||||||
|
logger:
|
||||||
file: /home/user/logger.yaml
|
file: /home/user/logger.yaml
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
logger:
|
general:
|
||||||
|
logger:
|
||||||
file: /home/aerex/baikal-storage-plugin.log
|
file: /home/aerex/baikal-storage-plugin.log
|
||||||
level: DEBUG
|
level: DEBUG
|
||||||
taskwarrior:
|
timezone: 'America/Denver'
|
||||||
|
storages:
|
||||||
|
taskwarrior:
|
||||||
taskdata: /home/aerex/.task
|
taskdata: /home/aerex/.task
|
||||||
taskrc: /home/aerex/.taskrc
|
taskrc: /home/aerex/.taskrc
|
||||||
project_tag_suffix: project_
|
project_tag_suffix: project_
|
||||||
|
@@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
use Aerex\BaikalStorage\AbstractConsole;
|
use Aerex\BaikalStorage\AbstractConsole;
|
||||||
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
||||||
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
||||||
use Aerex\BaikalStorage\Storages\IStorage;
|
use Aerex\BaikalStorage\Logger;
|
||||||
use Sabre\VObject\Component\VCalendar as Calendar;
|
use Sabre\VObject\Component\VCalendar as Calendar;
|
||||||
|
|
||||||
class StorageManagerTest extends TestCase {
|
class StorageManagerTest extends TestCase {
|
||||||
@@ -27,11 +27,20 @@ class StorageManagerTest extends TestCase {
|
|||||||
->getMock();
|
->getMock();
|
||||||
$this->mockConsole = $this->createMock(AbstractConsole::class);
|
$this->mockConsole = $this->createMock(AbstractConsole::class);
|
||||||
$this->mockStorage = $this->createMock(Taskwarrior::class);
|
$this->mockStorage = $this->createMock(Taskwarrior::class);
|
||||||
}
|
$this->mockLogger = $this->createMock(Logger::class);
|
||||||
|
$this->configs = [
|
||||||
|
'general' => [
|
||||||
|
'logger' => ['file' => '', 'level'=> 'DEBUG', 'enabled' => true],
|
||||||
|
'timezone' => 'UTC'
|
||||||
|
],
|
||||||
|
'storages' => [
|
||||||
|
'taskwarrior' => ['taskrc' => '', 'taskdata' => '']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function testAddTaskwarriorStorage() {
|
public function testAddTaskwarriorStorage() {
|
||||||
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => '']];
|
$tw = new Taskwarrior($this->mockConsole, $this->configs, $this->mockLogger);
|
||||||
$tw = new Taskwarrior($this->mockConsole, $configs);
|
|
||||||
$manager = new StorageManager($this->mockConfigBuilder);
|
$manager = new StorageManager($this->mockConfigBuilder);
|
||||||
$manager->addStorage(Taskwarrior::NAME, $tw);
|
$manager->addStorage(Taskwarrior::NAME, $tw);
|
||||||
$storages = $manager->getStorages();
|
$storages = $manager->getStorages();
|
||||||
@@ -46,8 +55,7 @@ class StorageManagerTest extends TestCase {
|
|||||||
->method('save')
|
->method('save')
|
||||||
->with($this->equalTo($cal));
|
->with($this->equalTo($cal));
|
||||||
|
|
||||||
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => '']];
|
$manager = new StorageManager($this->configs);
|
||||||
$manager = new StorageManager($configs);
|
|
||||||
$manager->addStorage(Taskwarrior::NAME, $this->mockStorage);
|
$manager->addStorage(Taskwarrior::NAME, $this->mockStorage);
|
||||||
$manager->import($cal);
|
$manager->import($cal);
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ namespace Aerex\BaikalStorage;
|
|||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Aerex\BaikalStorage\AbstractConsole;
|
use Aerex\BaikalStorage\AbstractConsole;
|
||||||
|
use Aerex\BaikalStorage\Logger;
|
||||||
use Sabre\VObject\Component\VCalendar as Calendar;
|
use Sabre\VObject\Component\VCalendar as Calendar;
|
||||||
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
||||||
|
|
||||||
@@ -16,11 +17,20 @@ class TaskwarriorTest extends TestCase {
|
|||||||
|
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
$this->mockConsole = $this->createMock(AbstractConsole::class);
|
$this->mockConsole = $this->createMock(AbstractConsole::class);
|
||||||
|
$this->mockLogger = $this->createMock(Logger::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVObjectToTask() {
|
public function testVObjectToTask() {
|
||||||
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => ''], 'logger' => ['file' => '', 'level'=> 'DEBUG', 'enabled' => true]];
|
$configs = [
|
||||||
$this->taskwarrior = new Taskwarrior($this->mockConsole, $configs);
|
'general' => [
|
||||||
|
'logger' => ['file' => '', 'level'=> 'DEBUG', 'enabled' => true],
|
||||||
|
'timezone' => 'UTC'
|
||||||
|
],
|
||||||
|
'storages' => [
|
||||||
|
'taskwarrior' => ['taskrc' => '', 'taskdata' => '']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
$this->taskwarrior = new Taskwarrior($this->mockConsole, $configs, $this->mockLogger);
|
||||||
$vcalendar = new Calendar([
|
$vcalendar = new Calendar([
|
||||||
'VTODO' => [
|
'VTODO' => [
|
||||||
'SUMMARY' => 'Finish project',
|
'SUMMARY' => 'Finish project',
|
||||||
|
Reference in New Issue
Block a user