-
Notifications
You must be signed in to change notification settings - Fork 428
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC: Speed optimize class-loading for levels tests #2916
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
57bcbd2
Speed optimize class-loading for levels tests
staabm 9d04fe6
Prevent unnecessary IO in ComposerJsonAndInstalledJsonSourceLocatorMaker
staabm 11ffaa8
fix warnings
staabm 37e325c
Revert "fix warnings"
staabm 4eb6d67
Revert "Speed optimize class-loading for levels tests"
staabm 030b8c0
Implement parallelized test levels via github actions matrix
staabm b025c05
separate test-levels-matrix job
staabm 45b12b0
fix deprecation
staabm 36f26cf
fix typo
staabm 9adf76d
backslash escapeing
staabm 947ddb7
review feedback
staabm 6185833
typo
staabm 5fe67ce
use list-tests-xml
staabm 6dc056d
simplify
staabm 0bcd114
Update tests.yml
staabm b77b48a
use escapeshellarg()
staabm f5aeead
added back escaping
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
shell_exec('php vendor/bin/phpunit --list-tests-xml test-list.xml'); | ||
|
||
$simpleXml = simplexml_load_file('test-list.xml'); | ||
if ($simpleXml === false) { | ||
throw new RuntimeException('Error loading test-list.xml'); | ||
} | ||
|
||
$testFilters = []; | ||
foreach($simpleXml->testCaseClass as $testCaseClass) { | ||
foreach($testCaseClass->testCaseMethod as $testCaseMethod) { | ||
if ((string) $testCaseMethod['groups'] !== 'levels') { | ||
continue; | ||
} | ||
|
||
$testCaseName = (string) $testCaseMethod['id']; | ||
|
||
[$className, $testName] = explode('::', $testCaseName, 2); | ||
$fileName = 'tests/'. str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php'; | ||
|
||
$filter = str_replace('\\', '\\\\', $testCaseName); | ||
|
||
$testFilters[] = sprintf("%s --filter '%s'", $fileName, $filter); | ||
} | ||
} | ||
|
||
if ($testFilters === []) { | ||
throw new RuntimeException('No tests found'); | ||
} | ||
|
||
echo json_encode($testFilters); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is doubling backslashes needed? I’d say that instead of that we need escapeshellarg() for both fileName and filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the plain command on the CLI only works only with double backslashes (in the filter arg)
See your command in #2916 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can add escapeshellarg(), but we still need this manual escaping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets give it a try and we will see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/phpstan/phpstan-src/actions/runs/7944377066/job/21689826256 shows that it doesn't work when we only use
escapeshellarg
(no tests executed).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that? I noticed it doesn't work but I don't know what eats the characters, whether it's bash or PHP. Doubling the backslashes seems very peculiar to me, maybe there are other things we need to fix too but we're currently unaware of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phpunit examples in docs also mention double backslashes
https://docs.phpunit.de/en/9.6/textui.html#textui-examples-filter-patterns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its interpreted as regex. Let mit try preg_quote()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know. It's probably a bash thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preg_quote would escape the following characters:
. \ + * ? [ ^ ] $ ( ) { } = ! < > | : - #
the only one of these which can show up in a class/method name is
\
. I think we can usepreg_quote
if you prefer but it should be enough to escape the backslash IMOedit: I had an idea