1: <?php
2:
3: namespace Alchemy\tests;
4: use Alchemy\core\schema\Table;
5: use Alchemy\core\query\Scalar;
6: use Alchemy\core\query\Query;
7: use Alchemy\core\query\Expression as E;
8:
9:
10: class QueryTest extends BaseTest {
11:
12: public function testGetParams() {
13: $users = Table::Core('users', array(
14: 'columns' => array(
15: 'UserID' => 'Integer(11)',
16: 'UserName' => 'String',
17: 'Email' => 'String')
18: ));
19:
20: $addrs = Table::Core('addresses', array(
21: 'columns' => array(
22: 'UserID' => 'Integer',
23: 'AddressType' => 'Integer',
24: 'StreetAddress' => 'String')
25: ));
26:
27: $phones = Table::Core('phones', array(
28: 'columns' => array(
29: 'UserID' => 'Integer',
30: 'PhoneNum' => 'String')
31: ));
32:
33: $addrs = $addrs->getRef();
34: $users = $users->getRef();
35: $phones = $phones->getRef();
36:
37: $query = Query::Core($users)
38: ->columns(array('Scalar', "value"), $users->UserName)
39: ->join($addrs, E::AND_(
40: $addrs->UserID->equal($users->UserID),
41: $addrs->AddressType->equal(5) ))
42: ->join($phones,
43: $phones->UserID->equal($users->UserID));
44:
45: $query->Aliased = $addrs->StreetAddress;
46: $query->PhoneNum = $phones->PhoneNum;
47: $query->Function = E::LOWER($users->UserName);
48:
49: $params = array(new Scalar("value"), new Scalar(5));
50: $this->assertEquals($params, $query->parameters());
51:
52: $columns = array(
53: 'UserName' => $users->UserName,
54: 'Aliased' => $addrs->StreetAddress,
55: 'PhoneNum' => $phones->PhoneNum,
56: 'Scalar' => new Scalar("value"),
57: 'Function' => E::LOWER($users->UserName));
58: $this->assertEquals($columns, $query->columns());
59: }
60: }
61: