minor #2429 fixed risky tests (fabpot)

This PR was merged into the 1.x branch.

Discussion
----------

fixed risky tests

Commits
-------

7259e52f fixed risky tests
This commit is contained in:
Fabien Potencier
2017-03-20 08:49:31 -07:00
9 changed files with 80 additions and 17 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
@@ -398,8 +398,11 @@ EOF
{
$twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
$twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime());
$twig->initRuntime();
// 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()
+1 -1
View File
@@ -26,7 +26,7 @@ class Twig_Tests_LegacyIntegrationTest extends Twig_Test_IntegrationTestCase
public function getTests($name, $legacyTests = false)
{
if (!$legacyTests) {
return array(array('not', '-', '', array(), '', array()));
return array(array('', '', '', array(), '', array()));
}
return parent::getTests($name, true);
+40 -4
View File
@@ -116,7 +116,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()
@@ -126,7 +128,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()
@@ -136,7 +140,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()
@@ -146,7 +152,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()
@@ -171,6 +179,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);
}
}
@@ -189,6 +201,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()
@@ -200,6 +216,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()
@@ -211,6 +231,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);
}
/**
@@ -240,6 +264,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()
@@ -258,6 +286,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()
@@ -269,6 +301,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);
}
/**
+4
View File
@@ -92,6 +92,10 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
$loader->getSourceContext($name);
$loader->isFresh($name, time());
$loader->setTemplate($name, 'foobar');
// add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above
// can be executed without crashing PHP
$this->addToAssertionCount(1);
}
}
@@ -37,7 +37,7 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends PHPUnit_Framework_TestCase
public function testRenderVariableBlockOptimizer()
{
if (PHP_VERSION_ID >= 50400) {
return;
$this->markTestSkipped('not needed on PHP >= 5.4');
}
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false));
+5 -3
View File
@@ -131,9 +131,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(
@@ -149,6 +146,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());
@@ -255,15 +259,15 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase
if ($defined) {
$this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type));
} else {
try {
$this->assertEquals($value, $template->getAttribute($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, $template->getAttribute($object, $item, $arguments, $type));
}
}
@@ -576,7 +580,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)
{