diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 77106ec7d..568a960a4 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -67,7 +67,9 @@ class SchemaTool /** * Creates the database schema for the given array of ClassMetadata instances. * + * @throws ToolsException * @param array $classes + * @return void */ public function createSchema(array $classes) { @@ -75,7 +77,11 @@ class SchemaTool $conn = $this->_em->getConnection(); foreach ($createSchemaSql as $sql) { - $conn->executeQuery($sql); + try { + $conn->executeQuery($sql); + } catch(\Exception $e) { + throw ToolsException::schemaToolFailure($sql, $e); + } } } @@ -94,7 +100,7 @@ class SchemaTool /** * Some instances of ClassMetadata don't need to be processed in the SchemaTool context. This method detects them. - * + * * @param ClassMetadata $class * @param array $processedClasses * @return bool @@ -551,7 +557,7 @@ class SchemaTool try { $conn->executeQuery($sql); } catch(\Exception $e) { - + } } } @@ -589,7 +595,7 @@ class SchemaTool /** * Get SQL to drop the tables defined by the passed classes. - * + * * @param array $classes * @return array */ @@ -615,7 +621,7 @@ class SchemaTool } } } - + if ($this->_platform->supportsSequences()) { foreach ($schema->getSequences() AS $sequence) { $visitor->acceptSequence($sequence); @@ -659,7 +665,7 @@ class SchemaTool /** * Gets the sequence of SQL statements that need to be performed in order * to bring the given class mappings in-synch with the relational schema. - * If $saveMode is set to true the command is executed in the Database, + * If $saveMode is set to true the command is executed in the Database, * else SQL is returned. * * @param array $classes The classes to consider. diff --git a/lib/Doctrine/ORM/Tools/ToolsException.php b/lib/Doctrine/ORM/Tools/ToolsException.php index f7ed87105..4551d87da 100644 --- a/lib/Doctrine/ORM/Tools/ToolsException.php +++ b/lib/Doctrine/ORM/Tools/ToolsException.php @@ -1,11 +1,38 @@ . + */ namespace Doctrine\ORM\Tools; use Doctrine\ORM\ORMException; +/** + * Tools related Exceptions + * + * @author Benjamin Eberlei + */ 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) { return new self("Could not map doctrine 1 type '$type'!"); diff --git a/tests/Doctrine/Tests/Models/Legacy/LegacyUser.php b/tests/Doctrine/Tests/Models/Legacy/LegacyUser.php index f4f5e1fcb..3e3deedb1 100644 --- a/tests/Doctrine/Tests/Models/Legacy/LegacyUser.php +++ b/tests/Doctrine/Tests/Models/Legacy/LegacyUser.php @@ -21,7 +21,7 @@ class LegacyUser */ public $_username; /** - * @Column(type="string", length=255) + * @Column(type="string", length=255, name="name") */ public $_name; /** diff --git a/tests/Doctrine/Tests/Models/Legacy/LegacyUserReference.php b/tests/Doctrine/Tests/Models/Legacy/LegacyUserReference.php index c6cd891a1..e666ae196 100644 --- a/tests/Doctrine/Tests/Models/Legacy/LegacyUserReference.php +++ b/tests/Doctrine/Tests/Models/Legacy/LegacyUserReference.php @@ -23,12 +23,12 @@ class LegacyUserReference private $_target; /** - * @column(type="string") + * @column(type="string", name="description") */ private $_description; /** - * @column(type="datetime") + * @column(type="datetime", name="created") */ private $_created; diff --git a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php index 8a5819956..44832fc76 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReadOnlyTest.php @@ -27,14 +27,14 @@ class ReadOnlyTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->flush(); $readOnly->name = "Test2"; - $readOnly->number = 4321; + $readOnly->numericValue = 4321; $this->_em->flush(); $this->_em->clear(); $dbReadOnly = $this->_em->find('Doctrine\Tests\ORM\Functional\ReadOnlyEntity', $readOnly->id); $this->assertEquals("Test1", $dbReadOnly->name); - $this->assertEquals(1234, $dbReadOnly->number); + $this->assertEquals(1234, $dbReadOnly->numericValue); } } @@ -51,11 +51,11 @@ class ReadOnlyEntity /** @column(type="string") */ public $name; /** @Column(type="integer") */ - public $number; + public $numericValue; public function __construct($name, $number) { $this->name = $name; - $this->number = $number; + $this->numericValue = $number; } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php index 21a042187..93dc0eea6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php @@ -24,7 +24,7 @@ class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase $user->name = "John Galt"; $user->username = "jgalt"; $user->status = "inactive"; - + $article = new CmsArticle(); $article->topic = "This is John Galt speaking!"; $article->text = "Yadda Yadda!"; @@ -44,11 +44,10 @@ class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase ->setParameter('author', $user) ->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) ->setParameter('author', $user) ->setParameter('topic', 'This is John Galt speaking!') - ->setParameter('text', 'Yadda Yadda!') ->getSingleResult(); $this->assertSame($article, $farticle); @@ -70,12 +69,11 @@ class DDC1040Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($article); $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) ->setParameter(1, 'This is John Galt speaking!') ->setParameter(2, $user) ->setParameter(3, $user) - ->setParameter(4, 'Yadda Yadda!') ->getSingleResult(); $this->assertSame($article, $farticle); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php index 472978bc2..bddbbdf44 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php @@ -106,7 +106,7 @@ class DDC1209_3 { /** * @Id - * @Column(type="datetime") + * @Column(type="datetime", name="somedate") */ private $date; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php index 34aef78cf..6e14e2111 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1228Test.php @@ -21,58 +21,58 @@ class DDC1228Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228User'), $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1228Profile'), )); - } catch(\PDOException $e) { - + } catch(\Exception $e) { + } } - + public function testOneToOnePersist() { $user = new DDC1228User; $profile = new DDC1228Profile(); $profile->name = "Foo"; $user->profile = $profile; - + $this->_em->persist($user); $this->_em->persist($profile); $this->_em->flush(); $this->_em->clear(); - + $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); - + $this->assertFalse($user->getProfile()->__isInitialized__, "Proxy is not initialized"); $user->getProfile()->setName("Bar"); $this->assertTrue($user->getProfile()->__isInitialized__, "Proxy is not initialized"); - + $this->assertEquals("Bar", $user->getProfile()->getName()); $this->assertEquals(array("id" => 1, "name" => "Foo"), $this->_em->getUnitOfWork()->getOriginalEntityData($user->getProfile())); - + $this->_em->flush(); $this->_em->clear(); - + $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); $this->assertEquals("Bar", $user->getProfile()->getName()); } - + public function testRefresh() { $user = new DDC1228User; $profile = new DDC1228Profile(); $profile->name = "Foo"; $user->profile = $profile; - + $this->_em->persist($user); $this->_em->persist($profile); $this->_em->flush(); $this->_em->clear(); - + $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1228User', $user->id); - + $this->_em->refresh($user); $user->name = "Baz"; $this->_em->flush(); $this->_em->clear(); - + $user = $this->_em->find(__NAMESPACE__ . '\\DDC1228User', $user->id); $this->assertEquals("Baz", $user->name); } @@ -88,20 +88,20 @@ class DDC1228User * @var int */ public $id; - + /** - * @column(type="string") + * @Column(type="string") * @var string */ - public $name = ''; - + public $name = 'Bar'; + /** * @OneToOne(targetEntity="DDC1228Profile") * @var Profile */ public $profile; - - public function getProfile() + + public function getProfile() { return $this->profile; } @@ -117,13 +117,13 @@ class DDC1228Profile * @var int */ public $id; - + /** * @column(type="string") * @var string */ public $name; - + public function getName() { return $this->name; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php index 467577a43..6783928ef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1238Test.php @@ -19,49 +19,49 @@ class DDC1238Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'), )); - } catch(\PDOException $e) { - + } catch(\Exception $e) { + } } - + public function testIssue() { $user = new DDC1238User; $user->setName("test"); - + $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + $userId = $user->getId(); $this->_em->clear(); - + $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); $this->_em->clear(); - + $userId2 = $user->getId(); $this->assertEquals($userId, $userId2, "This proxy can still be initialized."); } - + public function testIssueProxyClear() { $user = new DDC1238User; $user->setName("test"); - + $this->_em->persist($user); $this->_em->flush(); $this->_em->clear(); - + // force proxy load, getId() doesn't work anymore $user->getName(); $userId = $user->getId(); $this->_em->clear(); - + $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); $this->_em->clear(); - + $user2 = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId); - + // force proxy load, getId() doesn't work anymore $user->getName(); $this->assertNull($user->getId(), "Now this is null, we already have a user instance of that type"); @@ -75,18 +75,18 @@ class DDC1238User { /** @Id @GeneratedValue @Column(type="integer") */ private $id; - + /** * @Column * @var string */ private $name; - + public function getId() { return $this->id; } - + public function getName() { return $this->name; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php index e12ee9ab7..e283b9f1c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php @@ -7,56 +7,56 @@ use DateTime; 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() { parent::setUp(); try { $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1135User'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1135Phone'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335User'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1335Phone'), )); $this->loadFixture(); } catch(\Exception $e) { } } - - + + 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); $result = $query->getResult(); - + $this->assertEquals(sizeof($result), 3); $this->assertArrayHasKey(1, $result); $this->assertArrayHasKey(2, $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); $result = $query->getResult(); - + $this->assertEquals(sizeof($result), 3); $this->assertArrayHasKey('foo@foo.com', $result); $this->assertArrayHasKey('bar@bar.com', $result); $this->assertArrayHasKey('foobar@foobar.com', $result); - + $this->assertEquals(sizeof($result['foo@foo.com']->phones), 3); $this->assertEquals(sizeof($result['bar@bar.com']->phones), 3); $this->assertEquals(sizeof($result['foobar@foobar.com']->phones), 3); - + $this->assertArrayHasKey(1, $result['foo@foo.com']->phones->toArray()); $this->assertArrayHasKey(2, $result['foo@foo.com']->phones->toArray()); $this->assertArrayHasKey(3, $result['foo@foo.com']->phones->toArray()); - + $this->assertArrayHasKey(4, $result['bar@bar.com']->phones->toArray()); $this->assertArrayHasKey(5, $result['bar@bar.com']->phones->toArray()); $this->assertArrayHasKey(6, $result['bar@bar.com']->phones->toArray()); - + $this->assertArrayHasKey(7, $result['foobar@foobar.com']->phones->toArray()); $this->assertArrayHasKey(8, $result['foobar@foobar.com']->phones->toArray()); $this->assertArrayHasKey(9, $result['foobar@foobar.com']->phones->toArray()); @@ -65,77 +65,77 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase public function testTicket() { $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(); $result = $builder->getQuery()->getResult(); - + $this->assertEquals(sizeof($result), 3); $this->assertArrayHasKey(1, $result); $this->assertArrayHasKey(2, $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() { $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(); $result = $builder->getQuery()->getResult(); - + $this->assertEquals(sizeof($result), 3); $this->assertArrayHasKey('foo@foo.com', $result); $this->assertArrayHasKey('bar@bar.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() { $builder = $this->_em->createQueryBuilder(); $builder->select('u','p') - ->from(__NAMESPACE__ . '\DDC1135User', 'u', 'u.email') + ->from(__NAMESPACE__ . '\DDC1335User', 'u', 'u.email') ->join('u.phones', 'p', null, null, 'p.id'); - + $dql = $builder->getQuery()->getDQL(); $result = $builder->getQuery()->getResult(); - + $this->assertEquals(sizeof($result), 3); $this->assertArrayHasKey('foo@foo.com', $result); $this->assertArrayHasKey('bar@bar.com', $result); $this->assertArrayHasKey('foobar@foobar.com', $result); - + $this->assertEquals(sizeof($result['foo@foo.com']->phones), 3); $this->assertEquals(sizeof($result['bar@bar.com']->phones), 3); $this->assertEquals(sizeof($result['foobar@foobar.com']->phones), 3); - + $this->assertArrayHasKey(1, $result['foo@foo.com']->phones->toArray()); $this->assertArrayHasKey(2, $result['foo@foo.com']->phones->toArray()); $this->assertArrayHasKey(3, $result['foo@foo.com']->phones->toArray()); - + $this->assertArrayHasKey(4, $result['bar@bar.com']->phones->toArray()); $this->assertArrayHasKey(5, $result['bar@bar.com']->phones->toArray()); $this->assertArrayHasKey(6, $result['bar@bar.com']->phones->toArray()); - + $this->assertArrayHasKey(7, $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->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() { $p1 = array('11 xxxx-xxxx','11 yyyy-yyyy','11 zzzz-zzzz'); $p2 = array('22 xxxx-xxxx','22 yyyy-yyyy','22 zzzz-zzzz'); $p3 = array('33 xxxx-xxxx','33 yyyy-yyyy','33 zzzz-zzzz'); - - $u1 = new DDC1135User("foo@foo.com", "Foo",$p1); - $u2 = new DDC1135User("bar@bar.com", "Bar",$p2); - $u3 = new DDC1135User("foobar@foobar.com", "Foo Bar",$p3); - + + $u1 = new DDC1335User("foo@foo.com", "Foo",$p1); + $u2 = new DDC1335User("bar@bar.com", "Bar",$p2); + $u3 = new DDC1335User("foobar@foobar.com", "Foo Bar",$p3); + $this->_em->persist($u1); $this->_em->persist($u2); $this->_em->persist($u3); @@ -148,7 +148,7 @@ class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase /** * @Entity */ -class DDC1135User +class DDC1335User { /** * @Id @Column(type="integer") @@ -160,25 +160,25 @@ class DDC1135User * @Column(type="string", unique=true) */ public $email; - + /** * @Column(type="string") */ public $name; - + /** - * @OneToMany(targetEntity="DDC1135Phone", mappedBy="user", cascade={"persist", "remove"}) + * @OneToMany(targetEntity="DDC1335Phone", mappedBy="user", cascade={"persist", "remove"}) */ public $phones; - + public function __construct($email, $name, array $numbers = array()) { $this->name = $name; $this->email = $email; $this->phones = new \Doctrine\Common\Collections\ArrayCollection(); - + 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 */ -class DDC1135Phone +class DDC1335Phone { /** * @Id * @Column(name="id", type="integer") - * @GeneratedValue(strategy="AUTO") + * @GeneratedValue */ 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) */ public $user; @@ -209,6 +209,6 @@ class DDC1135Phone public function __construct($user, $number) { $this->user = $user; - $this->number = $number; + $this->numericalValue = $number; } } \ No newline at end of file