From 3c2ed7d8a8b9efae037f2f268502b48b8b99c0b4 Mon Sep 17 00:00:00 2001 From: Bob van de Vijver Date: Sat, 17 Jan 2015 13:21:30 +0100 Subject: [PATCH 1/4] Fixes the broken DQL command Now it can again output more than only the created SQL query. See https://github.com/doctrine/doctrine2/commit/cdb62a70cd0baac8357a42bbe42cacdb6784d2aa#comments --- lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php index 000a94d8c51..7cd74c91ef2 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php @@ -120,7 +120,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $query->setMaxResults((int) $maxResult); } - if ($input->hasOption('show-sql')) { + if ($input->hasOption('show-sql') && $input->getOption('show-sql')) { Debug::dump($query->getSQL()); return; } From 1c6fd512a5dc8f5744d89eee4a299430ea9ff2e1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 21:27:32 +0100 Subject: [PATCH 2/4] #1262 DDC-3513 - providing basic coverage for the `RunDqlCommand` logic --- .../Console/Command/RunDqlCommandTest.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php new file mode 100644 index 00000000000..0b4b88ac49a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php @@ -0,0 +1,73 @@ +useModelSet('generic'); + + parent::setUp(); + + $this->application = new Application(); + $this->command = new RunDqlCommand(); + + $this->application->setHelperSet(new HelperSet(array( + 'em' => new EntityManagerHelper($this->_em) + ))); + + $this->application->add($this->command); + + $this->tester = new CommandTester($this->command); + } + + public function testCommandName() + { + $this->assertSame($this->command, $this->application->get('orm:run-dql')); + } + + public function testWillRunQuery() + { + $this->_em->persist(new DateTimeModel()); + $this->_em->flush(); + + $this->assertSame( + 0, + $this->tester->execute(array( + 'command' => $this->command->getName(), + 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e' + )) + ); + + $this->assertContains(DateTimeModel::CLASSNAME, $this->tester->getDisplay()); + } +} From f06d652393dfb1d85199d457156f13bf3f63b947 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 21:30:34 +0100 Subject: [PATCH 3/4] #1262 DDC-3513 - `RunDqlCommand` should display the generated SQL when asked to do so --- .../Console/Command/RunDqlCommandTest.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php index 0b4b88ac49a..534922329d1 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/Command/RunDqlCommandTest.php @@ -64,10 +64,27 @@ public function testWillRunQuery() 0, $this->tester->execute(array( 'command' => $this->command->getName(), - 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e' + 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', )) ); $this->assertContains(DateTimeModel::CLASSNAME, $this->tester->getDisplay()); } + + public function testWillShowQuery() + { + $this->_em->persist(new DateTimeModel()); + $this->_em->flush(); + + $this->assertSame( + 0, + $this->tester->execute(array( + 'command' => $this->command->getName(), + 'dql' => 'SELECT e FROM ' . DateTimeModel::CLASSNAME . ' e', + '--show-sql' => 'true' + )) + ); + + $this->assertStringMatchesFormat('string \'SELECT %a', $this->tester->getDisplay()); + } } From fea0425a4f8e355150f063cc6057ae2cbc69f07e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 21:31:00 +0100 Subject: [PATCH 4/4] #1262 DDC-3513 - `RunDqlCommand` should write to the output object rather than to the output buffer --- lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php index 7cd74c91ef2..abd999aef09 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/RunDqlCommand.php @@ -81,6 +81,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + /* @var $em \Doctrine\ORM\EntityManagerInterface */ $em = $this->getHelper('em')->getEntityManager(); if (($dql = $input->getArgument('dql')) === null) { @@ -120,13 +121,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $query->setMaxResults((int) $maxResult); } - if ($input->hasOption('show-sql') && $input->getOption('show-sql')) { - Debug::dump($query->getSQL()); + if ($input->getOption('show-sql')) { + $output->writeln(Debug::dump($query->getSQL(), 2, true, false)); return; } $resultSet = $query->execute(array(), constant($hydrationMode)); - Debug::dump($resultSet, $input->getOption('depth')); + $output->writeln(Debug::dump($resultSet, $input->getOption('depth'), true, false)); } }