Skip to content

Commit

Permalink
Now testing the otherwise node. This test also forced me to add suppo…
Browse files Browse the repository at this point in the history
…rt for another binary node. The rest of the binary nodes will get added later.
  • Loading branch information
Tom Krush committed Feb 7, 2011
1 parent 6f02633 commit a78dff6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions bella/nodes.php
Expand Up @@ -15,6 +15,7 @@
require_once 'nodes/number.php';
require_once 'nodes/offset.php';
require_once 'nodes/or.php';
require_once 'nodes/lessthan.php';
require_once 'nodes/ordering.php';
require_once 'nodes/selectstatement.php';
require_once 'nodes/sqlliteral.php';
Expand Down
3 changes: 3 additions & 0 deletions bella/nodes/lessthan.php
@@ -0,0 +1,3 @@
<?php

class NodeBinaryLessThan extends NodeBinary {}
8 changes: 4 additions & 4 deletions bella/nodes/sqlliteral.php
Expand Up @@ -171,17 +171,17 @@ public function lteg_all($others)
return $this->grouping_all('lteg', $others);
}

public function glt($other)
public function lt($other)
{
return new NodeLessThan($this, $other);
return new NodeBinaryLessThan($this, $other);
}

public function glt_any($others)
public function lt_any($others)
{
return $this->grouping_any('glt', $others);
}

public function glt_all($others)
public function lt_all($others)
{
return $this->grouping_all('glt', $others);
}
Expand Down
9 changes: 9 additions & 0 deletions bella/tests/TableTestCase.php
Expand Up @@ -34,6 +34,15 @@ public function test_table_complex_where()
$this->assertEquals('SELECT * FROM users WHERE (project_id = 1 OR project_id = 4)', $query->to_sql(), 'should produce a statement');
}

public function test_table_where_or()
{
$users = new Table('users');
$query = $users->where($users['name']->eq('bob')->otherwise($users['age']->lt(25)));

$this->assertEquals("SELECT FROM users WHERE (name = bob OR age < 25)", $query->to_sql(), 'should produce a statement');
}


public function test_table_having()
{
$users = new Table('users');
Expand Down
8 changes: 8 additions & 0 deletions bella/visitors.php
Expand Up @@ -93,6 +93,14 @@ public function visitBinaryAnd(NodeBinaryAnd $node)
return "{$left} AND {$right}";
}

public function visitBinaryLessThan(NodeBinaryLessThan $node)
{
$left = $this->visit($node->left);
$right = $this->visit($node->right);

return "{$left} < {$right}";
}

public function visitGrouping(NodeGrouping $node)
{
$expression = $this->visit($node->expression);
Expand Down

0 comments on commit a78dff6

Please sign in to comment.