2010-04-07 22:39:34 +04:00
|
|
|
<?php
|
|
|
|
|
2010-05-14 22:38:35 +04:00
|
|
|
namespace Doctrine\Tests\DBAL\Functional;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
2010-04-07 22:39:34 +04:00
|
|
|
|
|
|
|
class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
try {
|
|
|
|
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
|
|
|
|
$table = new \Doctrine\DBAL\Schema\Table("fetch_table");
|
|
|
|
$table->addColumn('test_int', 'integer');
|
|
|
|
$table->addColumn('test_string', 'string');
|
|
|
|
|
|
|
|
$sm = $this->_conn->getSchemaManager();
|
|
|
|
$sm->createTable($table);
|
|
|
|
|
|
|
|
$this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo'));
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFetchAll()
|
|
|
|
{
|
|
|
|
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
|
|
|
$data = $this->_conn->fetchAll($sql, array(1, 'foo'));
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($data));
|
|
|
|
|
|
|
|
$row = $data[0];
|
|
|
|
$this->assertEquals(2, count($row));
|
|
|
|
|
|
|
|
$row = array_change_key_case($row, \CASE_LOWER);
|
|
|
|
$this->assertEquals(1, $row['test_int']);
|
|
|
|
$this->assertEquals('foo', $row['test_string']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFetchRow()
|
|
|
|
{
|
|
|
|
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
2010-05-14 22:33:42 +04:00
|
|
|
$row = $this->_conn->fetchAssoc($sql, array(1, 'foo'));
|
2010-04-07 22:39:34 +04:00
|
|
|
|
|
|
|
$row = array_change_key_case($row, \CASE_LOWER);
|
|
|
|
|
|
|
|
$this->assertEquals(1, $row['test_int']);
|
|
|
|
$this->assertEquals('foo', $row['test_string']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFetchArray()
|
|
|
|
{
|
|
|
|
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
|
|
|
|
$row = $this->_conn->fetchArray($sql, array(1, 'foo'));
|
|
|
|
|
|
|
|
$this->assertEquals(1, $row[0]);
|
|
|
|
$this->assertEquals('foo', $row[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|