/**
  * test query builder interface without proxy, dynamic
  *
  * @return void
  */
 public function testWithDynamicAndProxy()
 {
     $params = ['some' => 'some'];
     $processor = m::mock('Illuminate\\Database\\Query\\Processors\\Processor');
     $processor->shouldReceive('processSelect')->andReturn([['id' => 1]]);
     $processor->shouldReceive('processInsertGetId')->andReturn(1);
     $grammar = m::mock('Illuminate\\Database\\Query\\Grammars\\Grammar');
     $grammar->shouldReceive('compileInsert')->andReturn('insert into table');
     $grammar->shouldReceive('compileInsertGetId')->andReturn('insert into table');
     $grammar->shouldReceive('compileUpdate')->andReturn('update table set');
     $grammar->shouldReceive('compileDelete')->andReturn('delete from table');
     $grammar->shouldReceive('compileSelect')->andReturn('select * from table');
     $schemaBuilder = m::mock('Illuminate\\Database\\Schema\\Builder');
     $schemaBuilder->shouldReceive('getColumnListing')->andReturn(['some']);
     $connection = m::mock('Illuminate\\Database\\Connection');
     $connection->shouldReceive('getPostProcessor')->andReturn($processor);
     $connection->shouldReceive('getQueryGrammar')->andReturn($grammar);
     $connection->shouldReceive('getSchemaBuilder')->andReturn($schemaBuilder);
     $proxyManager = m::mock('Xpressengine\\Database\\ProxyManager');
     $proxyManager->shouldReceive('set');
     $proxyManager->shouldReceive('insert');
     $proxyManager->shouldReceive('update');
     $proxyManager->shouldReceive('delete');
     $proxyManager->shouldReceive('wheres');
     $proxyManager->shouldReceive('orders');
     $connector = m::mock('Xpressengine\\Database\\VirtualConnection');
     $connector->shouldReceive('getDefaultConnection')->andReturn($connection);
     $connector->shouldReceive('getSchemaBuilder')->andReturn($schemaBuilder);
     $connector->shouldReceive('getProxyManager')->andReturn($proxyManager);
     $connector->shouldReceive('insert')->andReturn(true);
     $connector->shouldReceive('insertGetId')->andReturn(1);
     $connector->shouldReceive('update')->andReturn(1);
     $connector->shouldReceive('delete')->andReturn(1);
     $connector->shouldReceive('select')->andReturn(1);
     $connector->shouldReceive('getSchema')->andReturn($params);
     /** @var \Xpressengine\Database\VirtualConnection $connector */
     $query = new DynamicQuery($connector, $grammar, $processor);
     $query->useProxy(true);
     $this->assertEquals(true, $query->insert($params));
     $this->assertEquals(1, $query->insertGetId($params));
     $this->assertEquals(true, $query->update($params));
     $this->assertEquals(true, $query->delete($params));
     $this->assertInstanceOf('Xpressengine\\Database\\DynamicQuery', $query->where([]));
     $proxyManager->shouldReceive('get');
     $proxyManager->shouldReceive('first');
     $this->assertEquals([['id' => 1]], $query->get());
     $this->assertEquals(['id' => 1], $query->first());
 }
Пример #2
0
 /**
  * For period search
  *
  * @param DynamicQuery $query xe database query builder
  * @param string       $since since datetime
  * @param string       $until until datetime
  * @return void
  */
 private function periodWhere(DynamicQuery &$query, $since, $until)
 {
     if ($since !== null && $until !== null) {
         $query->whereBetween('used.createdAt', [$since, $until]);
     } elseif ($since !== null) {
         $query->where('used.createdAt', '>', $since);
     } elseif ($until !== null) {
         $query->where('used.createdAt', '<', $until);
     }
 }