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 (!fopen($this->configs['file'], 'w')) {
|
||||
throw new \Exception(sprintf('Could not create logger file %s', $this->configs['file']));
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Aerex\BaikalStorage;
|
||||
|
||||
use Aerex\BaikalStorage\Logger;
|
||||
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
||||
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
||||
use Aerex\BaikalStorage\Configs\TaskwarriorConfig;
|
||||
@ -33,7 +34,7 @@ class Plugin extends ServerPlugin {
|
||||
|
||||
|
||||
/**
|
||||
* Creates the Taskwarrior plugin
|
||||
* Creates the Storage plugin
|
||||
*
|
||||
* @param CalendarProcessor $TWCalManager
|
||||
*
|
||||
@ -56,7 +57,7 @@ class Plugin extends ServerPlugin {
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace Aerex\BaikalStorage\Storages;
|
||||
|
||||
use Sabre\VObject\Component\VCalendar as Calendar;
|
||||
use Aerex\BaikalStorage\Logger;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonTimeZone;
|
||||
|
||||
@ -15,10 +14,10 @@ class Taskwarrior implements IStorage {
|
||||
private $logger;
|
||||
private $tz;
|
||||
|
||||
public function __construct($console, $configs) {
|
||||
public function __construct($console, $configs, $logger) {
|
||||
$this->console = $console;
|
||||
$this->configs = $configs['storages']['taskwarrior'];
|
||||
$this->logger = new Logger($configs, 'Taskwarrior');
|
||||
$this->logger = $logger;
|
||||
$this->tz = new CarbonTimeZone($configs['general']['timezone']);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Aerex\BaikalStorage\AbstractConsole;
|
||||
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
||||
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
||||
use Aerex\BaikalStorage\Storages\IStorage;
|
||||
use Aerex\BaikalStorage\Logger;
|
||||
use Sabre\VObject\Component\VCalendar as Calendar;
|
||||
|
||||
class StorageManagerTest extends TestCase {
|
||||
@ -27,11 +27,20 @@ class StorageManagerTest extends TestCase {
|
||||
->getMock();
|
||||
$this->mockConsole = $this->createMock(AbstractConsole::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() {
|
||||
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => '']];
|
||||
$tw = new Taskwarrior($this->mockConsole, $configs);
|
||||
public function testAddTaskwarriorStorage() {
|
||||
$tw = new Taskwarrior($this->mockConsole, $this->configs, $this->mockLogger);
|
||||
$manager = new StorageManager($this->mockConfigBuilder);
|
||||
$manager->addStorage(Taskwarrior::NAME, $tw);
|
||||
$storages = $manager->getStorages();
|
||||
@ -46,8 +55,7 @@ class StorageManagerTest extends TestCase {
|
||||
->method('save')
|
||||
->with($this->equalTo($cal));
|
||||
|
||||
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => '']];
|
||||
$manager = new StorageManager($configs);
|
||||
$manager = new StorageManager($this->configs);
|
||||
$manager->addStorage(Taskwarrior::NAME, $this->mockStorage);
|
||||
$manager->import($cal);
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace Aerex\BaikalStorage;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Aerex\BaikalStorage\AbstractConsole;
|
||||
use Aerex\BaikalStorage\Logger;
|
||||
use Sabre\VObject\Component\VCalendar as Calendar;
|
||||
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
||||
|
||||
@ -16,11 +17,20 @@ class TaskwarriorTest extends TestCase {
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->mockConsole = $this->createMock(AbstractConsole::class);
|
||||
$this->mockLogger = $this->createMock(Logger::class);
|
||||
}
|
||||
|
||||
public function testVObjectToTask() {
|
||||
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => ''], 'logger' => ['file' => '', 'level'=> 'DEBUG', 'enabled' => true]];
|
||||
$this->taskwarrior = new Taskwarrior($this->mockConsole, $configs);
|
||||
$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([
|
||||
'VTODO' => [
|
||||
'SUMMARY' => 'Finish project',
|
||||
|
Loading…
Reference in New Issue
Block a user