Skip to content

Commit

Permalink
minor #4472 [Twig 4] Add PHPUnit as dev dependency (ruudk)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.x branch.

Discussion
----------

[Twig 4] Add PHPUnit as dev dependency

This makes it easier to run the tests locally.

I understand we didn't do this previously (Twig 3) because of `symfony/simple-phpunit`. But that is now removed in Twig 4, so maybe we can do this as well?

Commits
-------

c352a8d [Twig 4] Add PHPUnit as dev dependency
  • Loading branch information
fabpot committed Dec 1, 2024
2 parents 80020a6 + c352a8d commit 196c9dc
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 20 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ jobs:
coverage: "none"
php-version: ${{ matrix.php-version }}
ini-values: memory_limit=-1
tools: phpunit:11.3

- name: "Add PHPUnit matcher"
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- run: composer install

- name: "Run tests"
run: phpunit
run: vendor/bin/phpunit

extension-tests:
needs:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"keywords": ["templating"],
"homepage": "https://twig.symfony.com",
"license": "BSD-3-Clause",
"minimum-stability": "dev",
"authors": [
{
"name": "Fabien Potencier",
Expand All @@ -31,7 +30,8 @@
},
"require-dev": {
"psr/container": "^1.0|^2.0",
"phpstan/phpstan": "^2.0"
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^11.4"
},
"autoload": {
"psr-4" : {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
failOnDeprecation="true"
Expand Down
5 changes: 2 additions & 3 deletions tests/DeprecatedCallableInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
* file that was distributed with this source code.
*/

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Twig\DeprecatedCallableInfo;

class DeprecatedCallableInfoTest extends TestCase
{
/**
* @dataProvider provideTestsForTriggerDeprecation
*/
#[DataProvider('provideTestsForTriggerDeprecation')]
public function testTriggerDeprecation($expected, DeprecatedCallableInfo $info)
{
$info->setType('function');
Expand Down
12 changes: 3 additions & 9 deletions tests/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,7 @@ public function testInlineCommentWithHashInString()
$this->assertTrue($stream->isEOF());
}

/**
* @dataProvider getTemplateForInlineCommentsForVariable
*/
#[DataProvider('getTemplateForInlineCommentsForVariable')]
public function testInlineCommentForVariable(string $template)
{
$lexer = new Lexer(new Environment(new ArrayLoader()));
Expand Down Expand Up @@ -524,9 +522,7 @@ public static function getTemplateForInlineCommentsForVariable()
}}'];
}

/**
* @dataProvider getTemplateForInlineCommentsForBlock
*/
#[DataProvider('getTemplateForInlineCommentsForBlock')]
public function testInlineCommentForBlock(string $template)
{
$lexer = new Lexer(new Environment(new ArrayLoader()));
Expand Down Expand Up @@ -562,9 +558,7 @@ public static function getTemplateForInlineCommentsForBlock()
%}me{% endif %}'];
}

/**
* @dataProvider getTemplateForInlineCommentsForComment
*/
#[DataProvider('getTemplateForInlineCommentsForComment')]
public function testInlineCommentForComment(string $template)
{
$lexer = new Lexer(new Environment(new ArrayLoader()));
Expand Down
5 changes: 2 additions & 3 deletions tests/Util/CallableArgumentsExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* file that was distributed with this source code.
*/

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Twig\Error\SyntaxError;
use Twig\Node\EmptyNode;
Expand Down Expand Up @@ -83,9 +84,7 @@ public function testGetArgumentsForStaticMethod()
$this->assertEquals(['arg1'], $this->getArguments('custom_static_function', __CLASS__.'::customStaticFunction', ['arg1' => 'arg1']));
}

/**
* @dataProvider getGetArgumentsConversionData
*/
#[DataProvider('getGetArgumentsConversionData')]
public function testGetArgumentsConversion($arg1, $arg2)
{
$this->assertEquals([null], $this->getArguments('custom', eval("return fn (\$$arg1) => '';"), [$arg1 => null]));
Expand Down

0 comments on commit 196c9dc

Please sign in to comment.