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;
|
|
|
|
use Aerex\BaikalStorage\Storages\IStorage;
|
|
|
|
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-05-03 16:41:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddTaskwarriorStorage() {
|
2020-05-12 23:56:22 -05:00
|
|
|
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => '']];
|
2020-05-28 11:54:21 -05:00
|
|
|
$tw = new Taskwarrior($this->mockConsole, $configs);
|
2020-05-03 16:41:59 -05:00
|
|
|
$manager = new StorageManager($this->mockConfigBuilder);
|
|
|
|
$manager->addStorage(Taskwarrior::NAME, $tw);
|
|
|
|
$storages = $manager->getStorages();
|
|
|
|
$configs = $manager->getConfigs();
|
|
|
|
$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-05-12 23:56:22 -05:00
|
|
|
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => '']];
|
|
|
|
$manager = new StorageManager($configs);
|
2020-05-03 16:41:59 -05:00
|
|
|
$manager->addStorage(Taskwarrior::NAME, $this->mockStorage);
|
|
|
|
$manager->import($cal);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|