PHP Classes

File: tests/eMapper/PostgreSQL/MapperBuilderTest.php

Recommend this page to a friend!
  Classes of Emmanuel Antico   eMapper   tests/eMapper/PostgreSQL/MapperBuilderTest.php   Download  
File: tests/eMapper/PostgreSQL/MapperBuilderTest.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: Added: Abstract type tests.
Date: 9 years ago
Size: 1,820 bytes
 

Contents

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

use
eMapper\Engine\PostgreSQL\PostgreSQLDriver;
use
eMapper\Mapper;
use
eMapper\PostgreSQL\PostgreSQLConfig;

/**
 * Test building PostgreSQLDriver intances
 *
 * @author emaphp
 * @group postgre
 * @group builder
 */
class MapperBuilderTest extends PostgreSQLTest {
    use
PostgreSQLConfig;
   
/**
     * @expectedException InvalidArgumentException
     */
   
public function testBuildException() {
       
$config = [];
       
$driver = PostgreSQLDriver::build($config);
    }
   
    public function
testArrayBuild() {
       
$config = ['database' => 'emapper_testing', 'host' => 'localhost', 'port' => '5432', 'username' => 'postgres', 'password' => 'c4lpurn14'];
       
$driver = PostgreSQLDriver::build($config);
       
$this->assertInstanceOf('eMapper\Engine\PostgreSQL\PostgreSQLDriver', $driver);
       
       
$mapper = new Mapper($driver);
       
$two = $mapper->type('i')->query("SELECT 1 + 1");
       
$this->assertEquals(2, $two);
       
       
$row = $mapper->type('array')->query("SELECT * FROM users WHERE user_id = 1");
       
$this->assertInternalType('array', $row);
       
       
$row = $mapper->type('object')->query("SELECT * FROM products WHERE product_id = 1");
       
$this->assertInstanceOf('stdClass', $row);
       
$driver->close();
    }
   
    public function
testBuildFromConnection() {
       
$conn = $this->getConnection();
       
$driver = new PostgreSQLDriver($conn);
       
$this->assertInstanceOf('eMapper\Engine\PostgreSQL\PostgreSQLDriver', $driver);
       
       
$mapper = new Mapper($driver);
       
$two = $mapper->type('i')->query("SELECT 1 + 1");
       
$this->assertEquals(2, $two);
       
       
$row = $mapper->type('array')->query("SELECT * FROM users WHERE user_id = 1");
       
$this->assertInternalType('array', $row);
       
       
$row = $mapper->type('object')->query("SELECT * FROM products WHERE product_id = 1");
       
$this->assertInstanceOf('stdClass', $row);
       
pg_close($conn);
    }
}
?>