From 55882ca7a646d4c1c908a9b7bc3fd7b8345f658a Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Sat, 27 May 2017 15:56:57 +0200 Subject: [PATCH] #6464 add test --- .../ORM/Functional/Ticket/GH6464Test.php | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php new file mode 100644 index 000000000..a69166d5d --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6464Test.php @@ -0,0 +1,89 @@ +_schemaTool->createSchema( + [ + $this->_em->getClassMetadata(GH6464Post::class), + $this->_em->getClassMetadata(GH6464User::class), + $this->_em->getClassMetadata(GH6464Author::class), + ] + ); + } + + /** + * Verifies that SqlWalker generates valid SQL for an INNER JOIN to CTI table + * + * SqlWalker needs to generate nested INNER JOIN statements, otherwise there would be INNER JOIN + * statements without an ON clause, which are valid on e.g. MySQL but rejected by PostgreSQL. + */ + public function testIssue() + { + + $qb = $this->_em->createQueryBuilder(); + + $query = $qb + ->select('p', 'a') + ->from(GH6464Post::class, 'p') + ->innerJoin(GH6464Author::class, 'a', 'WITH', 'p.authorId = a.id') + ->getQuery(); + + $this->assertNotRegExp( + '/INNER JOIN \w+ \w+ INNER JOIN/', + $query->getSQL(), + 'As of GH-6464, every INNER JOIN should have an ON clause, which is missing here' + ); + + // Query shouldn't yield a result, yet it shouldn't crash (anymore) + $this->assertEquals([], $query->getResult()); + } +} + +/** @Entity */ +class GH6464Post +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; + + /** @Column(type="integer") */ + public $authorId; + + /** @Column(length=100) */ + public $title; + + /** @Column(type="text") */ + public $text; +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorColumn(name="discr", type="string") + * @DiscriminatorMap({"author" = "GH6464Author"}) + */ +abstract class GH6464User +{ + /** @Id @Column(type="integer") @GeneratedValue */ + public $id; +} + +/** @Entity */ +class GH6464Author extends GH6464User +{ + /** @Column(length=50) */ + public $displayName; +}