PHP Classes

File: tests/eMapper/PostgreSQL/QueryTest.php

Recommend this page to a friend!
  Classes of Emmanuel Antico   eMapper   tests/eMapper/PostgreSQL/QueryTest.php   Download  
File: tests/eMapper/PostgreSQL/QueryTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: eMapper
Database abstraction layer that maps data types
Author: By
Last change:
Date: 9 years ago
Size: 2,391 bytes
 

Contents

Class file image Download
<?php
namespace eMapper\PostgreSQL;

use
eMapper\AbstractQueryTest;
use
eMapper\Engine\PostgreSQL\PostgreSQLDriver;
use
eMapper\Reflection\Profiler;
use
eMapper\Query\Builder\SelectQueryBuilder;
use
eMapper\Query\Attr;

/**
 * PostgreSQL query test
 * @author emaphp
 * @group postgre
 * @group query
 */
class QueryTest extends AbstractQueryTest {
    public function
build() {
       
$connection_string = PostgreSQLTest::$connstring;
       
$this->driver = new PostgreSQLDriver($connection_string);
       
$this->profile = Profiler::getClassProfile('Acme\Entity\Product');
    }
   
   
//SELECT regex
   
public function testRegex() {
       
$query = new SelectQueryBuilder($this->profile);
       
$query->setCondition(Attr::code()->matches('^(An?|The) +'));
        list(
$query, $args) = $query->build($this->driver, []);
       
$this->assertRegExpMatch("/SELECT \* FROM @@products WHERE product_code ~ #\{([\w]+)\}/", $query, $matches);
       
$index = $matches[1];
       
$this->assertArrayHasKey($index, $args);
       
$this->assertEquals('^(An?|The) +', $args[$index]);
    }
   
    public function
testNotRegex() {
       
$query = new SelectQueryBuilder($this->profile);
       
$query->setCondition(Attr::code()->matches('^(An?|The) +', false));
        list(
$query, $args) = $query->build($this->driver, []);
       
$this->assertRegExpMatch("/SELECT \* FROM @@products WHERE product_code !~ #\{([\w]+)\}/", $query, $matches);
       
$index = $matches[1];
       
$this->assertArrayHasKey($index, $args);
       
$this->assertEquals('^(An?|The) +', $args[$index]);
    }
   
   
//SELECT iregex
   
public function testIRegex() {
       
$query = new SelectQueryBuilder($this->profile);
       
$query->setCondition(Attr::code()->imatches('^(an?|the) +'));
        list(
$query, $args) = $query->build($this->driver, []);
       
$this->assertRegExpMatch("/SELECT \* FROM @@products WHERE product_code ~\* #\{([\w]+)\}/", $query, $matches);
       
$index = $matches[1];
       
$this->assertArrayHasKey($index, $args);
       
$this->assertEquals('^(an?|the) +', $args[$index]);
    }
   
    public function
testNotIRegex() {
       
$query = new SelectQueryBuilder($this->profile);
       
$query->setCondition(Attr::code()->imatches('^(an?|the) +', false));
        list(
$query, $args) = $query->build($this->driver, []);
       
$this->assertRegExpMatch("/SELECT \* FROM @@products WHERE product_code !~\* #\{([\w]+)\}/", $query, $matches);
       
$index = $matches[1];
       
$this->assertArrayHasKey($index, $args);
       
$this->assertEquals('^(an?|the) +', $args[$index]);
    }
}
?>