Skip to content

Commit

Permalink
Merge branch '3.1' into 3.2
Browse files Browse the repository at this point in the history
* 3.1:
  Skip test when iconv extension is missing
  Fix bundle commands are not available via find()
  • Loading branch information
fabpot committed Dec 10, 2016
2 parents c7ec4be + 3ff118a commit fef1546
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Console/Application.php
Expand Up @@ -80,6 +80,16 @@ public function doRun(InputInterface $input, OutputInterface $output)
return parent::doRun($input, $output);
}

/**
* {@inheritdoc}
*/
public function find($name)
{
$this->registerCommands();

return parent::find($name);
}

/**
* {@inheritdoc}
*/
Expand Down
Expand Up @@ -32,8 +32,7 @@ public function testBundleInterfaceImplementation()

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);

Expand All @@ -46,8 +45,7 @@ public function testBundleCommandsAreRegistered()

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));

Expand All @@ -60,47 +58,41 @@ public function testBundleCommandsAreRetrievable()

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'));
}

Expand Down Expand Up @@ -167,4 +159,18 @@ private function getKernel(array $bundles, $useDispatcher = false)

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;
}
}
6 changes: 6 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Expand Up @@ -238,7 +238,13 @@ public function testAddContent()
$crawler = new Crawler();
$crawler->addContent('<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><span>中文</span></html>');
$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', '<html><head><meta charset="Shift_JIS"></head><body>日本語</body></html>'));
$this->assertEquals('日本語', $crawler->filterXPath('//body')->text(), '->addContent() can recognize "Shift_JIS" in html5 meta charset tag');
Expand Down

0 comments on commit fef1546

Please sign in to comment.