Merge branch '1.x' into 2.x

* 1.x:
  fixed risky tests
This commit is contained in:
Fabien Potencier
2017-03-20 09:12:13 -07:00
6 changed files with 74 additions and 15 deletions
+4
View File
@@ -121,6 +121,10 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs)
{
if (!$outputs) {
$this->markTestSkipped('no legacy tests to run');
}
if ($condition) {
eval('$ret = '.$condition.';');
if (!$ret) {
+4 -1
View File
@@ -292,8 +292,11 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$twig = new Twig_Environment($loader);
$loader->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', '')));
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime());
$twig->loadTemplate('');
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any deprecations
$this->addToAssertionCount(1);
}
/**
+4
View File
@@ -284,6 +284,10 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
$parser = new Twig_Parser($env);
$parser->parse($env->tokenize(new Twig_Source($template, 'index')));
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function getMacroDefinitionSupportsConstantDefaultValues()
+40 -4
View File
@@ -105,7 +105,9 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
$lexer->tokenize(new Twig_Source($template, 'index'));
// should not throw an exception
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testLongVerbatim()
@@ -115,7 +117,9 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
$lexer->tokenize(new Twig_Source($template, 'index'));
// should not throw an exception
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testLongVar()
@@ -125,7 +129,9 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
$lexer->tokenize(new Twig_Source($template, 'index'));
// should not throw an exception
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testLongBlock()
@@ -135,7 +141,9 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()));
$lexer->tokenize(new Twig_Source($template, 'index'));
// should not throw an exception
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testBigNumbers()
@@ -161,6 +169,10 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$stream = $lexer->tokenize(new Twig_Source($template, 'index'));
$stream->expect(Twig_Token::VAR_START_TYPE);
$stream->expect(Twig_Token::STRING_TYPE, $expected);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
}
@@ -179,6 +191,10 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$stream->expect(Twig_Token::NUMBER_TYPE, '1');
$stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
$stream->expect(Twig_Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testStringWithEscapedInterpolation()
@@ -190,6 +206,10 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$stream->expect(Twig_Token::VAR_START_TYPE);
$stream->expect(Twig_Token::STRING_TYPE, 'bar #{baz+1}');
$stream->expect(Twig_Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testStringWithHash()
@@ -201,6 +221,10 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$stream->expect(Twig_Token::VAR_START_TYPE);
$stream->expect(Twig_Token::STRING_TYPE, 'bar # baz');
$stream->expect(Twig_Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
/**
@@ -230,6 +254,10 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
$stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
$stream->expect(Twig_Token::VAR_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testStringWithNestedInterpolationsInBlock()
@@ -248,6 +276,10 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
$stream->expect(Twig_Token::INTERPOLATION_END_TYPE);
$stream->expect(Twig_Token::BLOCK_END_TYPE);
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
public function testOperatorEndingWithALetterAtTheEndOfALine()
@@ -259,6 +291,10 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase
$stream->expect(Twig_Token::VAR_START_TYPE);
$stream->expect(Twig_Token::NUMBER_TYPE, 1);
$stream->expect(Twig_Token::OPERATOR_TYPE, 'and');
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without throwing any exceptions
$this->addToAssertionCount(1);
}
/**
+5 -3
View File
@@ -130,9 +130,6 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
$this->assertNull($parser->getParent());
}
// The getVarName() must not depend on the template loaders,
// If this test does not throw any exception, that's good.
// see https://github.com/symfony/symfony/issues/4218
public function testGetVarName()
{
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array(
@@ -148,6 +145,11 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
{% endmacro %}
EOF
, 'index')));
// The getVarName() must not depend on the template loaders,
// If this test does not throw any exception, that's good.
// see https://github.com/symfony/symfony/issues/4218
$this->addToAssertionCount(1);
}
protected function getParser()
+17 -7
View File
@@ -83,10 +83,14 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
if (!$allowed) {
$this->fail();
} else {
$this->addToAssertionCount(1);
}
} catch (Twig_Sandbox_SecurityError $e) {
if ($allowed) {
$this->fail();
} else {
$this->addToAssertionCount(1);
}
$this->assertContains('is not allowed', $e->getMessage());
@@ -190,15 +194,15 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
if ($defined) {
$this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type));
} else {
try {
$this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type));
throw new Exception('Expected Twig_Error_Runtime exception.');
} catch (Twig_Error_Runtime $e) {
if (method_exists($this, 'expectException')) {
$this->expectException('Twig_Error_Runtime');
if (null !== $exceptionMessage) {
$this->assertSame($exceptionMessage, $e->getMessage());
$this->expectExceptionMessage($exceptionMessage);
}
} else {
$this->setExpectedException('Twig_Error_Runtime', $exceptionMessage);
}
$this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type));
}
}
@@ -515,7 +519,13 @@ class Twig_TemplatePropertyObjectAndIterator extends Twig_TemplatePropertyObject
class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObject implements ArrayAccess
{
private $data = array();
private $data = array(
'defined' => 'defined',
'zero' => 0,
'null' => null,
'bar' => true,
'baz' => 'baz',
);
public function offsetExists($offset)
{