Overview

Namespaces

  • Alchemy
    • core
      • query
      • schema
    • dialect
    • engine
    • orm
    • tests
    • util
      • promise
  • PHP

Classes

  • ANSICompilerTest
  • ANSIDeleteTest
  • ANSIInsertTest
  • ANSISelectTest
  • ANSIUpdateTest
  • BaseTest
  • ColumnTypeTest
  • CompilerTest
  • DataTypeLexerTest
  • ElementTest
  • ExpressionTest
  • ForeignTest
  • InsertTest
  • Language
  • MapperTest
  • MockElement
  • MockPromisable
  • ORMQueryTest
  • PromiseTest
  • QueryTest
  • RelationshipTest
  • ScalarTest
  • SessionIntegrationTest
  • SignalTest
  • UploadedFile
  • WaitableTest
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace Alchemy\tests;
 4: use Alchemy\core\query\Expression;
 5: use Alchemy\core\query\Scalar;
 6: use Alchemy\core\query\Predicate;
 7: 
 8: 
 9: class ExpressionTest extends BaseTest {
10: 
11:     public function testGetParameters() {
12:         Expression::define('many', null, array('arity' => -1));
13: 
14:         $expr = Expression::many(
15:             new Scalar(5),
16:             Expression::many(
17:                 new Scalar(9),
18:                 new Scalar(3)) );
19: 
20:         $scalars = $expr->parameters();
21:         $this->assertEquals(3, count($scalars));
22:         $this->assertEquals(5, $scalars[0]->getValue());
23:         $this->assertEquals(3, $scalars[2]->getValue());
24:     }
25: 
26: 
27:     public function testStaticOperators() {
28:         $this->assertInstanceOf('Alchemy\core\query\Predicate', Expression::AND_());
29:     }
30: 
31: 
32:     public function testRoleChecks() {
33:         $int  = new Scalar(3);
34:         $prd  = Predicate::isNull($int);
35: 
36:         Expression::define('zero', null, array('arity' => 0));
37:         Expression::define('one',  null, array('arity' => 1));
38:         Expression::define('many', null, array('arity' => -1));
39: 
40:         $expr = Expression::zero();
41:         $expr = Expression::one ($int);
42:         $expr = Expression::many();
43:         $expr = Expression::many($int, $int, $int);
44:         $this->assertEquals(true, $expr->getTag('expr.value'));
45: 
46:         // tag check fail
47:         $this->assertThrows('Exception', function() use ($prd) {
48:             $expr = Expression::many($prd);
49:         });
50: 
51:         // arity fail
52:         $this->assertThrows('Exception', function() use ($int) {
53:             $expr = Expression::one();
54:         });
55: 
56:         $this->assertThrows('Exception', function() use ($int) {
57:             $expr = Expression::zero($int);
58:         });
59:     }
60: 
61: 
62:     public function testPredicateAll() {
63:         $lt = Predicate::lt(new Scalar(2), new Scalar(5));
64:         $eq = Predicate::equal(new Scalar(4), new Scalar(4));
65:         $and = Predicate::AND_($lt, $eq);
66:         $or = Predicate::OR_($eq, $lt);
67: 
68:         $all = Predicate::AND_($lt, $eq, $or, $eq);
69:         $this->assertEquals($all, Predicate::all(array($lt, $eq, $or, $eq)));
70:         $this->assertEquals($all, Predicate::all(array(array($lt, array($eq, $or)), array($eq))));
71:         $this->assertEquals($all, Predicate::all(array($and), $or, array($eq)));
72:         $this->assertEquals($all, Predicate::all(Predicate::AND_($and, $or, $eq)));
73: 
74:         $this->assertEquals($lt, Predicate::all($lt));
75:         $this->assertEquals($and, Predicate::all($and));
76:     }
77: }
78: 
API documentation generated by ApiGen 2.8.0