2015-11-27 23:58:05 +01:00
|
|
|
<?php
|
|
|
|
include_once 'tests/__lib__/Mock.php';
|
2016-07-27 23:27:28 +02:00
|
|
|
include_once 'tests/__mocks__/BeanMock.php';
|
2015-11-27 23:58:05 +01:00
|
|
|
include_once 'tests/__mocks__/SlimMock.php';
|
|
|
|
include_once 'tests/__mocks__/RedBeanMock.php';
|
|
|
|
|
|
|
|
use RedBeanPHP\Facade as RedBean;
|
2017-11-06 20:06:34 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2015-11-27 23:58:05 +01:00
|
|
|
|
|
|
|
class DataStoreMock extends DataStore {
|
|
|
|
const TABLE = 'MOCK_TABLE';
|
2016-01-15 03:45:22 +01:00
|
|
|
|
|
|
|
public static function getProps() {
|
|
|
|
return array(
|
|
|
|
'prop1',
|
|
|
|
'prop2',
|
|
|
|
'prop3',
|
|
|
|
);
|
|
|
|
}
|
2015-11-27 23:58:05 +01:00
|
|
|
|
2016-05-15 01:22:46 +02:00
|
|
|
public function getDefaultProps() {
|
2015-11-27 23:58:05 +01:00
|
|
|
return array(
|
|
|
|
'prop1' => 0,
|
|
|
|
'prop2' => 'hello'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 20:06:34 +01:00
|
|
|
class DataStoreTest extends TestCase {
|
2015-11-27 23:58:05 +01:00
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
RedBean::initStubs();
|
|
|
|
|
|
|
|
$this->instance = new DataStoreMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testContructor() {
|
2016-08-04 05:59:04 +02:00
|
|
|
$this->instance->store();
|
2015-11-27 23:58:05 +01:00
|
|
|
$newInstance = new DataStoreMock($this->instance->getBeanInstance());
|
|
|
|
|
|
|
|
$this->assertEquals($newInstance->prop1, 0);
|
|
|
|
$this->assertEquals($newInstance->prop2, 'hello');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDataStoreCustomData() {
|
|
|
|
$this->instance->setProperties(array(
|
|
|
|
'prop3' => 'EXTRA_DATA'
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals($this->instance->prop1, 0);
|
|
|
|
$this->assertEquals($this->instance->prop2, 'hello');
|
|
|
|
$this->assertEquals($this->instance->prop3, 'EXTRA_DATA');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testStore() {
|
|
|
|
$this->instance->store();
|
|
|
|
$this->assertTrue(RedBean::get('store')->hasBeenCalled());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDataStore() {
|
|
|
|
RedBean::setStatics(array(
|
2016-08-04 05:59:04 +02:00
|
|
|
'findOne' => \Mock::stub()->returns(new BeanMock(['prop1' => 'TEST_VALUE']))
|
2015-11-27 23:58:05 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$dataStoreIntance = DataStoreMock::getDataStore('ID_VALUE');
|
|
|
|
|
2016-08-04 05:59:04 +02:00
|
|
|
$this->assertEquals($dataStoreIntance->prop1, 'TEST_VALUE');
|
2015-11-27 23:58:05 +01:00
|
|
|
|
|
|
|
$this->assertTrue(RedBean::get('findOne')->hasBeenCalledWithArgs(
|
|
|
|
'MOCK_TABLE',
|
2016-01-15 03:45:22 +01:00
|
|
|
'id =:value',
|
2015-11-27 23:58:05 +01:00
|
|
|
array(
|
|
|
|
':value' => 'ID_VALUE'
|
|
|
|
)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteDataStore() {
|
2016-05-15 01:22:46 +02:00
|
|
|
$this->instance->delete();
|
2015-11-27 23:58:05 +01:00
|
|
|
|
2016-05-15 01:22:46 +02:00
|
|
|
$this->assertTrue(RedBean::get('trash')->hasBeenCalledWithArgs($this->instance->getBeanInstance()));
|
2015-11-27 23:58:05 +01:00
|
|
|
}
|
|
|
|
}
|