Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Translation] ReworkPhpAstExtractor tests organization for future improvements#60854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
welcoMattic wants to merge6 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromwelcoMattic:translation/php-ast-extractor-tests-rework

Conversation

welcoMattic
Copy link
Member

QA
Branch?7.4
Bug fix?no
New feature?no
Deprecations?no
IssuesFix #...
LicenseMIT

This PR is the first in a series that tend to improve PhpAstExtractor (covering more extractions cases, ease test writting for new cases, etc).

I've worked with@Jean-Beru,@Kazadri and@jprivet-dev in the past few weeks on various new cases to increase the number of "locations" from where the extractor can extract translation keys.

As we were working on my own Symfony fork, I'm opening the PR.
But to be honest my colleague@Jean-Beru did the large majority of the work here. Thanks to him 👏!

To avoid a big PR containing multiple new small features, we need to open and hopefully merge this one first to ease the tests writting for next new Visitors.


NB: I'm not sure to qualify or not this PR as New feature?

Jean-Beru reacted with heart emojiKocal reacted with eyes emoji
@carsonbotcarsonbot added this to the7.4 milestoneJun 20, 2025
@welcoMatticwelcoMatticforce-pushed thetranslation/php-ast-extractor-tests-rework branch 2 times, most recently from19b3d28 to2ed841fCompareJune 20, 2025 14:11
use Symfony\Component\Translation\Extractor\PhpAstExtractor;
use Symfony\Component\Translation\MessageCatalogue;

abstract class AbstractVisitorTest extends TestCase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should be namedAbstractVisitorTestCase as PHPUnit 10 has deprecated the fact of having abstract classes matching the class name suffix of tests (which isTest by default, and we use the default), and PHPUnit 11 fails for such case.

OskarStark reacted with thumbs up emoji
abstract class AbstractVisitorTest extends TestCase
{
abstract public function getVisitor(): NodeVisitor;
abstract public function getResource(): iterable|string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this should have pphdoc for 2 reasons:

  • document the return type fully
  • explain what this method is about

use Symfony\Component\Translation\Extractor\Visitor\ConstraintVisitor;
use Symfony\Component\Translation\MessageCatalogue;

class ConstraintVisitorTest extends AbstractVisitorTest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

having to make a new test class for each test looks weird to me.

we might want to have multiple tests running for ConstraintVisitor for instance, which would then require finding names for those test classes (instead of naming test methods like usual) or to merge everything in a single test (which removes any explanation of theintent of the test, and also prevents testing some legacy feature and non-legacy ones separately)

Designing theAbstractVisitorTest testcase in a way supporting a single test does not really matches the common PHPUnit architecture.
You should rather make it define a utility method taking a NodeVisitor and a resource as argument and returning a MessageCatalogue, and let each test class write as many tests it wants using this utility.

@@ -0,0 +1,72 @@
This template is used for translation message extraction tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

why using a PHP template to cover the case of extracting from form types ? This does not make sense to me.

@@ -0,0 +1,72 @@
This template is used for translation message extraction tests
<?php
// @see https://github.com/php-translation/extractor/blob/master/tests/Resources/Php/Symfony/ExplicitLabelType.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

why a@see targetting an external file (with a URL that won't even stay valid as it referencemaster which is a mutable reference)

@@ -0,0 +1,47 @@
This template is used for translation message extraction tests
<?php new TranslatableMessage('translatable single-quoted key'); ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

isn't this missing a use statement ?

@welcoMatticwelcoMatticforce-pushed thetranslation/php-ast-extractor-tests-rework branch from2ed841f to23ead95CompareJune 20, 2025 14:38
@OskarStarkOskarStark changed the title[Translation] Rework PhpAstExtractor tests organization for future improvements[Translation] ReworkPhpAstExtractor tests organization for future improvementsJun 23, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@stofstofstof requested changes

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

4 participants
@welcoMattic@stof@carsonbot@Jean-Beru

[8]ページ先頭

©2009-2025 Movatter.jp