From dd69b8875dc2477a12edc18f1baaf0113c8331b3 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Mon, 7 Nov 2016 20:38:43 +0100 Subject: [PATCH 1/2] Fix bundle commands are not available via find() --- .../FrameworkBundle/Console/Application.php | 10 ++++ .../Tests/Console/ApplicationTest.php | 46 +++++++++++-------- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php index 221a004250..6e6aca6043 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Console/Application.php +++ b/src/Symfony/Bundle/FrameworkBundle/Console/Application.php @@ -90,6 +90,16 @@ class Application extends BaseApplication return parent::doRun($input, $output); } + /** + * {@inheritdoc} + */ + public function find($name) + { + $this->registerCommands(); + + return parent::find($name); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php index fc0e7654db..a944da863f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Console/ApplicationTest.php @@ -32,8 +32,7 @@ class ApplicationTest extends TestCase public function testBundleCommandsAreRegistered() { - $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); - $bundle->expects($this->once())->method('registerCommands'); + $bundle = $this->createBundleMock(array()); $kernel = $this->getKernel(array($bundle), true); @@ -46,8 +45,7 @@ class ApplicationTest extends TestCase public function testBundleCommandsAreRetrievable() { - $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); - $bundle->expects($this->once())->method('registerCommands'); + $bundle = $this->createBundleMock(array()); $kernel = $this->getKernel(array($bundle)); @@ -60,47 +58,41 @@ class ApplicationTest extends TestCase public function testBundleSingleCommandIsRetrievable() { - $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); - $bundle->expects($this->once())->method('registerCommands'); + $command = new Command('example'); + + $bundle = $this->createBundleMock(array($command)); $kernel = $this->getKernel(array($bundle)); $application = new Application($kernel); - $command = new Command('example'); - $application->add($command); - $this->assertSame($command, $application->get('example')); } public function testBundleCommandCanBeFound() { - $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); - $bundle->expects($this->once())->method('registerCommands'); + $command = new Command('example'); + + $bundle = $this->createBundleMock(array($command)); $kernel = $this->getKernel(array($bundle)); $application = new Application($kernel); - $command = new Command('example'); - $application->add($command); - $this->assertSame($command, $application->find('example')); } public function testBundleCommandCanBeFoundByAlias() { - $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); - $bundle->expects($this->once())->method('registerCommands'); + $command = new Command('example'); + $command->setAliases(array('alias')); + + $bundle = $this->createBundleMock(array($command)); $kernel = $this->getKernel(array($bundle)); $application = new Application($kernel); - $command = new Command('example'); - $command->setAliases(array('alias')); - $application->add($command); - $this->assertSame($command, $application->find('alias')); } @@ -167,4 +159,18 @@ class ApplicationTest extends TestCase return $kernel; } + + private function createBundleMock(array $commands) + { + $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\Bundle'); + $bundle + ->expects($this->once()) + ->method('registerCommands') + ->will($this->returnCallback(function (Application $application) use ($commands) { + $application->addCommands($commands); + })) + ; + + return $bundle; + } } From ae7377d12803d02e9d5e2eaef5e738dca7f2c587 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Fri, 9 Dec 2016 18:49:43 +0100 Subject: [PATCH 2/2] Skip test when iconv extension is missing --- src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php index 65e2a90e87..5d5c633888 100755 --- a/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php @@ -206,7 +206,13 @@ EOF $crawler = new Crawler(); $crawler->addContent('中文'); $this->assertEquals('中文', $crawler->filterXPath('//span')->text(), '->addContent() guess wrong charset'); + } + /** + * @requires extension iconv + */ + public function testAddContentNonUtf8() + { $crawler = new Crawler(); $crawler->addContent(iconv('UTF-8', 'SJIS', '日本語')); $this->assertEquals('日本語', $crawler->filterXPath('//body')->text(), '->addContent() can recognize "Shift_JIS" in html5 meta charset tag');