Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / PostgreSQLIdentityStrategyTest.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional;
4
5 use Doctrine\ORM\Event\PreUpdateEventArgs;
6
7 require_once __DIR__ . '/../../TestInit.php';
8
9 class PostgreSQLIdentityStrategyTest extends \Doctrine\Tests\OrmFunctionalTestCase
10 {
11     protected function setUp() {
12         parent::setUp();
13         if ($this->_em->getConnection()->getDatabasePlatform()->getName() != 'postgresql') {
14             $this->markTestSkipped('This test is special to the PostgreSQL IDENTITY key generation strategy.');
15         } else {
16             try {
17                 $this->_schemaTool->createSchema(array(
18                         $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\PostgreSQLIdentityEntity'),
19                 ));
20             } catch (\Exception $e) {
21                 // Swallow all exceptions. We do not test the schema tool here.
22             }
23         }
24     }
25
26     protected function tearDown() {
27         parent::tearDown();
28         // drop sequence manually due to dependency
29         $this->_em->getConnection()->exec('DROP SEQUENCE postgresqlidentityentity_id_seq CASCADE');
30     }
31
32     public function testPreSavePostSaveCallbacksAreInvoked()
33     {
34         $entity = new PostgreSQLIdentityEntity();
35         $entity->setValue('hello');
36         $this->_em->persist($entity);
37         $this->_em->flush();
38         $this->assertTrue(is_numeric($entity->getId()));
39         $this->assertTrue($entity->getId() > 0);
40         $this->assertTrue($this->_em->contains($entity));
41     }
42 }
43
44 /** @Entity */
45 class PostgreSQLIdentityEntity {
46     /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */
47     private $id;
48     /** @Column(type="string") */
49     private $value;
50     public function getId() {return $this->id;}
51     public function getValue() {return $this->value;}
52     public function setValue($value) {$this->value = $value;}
53 }