diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index ca0f3594a..2253f7165 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -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) { diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index b5dfd6323..2fde48a9d 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -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); } /** diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php index bcb75c282..54f2ecc96 100644 --- a/test/Twig/Tests/ExpressionParserTest.php +++ b/test/Twig/Tests/ExpressionParserTest.php @@ -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() diff --git a/test/Twig/Tests/LegacyIntegrationTest.php b/test/Twig/Tests/LegacyIntegrationTest.php index 055a61707..2ed758038 100644 --- a/test/Twig/Tests/LegacyIntegrationTest.php +++ b/test/Twig/Tests/LegacyIntegrationTest.php @@ -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); diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php index caf331e06..c46044971 100644 --- a/test/Twig/Tests/LexerTest.php +++ b/test/Twig/Tests/LexerTest.php @@ -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); } /** diff --git a/test/Twig/Tests/Loader/ArrayTest.php b/test/Twig/Tests/Loader/ArrayTest.php index fe009e2be..ac3c73ed5 100644 --- a/test/Twig/Tests/Loader/ArrayTest.php +++ b/test/Twig/Tests/Loader/ArrayTest.php @@ -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); } } diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php index 95d950929..0a48e6dd7 100644 --- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -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)); diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php index 3d0d769d8..1bc2b0965 100644 --- a/test/Twig/Tests/ParserTest.php +++ b/test/Twig/Tests/ParserTest.php @@ -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() diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 97a598249..faa68c6c0 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -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) {