Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Functional / BlobTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Functional;
4
5 use Doctrine\DBAL\Types\Type;
6 use Doctrine\DBAL\Connection;
7 use PDO;
8
9 require_once __DIR__ . '/../../TestInit.php';
10
11 /**
12  * @group DBAL-6
13  */
14 class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase
15 {
16     public function setUp()
17     {
18         parent::setUp();
19
20         try {
21             /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
22             $table = new \Doctrine\DBAL\Schema\Table("blob_table");
23             $table->addColumn('id', 'integer');
24             $table->addColumn('clobfield', 'text');
25             $table->addColumn('blobfield', 'blob');
26             $table->setPrimaryKey(array('id'));
27
28             $sm = $this->_conn->getSchemaManager();
29             $sm->createTable($table);
30         } catch(\Exception $e) {
31
32         }
33         $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('blob_table'));
34     }
35
36     public function testInsert()
37     {
38         $ret = $this->_conn->insert('blob_table',
39             array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
40             array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
41         );
42         $this->assertEquals(1, $ret);
43     }
44
45     public function testSelect()
46     {
47         $ret = $this->_conn->insert('blob_table',
48             array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
49             array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
50         );
51
52         $this->assertBlobContains('test');
53     }
54
55     public function testUpdate()
56     {
57         $ret = $this->_conn->insert('blob_table',
58             array('id' => 1, 'clobfield' => 'test', 'blobfield' => 'test'),
59             array(\PDO::PARAM_INT, \PDO::PARAM_STR, \PDO::PARAM_LOB)
60         );
61
62         $this->_conn->update('blob_table',
63             array('blobfield' => 'test2'),
64             array('id' => 1),
65             array(\PDO::PARAM_LOB, \PDO::PARAM_INT)
66         );
67
68         $this->assertBlobContains('test2');
69     }
70
71     private function assertBlobContains($text)
72     {
73         $rows = $this->_conn->fetchAll('SELECT * FROM blob_table');
74
75         $this->assertEquals(1, count($rows));
76         $row = array_change_key_case($rows[0], CASE_LOWER);
77
78         $blobValue = Type::getType('blob')->convertToPHPValue($row['blobfield'], $this->_conn->getDatabasePlatform());
79
80         $this->assertInternalType('resource', $blobValue);
81         $this->assertEquals($text, stream_get_contents($blobValue));
82     }
83 }