Merge branch '3.4' into 4.4
* 3.4: drop logger mock in favor of using the BufferingLogger [Yaml Parser] Fix edge cases when parsing multiple documents fix parsing comments not prefixed by a space
This commit is contained in:
commit
d1353c0602
@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\EventDispatcher\Tests\Debug;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Debug\BufferingLogger;
|
||||
use Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
@ -206,41 +207,57 @@ class TraceableEventDispatcherTest extends TestCase
|
||||
|
||||
public function testLogger()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
$logger = new BufferingLogger();
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
|
||||
$tdispatcher->addListener('foo', $listener1 = function () {});
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {});
|
||||
|
||||
$logger->expects($this->exactly(2))
|
||||
->method('debug')
|
||||
->withConsecutive(
|
||||
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
|
||||
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']]
|
||||
);
|
||||
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$this->assertSame([
|
||||
[
|
||||
'debug',
|
||||
'Notified event "{event}" to listener "{listener}".',
|
||||
['event' => 'foo', 'listener' => 'closure'],
|
||||
],
|
||||
[
|
||||
'debug',
|
||||
'Notified event "{event}" to listener "{listener}".',
|
||||
['event' => 'foo', 'listener' => 'closure'],
|
||||
],
|
||||
], $logger->cleanLogs());
|
||||
}
|
||||
|
||||
public function testLoggerWithStoppedEvent()
|
||||
{
|
||||
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
|
||||
$logger = new BufferingLogger();
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$tdispatcher = new TraceableEventDispatcher($dispatcher, new Stopwatch(), $logger);
|
||||
$tdispatcher->addListener('foo', $listener1 = function (Event $event) { $event->stopPropagation(); });
|
||||
$tdispatcher->addListener('foo', $listener2 = function () {});
|
||||
|
||||
$logger->expects($this->exactly(3))
|
||||
->method('debug')
|
||||
->withConsecutive(
|
||||
['Notified event "{event}" to listener "{listener}".', ['event' => 'foo', 'listener' => 'closure']],
|
||||
['Listener "{listener}" stopped propagation of the event "{event}".', ['event' => 'foo', 'listener' => 'closure']],
|
||||
['Listener "{listener}" was not called for event "{event}".', ['event' => 'foo', 'listener' => 'closure']]
|
||||
);
|
||||
|
||||
$tdispatcher->dispatch(new Event(), 'foo');
|
||||
|
||||
$this->assertSame([
|
||||
[
|
||||
'debug',
|
||||
'Notified event "{event}" to listener "{listener}".',
|
||||
['event' => 'foo', 'listener' => 'closure'],
|
||||
],
|
||||
[
|
||||
'debug',
|
||||
'Listener "{listener}" stopped propagation of the event "{event}".',
|
||||
['event' => 'foo', 'listener' => 'closure'],
|
||||
],
|
||||
[
|
||||
'debug',
|
||||
'Listener "{listener}" was not called for event "{event}".',
|
||||
['event' => 'foo', 'listener' => 'closure'],
|
||||
],
|
||||
], $logger->cleanLogs());
|
||||
}
|
||||
|
||||
public function testDispatchCallListeners()
|
||||
|
@ -23,6 +23,7 @@
|
||||
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
|
||||
"symfony/expression-language": "^3.4|^4.0|^5.0",
|
||||
"symfony/config": "^3.4|^4.0|^5.0",
|
||||
"symfony/debug": "~3.4|~4.4",
|
||||
"symfony/http-foundation": "^3.4|^4.0|^5.0",
|
||||
"symfony/service-contracts": "^1.1|^2",
|
||||
"symfony/stopwatch": "^3.4|^4.0|^5.0",
|
||||
|
@ -90,7 +90,7 @@ class Inline
|
||||
}
|
||||
|
||||
// some comments are allowed at the end
|
||||
if (preg_replace('/\s+#.*$/A', '', substr($value, $i))) {
|
||||
if (preg_replace('/\s*#.*$/A', '', substr($value, $i))) {
|
||||
throw new ParseException(sprintf('Unexpected characters near "%s".', substr($value, $i)), self::$parsedLineNumber + 1, $value, self::$parsedFilename);
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,7 @@ class Parser
|
||||
$this->refs = [];
|
||||
$this->skippedLineNumbers = [];
|
||||
$this->locallySkippedLineNumbers = [];
|
||||
$this->totalNumberOfLines = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
@ -799,6 +799,16 @@ class InlineTest extends TestCase
|
||||
self::assertSame('-0123456789', Inline::parse('-0123456789'));
|
||||
}
|
||||
|
||||
public function testParseCommentNotPrefixedBySpaces()
|
||||
{
|
||||
self::assertSame('foo', Inline::parse('"foo"#comment'));
|
||||
}
|
||||
|
||||
public function testParseUnquotedStringContainingHashTagNotPrefixedBySpace()
|
||||
{
|
||||
self::assertSame('foo#nocomment', Inline::parse('foo#nocomment'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider unquotedExclamationMarkThrowsProvider
|
||||
*/
|
||||
|
@ -2438,6 +2438,39 @@ YAML;
|
||||
$this->parser->parse($yaml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a regression test for a bug where a YAML block with a nested multiline string using | was parsed without
|
||||
* a trailing \n when a shorter YAML document was parsed before.
|
||||
*
|
||||
* When a shorter document was parsed before, the nested string did not have a \n at the end of the string, because
|
||||
* the Parser thought it was the end of the file, even though it is not.
|
||||
*/
|
||||
public function testParsingMultipleDocuments()
|
||||
{
|
||||
$shortDocument = 'foo: bar';
|
||||
$longDocument = <<<YAML
|
||||
a:
|
||||
b: |
|
||||
row
|
||||
row2
|
||||
c: d
|
||||
YAML;
|
||||
|
||||
$expected = ['a' => ['b' => "row\nrow2\n"], 'c' => 'd'];
|
||||
|
||||
// The parser was not used before, so there is a new line after row2
|
||||
$this->assertSame($expected, $this->parser->parse($longDocument));
|
||||
|
||||
$parser = new Parser();
|
||||
// The first parsing set and fixed the totalNumberOfLines in the Parser before, so parsing the short document here
|
||||
// to reproduce the issue. If the issue would not have been fixed, the next assertion will fail
|
||||
$parser->parse($shortDocument);
|
||||
|
||||
// After the total number of lines has been rset the result will be the same as if a new parser was used
|
||||
// (before, there was no \n after row2)
|
||||
$this->assertSame($expected, $parser->parse($longDocument));
|
||||
}
|
||||
}
|
||||
|
||||
class B
|
||||
|
Reference in New Issue
Block a user