minor #1891 made the tests semantically more correct (fabpot)

This PR was merged into the 1.x branch.

Discussion
----------

made the tests semantically more correct

Calling `initRuntime()` is just a side-effect of loading a template.

Commits
-------

f839ad3 made the tests semantically more correct
This commit is contained in:
Fabien Potencier
2015-10-25 08:16:08 +01:00
+10 -10
View File
@@ -54,11 +54,11 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$globals = $twig->getGlobals();
$this->assertEquals('bar', $globals['foo']);
// globals can be modified after runtime init
// globals can be modified after a template has been loaded
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->initRuntime();
$twig->loadTemplate('index');
$twig->addGlobal('foo', 'bar');
$globals = $twig->getGlobals();
$this->assertEquals('bar', $globals['foo']);
@@ -72,12 +72,12 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$globals = $twig->getGlobals();
$this->assertEquals('bar', $globals['foo']);
// globals can be modified after extensions and runtime init
// globals can be modified after extensions and a template has been loaded
$twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{foo}}')));
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->getFunctions();
$twig->initRuntime();
$twig->loadTemplate('index');
$twig->addGlobal('foo', 'bar');
$globals = $twig->getGlobals();
$this->assertEquals('bar', $globals['foo']);
@@ -89,11 +89,11 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$this->assertEquals('bar', $template->render(array()));
/* to be uncomment in Twig 2.0
// globals cannot be added after runtime init
// globals cannot be added after a template has been loaded
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->initRuntime();
$twig->loadTemplate('index');
try {
$twig->addGlobal('bar', 'bar');
$this->fail();
@@ -113,12 +113,12 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
}
// globals cannot be added after extensions and runtime init
// globals cannot be added after extensions and a template has been loaded
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->addGlobal('foo', 'foo');
$twig->getGlobals();
$twig->getFunctions();
$twig->initRuntime();
$twig->loadTemplate('index');
try {
$twig->addGlobal('bar', 'bar');
$this->fail();
@@ -126,9 +126,9 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
}
// test adding globals after initRuntime without call to getGlobals
// test adding globals after a template has been loaded without call to getGlobals
$twig = new Twig_Environment($this->getMock('Twig_LoaderInterface'));
$twig->initRuntime();
$twig->loadTemplate('index');
try {
$twig->addGlobal('bar', 'bar');
$this->fail();