Commit 67947934 authored by Benjamin Eberlei's avatar Benjamin Eberlei

DDC-697 - Added more tests for Type Conversion during execution

parent 53209d99
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
namespace Doctrine\Tests\DBAL\Functional; namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Types\Type;
use PDO;
require_once __DIR__ . '/../../TestInit.php'; require_once __DIR__ . '/../../TestInit.php';
class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
...@@ -15,11 +18,12 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -15,11 +18,12 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table = new \Doctrine\DBAL\Schema\Table("fetch_table"); $table = new \Doctrine\DBAL\Schema\Table("fetch_table");
$table->addColumn('test_int', 'integer'); $table->addColumn('test_int', 'integer');
$table->addColumn('test_string', 'string'); $table->addColumn('test_string', 'string');
$table->addColumn('test_datetime', 'datetime', array('notnull' => false));
$sm = $this->_conn->getSchemaManager(); $sm = $this->_conn->getSchemaManager();
$sm->createTable($table); $sm->createTable($table);
$this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo')); $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10'));
} catch(\Exception $e) { } catch(\Exception $e) {
} }
...@@ -167,4 +171,52 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -167,4 +171,52 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->assertEquals('foo', $testString); $this->assertEquals('foo', $testString);
} }
/**
* @group DDC-697
*/
public function testExecuteQueryBindDateTimeType()
{
$sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?';
$stmt = $this->_conn->executeQuery($sql,
array(1 => new \DateTime('2010-01-01 10:10:10')),
array(1 => Type::DATETIME)
);
$this->assertEquals(1, $stmt->fetchColumn());
}
/**
* @group DDC-697
*/
public function testExecuteUpdateBindDateTimeType()
{
$datetime = new \DateTime('2010-02-02 20:20:20');
$sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)';
$affectedRows = $this->_conn->executeUpdate($sql,
array(1 => 1, 2 => 'foo', 3 => $datetime),
array(1 => PDO::PARAM_INT, 2 => PDO::PARAM_STR, 3 => Type::DATETIME)
);
$this->assertEquals(1, $affectedRows);
$this->assertEquals(1, $this->_conn->executeQuery(
'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?',
array(1 => $datetime),
array(1 => Type::DATETIME)
)->fetchColumn());
}
/**
* @group DDC-697
*/
public function testPrepareQueryBindValueDateTimeType()
{
$sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?';
$stmt = $this->_conn->prepare($sql);
$stmt->bindValue(1, new \DateTime('2010-01-01 10:10:10'), Type::DATETIME);
$stmt->execute();
$this->assertEquals(1, $stmt->fetchColumn());
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment