1
0
mirror of synced 2024-12-14 15:16:04 +03:00

DDC-1384 - Fix all tests on Oracle

This commit is contained in:
Benjamin Eberlei 2011-10-29 23:58:09 +02:00
parent 50e028212d
commit 30731e0727
10 changed files with 139 additions and 108 deletions

View File

@ -67,7 +67,9 @@ class SchemaTool
/** /**
* Creates the database schema for the given array of ClassMetadata instances. * Creates the database schema for the given array of ClassMetadata instances.
* *
* @throws ToolsException
* @param array $classes * @param array $classes
* @return void
*/ */
public function createSchema(array $classes) public function createSchema(array $classes)
{ {
@ -75,7 +77,11 @@ class SchemaTool
$conn = $this->_em->getConnection(); $conn = $this->_em->getConnection();
foreach ($createSchemaSql as $sql) { foreach ($createSchemaSql as $sql) {
try {
$conn->executeQuery($sql); $conn->executeQuery($sql);
} catch(\Exception $e) {
throw ToolsException::schemaToolFailure($sql, $e);
}
} }
} }

View File

@ -1,11 +1,38 @@
<?php <?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Tools; namespace Doctrine\ORM\Tools;
use Doctrine\ORM\ORMException; use Doctrine\ORM\ORMException;
/**
* Tools related Exceptions
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class ToolsException extends ORMException class ToolsException extends ORMException
{ {
public static function schemaToolFailure($sql, \Exception $e)
{
return new self("Schema-Tool failed with Error '" . $e->getMessage() . "' while executing DDL: " . $sql, "0", $e);
}
public static function couldNotMapDoctrine1Type($type) public static function couldNotMapDoctrine1Type($type)
{ {
return new self("Could not map doctrine 1 type '$type'!"); return new self("Could not map doctrine 1 type '$type'!");

View File

@ -21,7 +21,7 @@ class LegacyUser
*/ */
public $_username; public $_username;
/** /**
* @Column(type="string", length=255) * @Column(type="string", length=255, name="name")
*/ */
public $_name; public $_name;
/** /**

View File

@ -23,12 +23,12 @@ class LegacyUserReference
private $_target; private $_target;
/** /**
* @column(type="string") * @column(type="string", name="description")
*/ */
private $_description; private $_description;
/** /**
* @column(type="datetime") * @column(type="datetime", name="created")
*/ */
private $_created; private $_created;

View File

@ -27,14 +27,14 @@ class ReadOnlyTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->flush(); $this->_em->flush();
$readOnly->name = "Test2"; $readOnly->name = "Test2";
$readOnly->number = 4321; $readOnly->numericValue = 4321;
$this->_em->flush(); $this->_em->flush();
$this->_em->clear(); $this->_em->clear();
$dbReadOnly = $this->_em->find('Doctrine\Tests\ORM\Functional\ReadOnlyEntity', $readOnly->id); $dbReadOnly = $this->_em->find('Doctrine\Tests\ORM\Functional\ReadOnlyEntity', $readOnly->id);
$this->assertEquals("Test1", $dbReadOnly->name); $this->assertEquals("Test1", $dbReadOnly->name);
$this->assertEquals(1234, $dbReadOnly->number); $this->assertEquals(1234, $dbReadOnly->numericValue);
} }
} }
@ -51,11 +51,11 @@ class ReadOnlyEntity
/** @column(type="string") */ /** @column(type="string") */
public $name; public $name;
/** @Column(type="integer") */ /** @Column(type="integer") */
public $number; public $numericValue;
public function __construct($name, $number) public function __construct($name, $number)
{ {
$this->name = $name; $this->name = $name;
$this->number = $number; $this->numericValue = $number;
} }
} }

View File

@ -44,11 +44,10 @@ class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase
->setParameter('author', $user) ->setParameter('author', $user)
->getResult(); ->getResult();
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = :topic AND a.user = :author AND a.user = :author AND a.text = :text"; $dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = :topic AND a.user = :author AND a.user = :author";
$farticle = $this->_em->createQuery($dql) $farticle = $this->_em->createQuery($dql)
->setParameter('author', $user) ->setParameter('author', $user)
->setParameter('topic', 'This is John Galt speaking!') ->setParameter('topic', 'This is John Galt speaking!')
->setParameter('text', 'Yadda Yadda!')
->getSingleResult(); ->getSingleResult();
$this->assertSame($article, $farticle); $this->assertSame($article, $farticle);
@ -70,12 +69,11 @@ class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->persist($article); $this->_em->persist($article);
$this->_em->flush(); $this->_em->flush();
$dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1 AND a.user = ?2 AND a.user = ?3 AND a.text = ?4"; $dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1 AND a.user = ?2 AND a.user = ?3";
$farticle = $this->_em->createQuery($dql) $farticle = $this->_em->createQuery($dql)
->setParameter(1, 'This is John Galt speaking!') ->setParameter(1, 'This is John Galt speaking!')
->setParameter(2, $user) ->setParameter(2, $user)
->setParameter(3, $user) ->setParameter(3, $user)
->setParameter(4, 'Yadda Yadda!')
->getSingleResult(); ->getSingleResult();
$this->assertSame($article, $farticle); $this->assertSame($article, $farticle);

View File

@ -106,7 +106,7 @@ class DDC1209_3
{ {
/** /**
* @Id * @Id
* @Column(type="datetime") * @Column(type="datetime", name="somedate")
*/ */
private $date; private $date;

View File

@ -21,7 +21,7 @@ class DDC1228Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228User'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228Profile'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228Profile'),
)); ));
} catch(\PDOException $e) { } catch(\Exception $e) {
} }
} }
@ -90,10 +90,10 @@ class DDC1228User
public $id; public $id;
/** /**
* @column(type="string") * @Column(type="string")
* @var string * @var string
*/ */
public $name = ''; public $name = 'Bar';
/** /**
* @OneToOne(targetEntity="DDC1228Profile") * @OneToOne(targetEntity="DDC1228Profile")

View File

@ -19,7 +19,7 @@ class DDC1238Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_schemaTool->createSchema(array( $this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'),
)); ));
} catch(\PDOException $e) { } catch(\Exception $e) {
} }
} }

View File

@ -7,17 +7,17 @@ use DateTime;
require_once __DIR__ . '/../../../TestInit.php'; require_once __DIR__ . '/../../../TestInit.php';
/** /**
* @group DDC-1135 * @group DDC-1335
*/ */
class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase class DDC1335Test extends \Doctrine\Tests\OrmFunctionalTestCase
{ {
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
try { try {
$this->_schemaTool->createSchema(array( $this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1135User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335User'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1135Phone'), $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335Phone'),
)); ));
$this->loadFixture(); $this->loadFixture();
} catch(\Exception $e) { } catch(\Exception $e) {
@ -27,7 +27,7 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
public function testDql() public function testDql()
{ {
$dql = 'SELECT u FROM ' . __NAMESPACE__ . '\DDC1135User u INDEX BY u.id'; $dql = 'SELECT u FROM ' . __NAMESPACE__ . '\DDC1335User u INDEX BY u.id';
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$result = $query->getResult(); $result = $query->getResult();
@ -36,7 +36,7 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertArrayHasKey(2, $result); $this->assertArrayHasKey(2, $result);
$this->assertArrayHasKey(3, $result); $this->assertArrayHasKey(3, $result);
$dql = 'SELECT u, p FROM '.__NAMESPACE__ . '\DDC1135User u INDEX BY u.email INNER JOIN u.phones p INDEX BY p.id'; $dql = 'SELECT u, p FROM '.__NAMESPACE__ . '\DDC1335User u INDEX BY u.email INNER JOIN u.phones p INDEX BY p.id';
$query = $this->_em->createQuery($dql); $query = $this->_em->createQuery($dql);
$result = $query->getResult(); $result = $query->getResult();
@ -65,7 +65,7 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
public function testTicket() public function testTicket()
{ {
$builder = $this->_em->createQueryBuilder(); $builder = $this->_em->createQueryBuilder();
$builder->select('u')->from(__NAMESPACE__ . '\DDC1135User', 'u', 'u.id'); $builder->select('u')->from(__NAMESPACE__ . '\DDC1335User', 'u', 'u.id');
$dql = $builder->getQuery()->getDQL(); $dql = $builder->getQuery()->getDQL();
$result = $builder->getQuery()->getResult(); $result = $builder->getQuery()->getResult();
@ -74,13 +74,13 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertArrayHasKey(1, $result); $this->assertArrayHasKey(1, $result);
$this->assertArrayHasKey(2, $result); $this->assertArrayHasKey(2, $result);
$this->assertArrayHasKey(3, $result); $this->assertArrayHasKey(3, $result);
$this->assertEquals('SELECT u FROM ' . __NAMESPACE__ . '\DDC1135User u INDEX BY u.id', $dql); $this->assertEquals('SELECT u FROM ' . __NAMESPACE__ . '\DDC1335User u INDEX BY u.id', $dql);
} }
public function testIndexByUnique() public function testIndexByUnique()
{ {
$builder = $this->_em->createQueryBuilder(); $builder = $this->_em->createQueryBuilder();
$builder->select('u')->from(__NAMESPACE__ . '\DDC1135User', 'u', 'u.email'); $builder->select('u')->from(__NAMESPACE__ . '\DDC1335User', 'u', 'u.email');
$dql = $builder->getQuery()->getDQL(); $dql = $builder->getQuery()->getDQL();
$result = $builder->getQuery()->getResult(); $result = $builder->getQuery()->getResult();
@ -89,14 +89,14 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertArrayHasKey('foo@foo.com', $result); $this->assertArrayHasKey('foo@foo.com', $result);
$this->assertArrayHasKey('bar@bar.com', $result); $this->assertArrayHasKey('bar@bar.com', $result);
$this->assertArrayHasKey('foobar@foobar.com', $result); $this->assertArrayHasKey('foobar@foobar.com', $result);
$this->assertEquals('SELECT u FROM ' . __NAMESPACE__ . '\DDC1135User u INDEX BY u.email', $dql); $this->assertEquals('SELECT u FROM ' . __NAMESPACE__ . '\DDC1335User u INDEX BY u.email', $dql);
} }
public function testIndexWithJoin() public function testIndexWithJoin()
{ {
$builder = $this->_em->createQueryBuilder(); $builder = $this->_em->createQueryBuilder();
$builder->select('u','p') $builder->select('u','p')
->from(__NAMESPACE__ . '\DDC1135User', 'u', 'u.email') ->from(__NAMESPACE__ . '\DDC1335User', 'u', 'u.email')
->join('u.phones', 'p', null, null, 'p.id'); ->join('u.phones', 'p', null, null, 'p.id');
$dql = $builder->getQuery()->getDQL(); $dql = $builder->getQuery()->getDQL();
@ -123,7 +123,7 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertArrayHasKey(8, $result['foobar@foobar.com']->phones->toArray()); $this->assertArrayHasKey(8, $result['foobar@foobar.com']->phones->toArray());
$this->assertArrayHasKey(9, $result['foobar@foobar.com']->phones->toArray()); $this->assertArrayHasKey(9, $result['foobar@foobar.com']->phones->toArray());
$this->assertEquals('SELECT u, p FROM '.__NAMESPACE__ . '\DDC1135User u INDEX BY u.email INNER JOIN u.phones p INDEX BY p.id', $dql); $this->assertEquals('SELECT u, p FROM '.__NAMESPACE__ . '\DDC1335User u INDEX BY u.email INNER JOIN u.phones p INDEX BY p.id', $dql);
} }
private function loadFixture() private function loadFixture()
@ -132,9 +132,9 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
$p2 = array('22 xxxx-xxxx','22 yyyy-yyyy','22 zzzz-zzzz'); $p2 = array('22 xxxx-xxxx','22 yyyy-yyyy','22 zzzz-zzzz');
$p3 = array('33 xxxx-xxxx','33 yyyy-yyyy','33 zzzz-zzzz'); $p3 = array('33 xxxx-xxxx','33 yyyy-yyyy','33 zzzz-zzzz');
$u1 = new DDC1135User("foo@foo.com", "Foo",$p1); $u1 = new DDC1335User("foo@foo.com", "Foo",$p1);
$u2 = new DDC1135User("bar@bar.com", "Bar",$p2); $u2 = new DDC1335User("bar@bar.com", "Bar",$p2);
$u3 = new DDC1135User("foobar@foobar.com", "Foo Bar",$p3); $u3 = new DDC1335User("foobar@foobar.com", "Foo Bar",$p3);
$this->_em->persist($u1); $this->_em->persist($u1);
$this->_em->persist($u2); $this->_em->persist($u2);
@ -148,7 +148,7 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
/** /**
* @Entity * @Entity
*/ */
class DDC1135User class DDC1335User
{ {
/** /**
* @Id @Column(type="integer") * @Id @Column(type="integer")
@ -167,7 +167,7 @@ class DDC1135User
public $name; public $name;
/** /**
* @OneToMany(targetEntity="DDC1135Phone", mappedBy="user", cascade={"persist", "remove"}) * @OneToMany(targetEntity="DDC1335Phone", mappedBy="user", cascade={"persist", "remove"})
*/ */
public $phones; public $phones;
@ -178,7 +178,7 @@ class DDC1135User
$this->phones = new \Doctrine\Common\Collections\ArrayCollection(); $this->phones = new \Doctrine\Common\Collections\ArrayCollection();
foreach ($numbers as $number) { foreach ($numbers as $number) {
$this->phones->add(new DDC1135Phone($this,$number)); $this->phones->add(new DDC1335Phone($this,$number));
} }
} }
} }
@ -186,22 +186,22 @@ class DDC1135User
/** /**
* @Entity * @Entity
*/ */
class DDC1135Phone class DDC1335Phone
{ {
/** /**
* @Id * @Id
* @Column(name="id", type="integer") * @Column(name="id", type="integer")
* @GeneratedValue(strategy="AUTO") * @GeneratedValue
*/ */
public $id; public $id;
/** /**
* @Column(name="number", type="string", nullable = false) * @Column(name="numericalValue", type="string", nullable = false)
*/ */
public $number; public $numericalValue;
/** /**
* @ManyToOne(targetEntity="DDC1135User", inversedBy="phones") * @ManyToOne(targetEntity="DDC1335User", inversedBy="phones")
* @JoinColumn(name="user_id", referencedColumnName="id", nullable = false) * @JoinColumn(name="user_id", referencedColumnName="id", nullable = false)
*/ */
public $user; public $user;
@ -209,6 +209,6 @@ class DDC1135Phone
public function __construct($user, $number) public function __construct($user, $number)
{ {
$this->user = $user; $this->user = $user;
$this->number = $number; $this->numericalValue = $number;
} }
} }