baikal-storage-plugin/tests/StorageManagerTest.php

56 lines
1.7 KiB
PHP
Raw Normal View History

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;
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);
$this->mockStorage = $this->createMock(Taskwarrior::class);
2020-05-03 16:41:59 -05:00
}
public function testAddTaskwarriorStorage() {
$configs = ['taskwarrior' => ['taskrc' => '', 'taskdata' => '']];
$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));
$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);
}
}