fix: Added logger as a dependency for storage class
This commit is contained in:
parent
8cafda3f26
commit
df7ab092cc
@ -20,7 +20,7 @@ class Logger {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createLoggerFile() {
|
public function createLoggerFile() {
|
||||||
if (!file_exists($this->configs['file'])) {
|
if (!file_exists($this->configs['file'])) {
|
||||||
if (!fopen($this->configs['file'], 'w')) {
|
if (!fopen($this->configs['file'], 'w')) {
|
||||||
throw new \Exception(sprintf('Could not create logger file %s', $this->configs['file']));
|
throw new \Exception(sprintf('Could not create logger file %s', $this->configs['file']));
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
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;
|
use Carbon\CarbonTimeZone;
|
||||||
|
|
||||||
@ -15,10 +14,10 @@ class Taskwarrior implements IStorage {
|
|||||||
private $logger;
|
private $logger;
|
||||||
private $tz;
|
private $tz;
|
||||||
|
|
||||||
public function __construct($console, $configs) {
|
public function __construct($console, $configs, $logger) {
|
||||||
$this->console = $console;
|
$this->console = $console;
|
||||||
$this->configs = $configs['storages']['taskwarrior'];
|
$this->configs = $configs['storages']['taskwarrior'];
|
||||||
$this->logger = new Logger($configs, 'Taskwarrior');
|
$this->logger = $logger;
|
||||||
$this->tz = new CarbonTimeZone($configs['general']['timezone']);
|
$this->tz = new CarbonTimeZone($configs['general']['timezone']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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',
|
||||||
|
Loading…
Reference in New Issue
Block a user