1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103:
<?php
namespace Nethgui\Test\Unit\Nethgui\Adapter;
use \Nethgui\Test\Tool\DB;
use \Nethgui\Test\Tool\MockFactory;
class TableAdapter2Test extends \PHPUnit_Framework_TestCase
{
protected $object;
protected $mockDb;
protected function setUp()
{
$this->mockDb = $this->getInitialDb();
;
$this->object = new \Nethgui\Adapter\TableAdapter(MockFactory::getMockDatabase($this, $this->mockDb));
}
protected function getInitialDb()
{
$db = new \Nethgui\Test\Tool\DB;
$type = 'T';
$initialTable = array();
foreach (array(1, 2, 3) as $i) {
$initialTable[$i . 'K'] = array(
'type' => $type . $i,
$i . 'P' => $i . 'V',
$i . 'Q' => $i . 'W',
);
}
return $db->set(DB::getAll(NULL), $initialTable);
}
public function testGet()
{
$e = new \ArrayObject(array(
'1K' => new \ArrayObject(array('type' => 'T1', '1P' => '1V', '1Q' => '1W')),
'2K' => new \ArrayObject(array('type' => 'T2', '2P' => '2V', '2Q' => '2W')),
'3K' => new \ArrayObject(array('type' => 'T3', '3P' => '3V', '3Q' => '3W')),
));
$v = $this->object->get();
$this->assertInstanceOf("ArrayObject", $v);
$this->assertEquals($e, $v);
}
public function testSave1()
{
$f = $e = new \ArrayObject(array(
'1K' => new \ArrayObject(array('type' => 'T1', '1P' => '1V', '1Q' => '1W')),
'2K' => new \ArrayObject(array('type' => 'T2', '2P' => '2V', '2Q' => '2W')),
'3K' => new \ArrayObject(array('type' => 'T3', '3P' => '3V', '3Q' => '3W')),
));
$this->mockDb->set(DB::setKey('4K', 'T4', array('4P' => '4V', '4Q' => '4W')), $f);
$this->mockDb->setFinal(TRUE);
$this->object->offsetSet('4K', array('type' => 'T4', '4P' => '4V', '4Q' => '4W'));
$this->assertTrue($this->object->isModified());
$this->assertEquals(1, $this->object->save());
}
public function testSave2()
{
$this->object->offsetSet('4K', array('4P' => '4V', '4Q' => '4W'));
$this->object->save();
}
}