Skip to content

Commit

Permalink
Merge branch '2.2' into 2.3
Browse files Browse the repository at this point in the history
* 2.2:
  fixes RequestDataCollector bug, visible when used on Drupal8
  [Console] fixed exception rendering when nested styles
  [Console] added some more information about OutputFormatter::replaceStyle()
  [Console] fixed the formatter for single-char tags
  [Console] Escape exception message during the rendering of an exception
  [BrowserKit] Fixed the handling of parameters when redirecting
  Typo fix
  HttpFoundation RequestTest - Fixed indentation and removed comments
  HttpFoundation Request test for symfony#8619
  LICENSE files moved to meta folders
  added missing method in the UPGRADE file for 2.2 (closes symfony#8941)
  [Translation] Removed an unneeded return annotation.
  [DomCrawler] Added missing docblocks and removed unneeded return annotation.

Conflicts:
	src/Symfony/Component/BrowserKit/Client.php
	src/Symfony/Component/DomCrawler/Crawler.php
  • Loading branch information
fabpot committed Sep 18, 2013
2 parents 0ebb8bc + 5ffe1bc commit d182503
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 38 deletions.
5 changes: 3 additions & 2 deletions UPGRADE-2.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,9 @@
}
```

* The method `ExecutionContext::addViolationAtSubPath()` was deprecated and
will be removed in Symfony 2.3. You should use `addViolationAt()` instead.
* The methods `ExecutionContext::addViolationAtSubPath()` and
`ExecutionContext::addViolationAtPath()` were deprecated and will be
removed in Symfony 2.3. You should use `addViolationAt()` instead.

Before:

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion src/Symfony/Component/BrowserKit/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,19 @@ public function followRedirect()
$content = $request->getContent();
}

if ('get' === strtolower($method)) {
// Don't forward parameters for GET request as it should reach the redirection URI
$parameters = array();
} else {
$parameters = $request->getParameters();
}

$server = $request->getServer();
unset($server['HTTP_IF_NONE_MATCH'], $server['HTTP_IF_MODIFIED_SINCE']);

$this->isMainRequest = false;

$response = $this->request($method, $this->redirect, $request->getParameters(), $files, $server, $content);
$response = $this->request($method, $this->redirect, $parameters, $files, $server, $content);

$this->isMainRequest = true;

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/BrowserKit/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,10 @@ public function testFollowRedirectWithMaxRedirects()
$this->assertEquals('http://www.example.com/redirected', $client->getRequest()->getUri(), '->followRedirect() follows a redirect if any');

$client->setNextResponse(new Response('', 302, array('Location' => 'http://www.example.com/redirected')));
$client->request('POST', 'http://www.example.com/foo/foobar');
$client->request('POST', 'http://www.example.com/foo/foobar', array('name' => 'bar'));

$this->assertEquals('get', $client->getRequest()->getMethod(), '->followRedirect() uses a get for 302');
$this->assertEquals(array(), $client->getRequest()->getParameters(), '->followRedirect() does not submit parameters when changing the method');
}

public function testFollowRedirectWithCookies()
Expand Down
28 changes: 14 additions & 14 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,29 +729,29 @@ public function renderException($e, $output)
$title = sprintf(' [%s] ', get_class($e));
$len = $strlen($title);
$width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
$formatter = $output->getFormatter();
$lines = array();
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
foreach (str_split($line, $width - 4) as $line) {
$lines[] = sprintf(' %s ', $line);
$len = max($strlen($line) + 4, $len);
// pre-format lines to get the right string length
$lineLength = $strlen(preg_replace('/\[[^m]*m/', '', $formatter->format($line))) + 4;
$lines[] = array($line, $lineLength);

$len = max($lineLength, $len);
}
}

$messages = array(str_repeat(' ', $len), $title.str_repeat(' ', max(0, $len - $strlen($title))));

$messages = array('', '');
$messages[] = $emptyLine = $formatter->format(sprintf('<error>%s</error>', str_repeat(' ', $len)));
$messages[] = $formatter->format(sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - $strlen($title)))));
foreach ($lines as $line) {
$messages[] = $line.str_repeat(' ', $len - $strlen($line));
$messages[] = $formatter->format(sprintf('<error> %s %s</error>', $line[0], str_repeat(' ', $len - $line[1])));
}
$messages[] = $emptyLine;
$messages[] = '';
$messages[] = '';

$messages[] = str_repeat(' ', $len);

$output->writeln("");
$output->writeln("");
foreach ($messages as $message) {
$output->writeln('<error>'.$message.'</error>');
}
$output->writeln("");
$output->writeln("");
$output->writeln($messages, OutputInterface::OUTPUT_RAW);

if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$output->writeln('<comment>Exception trace:</comment>');
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Console/Formatter/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OutputFormatter implements OutputFormatterInterface
/**
* The pattern to phrase the format.
*/
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?: [^<\\\\]+ | (?!<(?:/?[a-z]|/>)). | .(?<=\\\\<) )*)#isx';
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]*)?>((?: [^<\\\\]+ | (?!<(?:/?[a-z]|/>)). | .(?<=\\\\<) )*)#isx';

private $decorated;
private $styles = array();
Expand Down Expand Up @@ -163,6 +163,8 @@ public function getStyleStack()
/**
* Replaces style of the output.
*
* All escaped tags and tags that reference unknown styles are kept as is.
*
* @param array $match
*
* @return string The replaced style
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@ public function testRenderException()
$tester->run(array('command' => 'foo3:bar'), array('decorated' => false));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');

$tester->run(array('command' => 'foo3:bar'), array('decorated' => true));
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception3decorated.txt', $tester->getDisplay(true), '->renderException() renders a pretty exceptions with previous exceptions');

$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
$application->setAutoExit(false);
$application->expects($this->any())
Expand Down
8 changes: 6 additions & 2 deletions src/Symfony/Component/Console/Tests/Fixtures/Foo3Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
throw new \Exception("First exception");
try {
throw new \Exception("First exception <p>this is html</p>");
} catch (\Exception $e) {
throw new \Exception("Second exception <comment>comment</comment>", 0, $e);
}
} catch (\Exception $e) {
throw new \Exception("Second exception", 0, $e);
throw new \Exception("Third exception <fg=blue;bg=red>comment</>", 0, $e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@



[Exception]
Second exception

[Exception]
Third exception comment





[Exception]
First exception


[Exception]
Second exception comment






[Exception]
First exception <p>this is html</p>



foo3:bar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


 
 [Exception] 
 Third exception comment 
 




 
 [Exception] 
 Second exception comment 
 




 
 [Exception] 
 First exception <p>this is html</p> 
 


foo3:bar


Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public function testNewStyle()
$this->assertEquals($style, $formatter->getStyle('test'));
$this->assertNotEquals($style, $formatter->getStyle('info'));

$this->assertEquals("\033[34;47msome custom msg\033[0m", $formatter->format('<test>some custom msg</test>'));
$style = new OutputFormatterStyle('blue', 'white');
$formatter->setStyle('b', $style);

$this->assertEquals("\033[34;47msome \033[0m\033[34;47mcustom\033[0m\033[34;47m msg\033[0m", $formatter->format('<test>some <b>custom</b> msg</test>'));
}

public function testRedefineStyle()
Expand All @@ -137,7 +140,7 @@ public function testInlineStyle()
public function testNonStyleTag()
{
$formatter = new OutputFormatter(true);
$this->assertEquals("\033[32msome \033[0m\033[32m<tag> styled\033[0m", $formatter->format('<info>some <tag> styled</info>'));
$this->assertEquals("\033[32msome \033[0m\033[32m<tag> styled \033[0m\033[32m<p>single-char tag\033[0m\033[32m</p>\033[0m", $formatter->format('<info>some <tag> styled <p>single-char tag</p></info>'));
}

public function testNotDecoratedFormatter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* PhpFileLoader loads service definitions from a PHP file.
*
* The PHP file is required and the $container variable can be
* used form the file to change the container.
* used within the file to change the container.
*
* @author Fabien Potencier <[email protected]>
*/
Expand Down
13 changes: 11 additions & 2 deletions src/Symfony/Component/DomCrawler/Crawler.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ public function add($node)
*
* @param string $content A string to parse as HTML/XML
* @param null|string $type The content type of the string
*
* @return null|void
*/
public function addContent($content, $type = null)
{
Expand Down Expand Up @@ -749,6 +747,11 @@ public static function xpathLiteral($s)
return sprintf("concat(%s)", implode($parts, ', '));
}

/**
* @param integer $position
*
* @return \DOMElement|null
*/
protected function getNode($position)
{
foreach ($this as $i => $node) {
Expand All @@ -762,6 +765,12 @@ protected function getNode($position)
// @codeCoverageIgnoreEnd
}

/**
* @param \DOMElement $node
* @param string $siblingDir
*
* @return array
*/
protected function sibling($node, $siblingDir = 'nextSibling')
{
$nodes = array();
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,25 @@ public function testGetPort()
$port = $request->getPort();

$this->assertEquals(80, $port, 'If X_FORWARDED_PROTO is set to http return 80.');

$request = Request::create('http://example.com', 'GET', array(), array(), array(), array(
'HTTP_X_FORWARDED_PROTO' => 'On'
));
$port = $request->getPort();
$this->assertEquals(443, $port, 'With only PROTO set and value is On, getPort() defaults to 443.');

$request = Request::create('http://example.com', 'GET', array(), array(), array(), array(
'HTTP_X_FORWARDED_PROTO' => '1'
));
$port = $request->getPort();
$this->assertEquals(443, $port, 'With only PROTO set and value is 1, getPort() defaults to 443.');

$request = Request::create('http://example.com', 'GET', array(), array(), array(), array(
'HTTP_X_FORWARDED_PROTO' => 'something-else'
));
$port = $request->getPort();
$this->assertEquals(80, $port, 'With only PROTO set and value is not recognized, getPort() defaults to 80.');

Request::setTrustedProxies(array());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function collect(Request $request, Response $response, \Exception $except

$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
if ('_route' == $key && is_object($value)) {
if ('_route' === $key && is_object($value)) {
$attributes['_route'] = $this->varToString($value->getPath());
} elseif ('_route_params' == $key) {
} elseif ('_route_params' === $key) {
foreach ($value as $key => $v) {
$attributes['_route_params'][$key] = $this->varToString($v);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Translation/PluralizationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ public static function get($number, $locale)
* @param string $rule A PHP callable
* @param string $locale The locale
*
* @return null
*
* @throws \LogicException
*/
public static function set($rule, $locale)
Expand Down

0 comments on commit d182503

Please sign in to comment.