Beispiel #1
0
 public function testIsDirtyFlag()
 {
     $conn = m::mock('\\SimpleAR\\Database\\Connection[insert]');
     $conn->shouldReceive('insert')->once()->andReturn(12);
     DB::setConnection($conn);
     $article = new Article();
     $this->assertFalse($article->isDirty());
     $article->foo = 'bar';
     $this->assertTrue($article->isDirty());
     $article->save();
     $this->assertFalse($article->isDirty());
 }
Beispiel #2
0
 /**
  * Get the connection instance.
  *
  * @return Connection
  */
 public function getConnection()
 {
     return $this->_connection = $this->_connection ?: DB::getConnection();
 }
 public function testDistinctObject()
 {
     $b = new SelectBuilder();
     $b->root('Article');
     $b->count(DB::distinct(Article::table()->getPrimaryKey()));
     $b->select(['*'], false);
     $components = $b->build();
     $c = new BaseCompiler();
     $sql = $c->compileSelect($components);
     $expected = 'SELECT * ,COUNT(DISTINCT `id`) FROM `articles`';
     $this->assertEquals($expected, $sql);
 }
 /**
  * @covers ::whereFunc
  */
 public function testWhereFunc()
 {
     $b = new WhereBuilder();
     $b->root('Author');
     $b->whereFunc(DB::avg('age'), '>', 30);
     $components = $b->build();
     $expr = new FuncExpr('age', 'AVG');
     $expr->setValue(['age']);
     $where = [['type' => 'Basic', 'table' => '_', 'cols' => [$expr], 'op' => '>', 'val' => 30, 'logic' => 'AND', 'not' => false]];
     $this->assertEquals($where, $components['where']);
 }