1: <?php
2:
3: namespace Alchemy\tests;
4: use Alchemy\orm\Session;
5: use Alchemy\dialect\SQLiteCompiler;
6: use Datetime;
7:
8:
9: class MapperTest extends BaseTest {
10:
11: public function testInsert() {
12: $result = $this->getMockBuilder('Alchemy\engine\ResultSet')
13: ->disableOriginalConstructor()
14: ->setMethods(array('lastInsertID'))
15: ->getMock();
16:
17: $result->expects($this->once())
18: ->method('lastInsertID')
19: ->will($this->returnValue(1234));
20:
21: $engine = $this->getMockBuilder('Alchemy\engine\Engine')
22: ->setConstructorArgs(array(new SQLiteCompiler(), 'sqlite::memory:'))
23: ->setMethods(array('execute'))
24: ->getMock();
25:
26: $engine->expects($this->once())
27: ->method('execute')
28: ->with($this->equalTo('INSERT INTO Language (ISO2Code, LatestChangeStamp) VALUES (:p0, :p1)'))
29: ->will($this->returnValue($result));
30:
31: $session = new Session($engine);
32:
33: $lang = new Language();
34: $lang->ISO2Code = 'es';
35: $lang->LatestChangeStamp = new DateTime("1984-01-01");
36:
37: $session->add($lang);
38: $session->commit();
39: }
40:
41:
42: public function testSelect() {
43: $compiler = new SQLiteCompiler(array('alias_tables' => true));
44: $engine = $this->getMockBuilder('Alchemy\engine\Engine')
45: ->setConstructorArgs(array($compiler, 'sqlite::memory:'))
46: ->setMethods(array('execute'))
47: ->getMock();
48:
49: $engine->expects($this->once())
50: ->method('execute')
51: ->with($this->equalTo('SELECT la1.LanguageID as LanguageID, la1.ISO2Code as ISO2Code, la1.ParentLanguageID as ParentLanguageID, la1.SpokenLanguageID as SpokenLanguageID, la1.LatestChangeStamp as LatestChangeStamp FROM Language la1'));
52:
53: $session = new Session($engine);
54: $all = $session->objects('Alchemy\tests\Language')->all();
55: }
56: }
57: