Skip to content

Commit

Permalink
feature #2452 Support PHPUnit 6 for testing extensions (hkdobrev)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.x branch.

Discussion
----------

Support PHPUnit 6 for testing extensions

When testing a Twig extension via the provided test cases [according to the documentation](https://twig.sensiolabs.org/doc/2.x/advanced.html#testing-an-extension), PHPUnit 6 is not supported.

I think we should force people who haven't upgraded to upgrade to PHPUnit 6 instead of limiting the ones who did.

Also, Twig 2.x runs only on PHP 7. People using Twig 2.x would most likely also test their code on PHP 7. Even though PHPUnit 5 supports PHP 7, I think most people who have updated PHP could update or would have already updated PHPUnit.

Commits
-------

8ebaf8e Support PHPUnit 6 for testing extensions
  • Loading branch information
fabpot committed May 11, 2017
2 parents f4adaef + 8ebaf8e commit ccee78e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/Twig/Test/IntegrationTestCase.php
Expand Up @@ -9,13 +9,16 @@
* file that was distributed with this source code.
*/

use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Constraint\Exception as ExceptionConstraint;

/**
* Integration test helper.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Karma Dordrak <drak@zikula.org>
*/
abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
abstract class Twig_Test_IntegrationTestCase extends TestCase
{
/**
* @return string
Expand Down Expand Up @@ -196,7 +199,8 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e

if (false !== $exception) {
list($class) = explode(':', $exception);
$this->assertThat(null, new PHPUnit_Framework_Constraint_Exception($class));
$constraintClass = class_exists(ExceptionConstraint::class) ? ExceptionConstraint::class : \PHPUnit_Framework_Constraint_Exception::class;
$this->assertThat(null, new $constraintClass($class));
}

$expected = trim($match[3], "\n ");
Expand Down
4 changes: 3 additions & 1 deletion lib/Twig/Test/NodeTestCase.php
@@ -1,5 +1,7 @@
<?php

use PHPUnit\Framework\TestCase;

/*
* This file is part of Twig.
*
Expand All @@ -8,7 +10,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
abstract class Twig_Test_NodeTestCase extends PHPUnit_Framework_TestCase
abstract class Twig_Test_NodeTestCase extends TestCase
{
abstract public function getTests();

Expand Down

0 comments on commit ccee78e

Please sign in to comment.