2020-05-03 16:41:59 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Aerex\BaikalStorage;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Aerex\BaikalStorage\AbstractConsole;
|
|
|
|
use Aerex\BaikalStorage\Configs\ConfigBuilder;
|
|
|
|
use Aerex\BaikalStorage\Storages\Taskwarrior;
|
2020-06-11 11:43:56 -05:00
|
|
|
use Aerex\BaikalStorage\Logger;
|
2020-05-03 16:41:59 -05:00
|
|
|
use Sabre\VObject\Component\VCalendar as Calendar;
|
|
|
|
|
|
|
|
class StorageManagerTest extends TestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject
|
|
|
|
* */
|
|
|
|
private $mockConsole;
|
|
|
|
|
|
|
|
private $mockStorage;
|
|
|
|
|
|
|
|
public $mockConfigBuilder;
|
|
|
|
|
2020-05-28 11:54:21 -05:00
|
|
|
protected function setUp(): void {
|
2020-05-03 16:41:59 -05:00
|
|
|
$this->mockConfigBuilder = $this->getMockBuilder(ConfigBuilder::class)
|
|
|
|
->setMethods(['readContent'])
|
|
|
|
->setConstructorArgs([''])
|
|
|
|
->getMock();
|
|
|
|
$this->mockConsole = $this->createMock(AbstractConsole::class);
|
2020-05-28 11:54:21 -05:00
|
|
|
$this->mockStorage = $this->createMock(Taskwarrior::class);
|
2020-06-11 11:43:56 -05:00
|
|
|
$this->mockLogger = $this->createMock(Logger::class);
|
|
|
|
$this->configs = [
|
|
|
|
'general' => [
|
2020-06-14 23:55:05 -05:00
|
|
|
'logger' => ['file' => '', 'level'=> 'DEBUG', 'enabled' => true]
|
2020-06-11 11:43:56 -05:00
|
|
|
],
|
|
|
|
'storages' => [
|
|
|
|
'taskwarrior' => ['taskrc' => '', 'taskdata' => '']
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2020-05-03 16:41:59 -05:00
|
|
|
|
2020-06-11 11:43:56 -05:00
|
|
|
public function testAddTaskwarriorStorage() {
|
|
|
|
$tw = new Taskwarrior($this->mockConsole, $this->configs, $this->mockLogger);
|
2020-05-03 16:41:59 -05:00
|
|
|
$manager = new StorageManager($this->mockConfigBuilder);
|
|
|
|
$manager->addStorage(Taskwarrior::NAME, $tw);
|
|
|
|
$storages = $manager->getStorages();
|
2020-06-14 23:55:05 -05:00
|
|
|
$this->configs = $manager->getConfigs();
|
2020-05-03 16:41:59 -05:00
|
|
|
$this->assertEquals(sizeof(array_keys($storages)), 1, 'Taskwarrior storage was not added');
|
|
|
|
$this->assertArrayHasKey('taskwarrior', $storages, 'Storages should have taskwarrior');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTaskwarriorImport() {
|
|
|
|
$cal = new Calendar();
|
|
|
|
$this->mockStorage->expects($this->once())
|
|
|
|
->method('save')
|
|
|
|
->with($this->equalTo($cal));
|
|
|
|
|
2020-06-11 11:43:56 -05:00
|
|
|
$manager = new StorageManager($this->configs);
|
2020-05-03 16:41:59 -05:00
|
|
|
$manager->addStorage(Taskwarrior::NAME, $this->mockStorage);
|
|
|
|
$manager->import($cal);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|