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
WIP Add ability to run tests in a separate process #285
Conversation
It's not working, need to see why.
So, after a bit of digging I've found out what the correct flags are, but the problem is that the test fails with
Digging into PHPUnit, in the This will return 'filename' => '/Users/denis.zoljom/Projects/Personal/pest/src/Factories/TestCaseFactory.php(233) : eval()\'d code', And the |
This will have to be modified - only tests which we want to run in a separate process should have temp file written, the regular tests can be eval'd. Also, cleanup process needs to be written for the *Temp.php files. For some reason this fails on the PHPUnit level with 'Error: Class 'PHPUnit\TextUI\XmlConfiguration\Loader' not found in Standard input code on line 97'. Need to investigate what happens here.
Looks like, when using on the fly created file, the test template by PHPUnit has some weird issues (like it cannot resolve dependencies). Running
Gives the following result Output
|
@dingo-d Have you managed? |
Not had the time lately to work on this. When I'll hqve some more time I'll give it another go. |
/** | ||
* Makes a fully qualified class name from the given filename. | ||
*/ | ||
public function makeTemporaryClassFromFilename(string $filename): string |
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.
We really need all this code?
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.
This part is related to the comment
So, after a bit of digging I've found out what the correct flags are, but the problem is that the test fails with
Parse error: syntax error, unexpected 'd' (T_STRING) in Standard input code on line 33
Digging into PHPUnit, in the
src/Framework/TestCase.php
line 847 there is a call to agetFileName()
method of a reflection class of the test class. And since all the test classes in Pest are done on the fly usingeval
in theTestCaseFactory.php
, there are no real test classes (not in the PHPUnit sense of the word).This will return
'filename' => '/Users/denis.zoljom/Projects/Personal/pest/src/Factories/TestCaseFactory.php(233) : eval()\'d code',
And the
: eval()\'d code'
trips PHPUnit up causing the above error. I'll try to see what else I can dig out and if this can be solved in any way.
The issue is that when using eval, the reflection won't return the intended filename (by design). This is a workaround (attempt at least).
Probably this is related to sebastianbergmann/phpunit#4664 |
What is the current state of this pull request? |
@nunomaduro I think it is a phpunit bug itself sebastianbergmann/phpunit#4664 |
Yup, I am kinda blocked by the phpunit not behaving as expected (even when creating a test class file on the fly vs using reflection). Maybe it will get fixed in v10? |
Lets revisit this pull request later. |
It looks like the upstream bug in the environment package has been fixed, any chance of picking this up again? I'd work on this, but the repo has changed substantially from when I last worked on this, so I'd have to spend too much time I don't currently have(unfortunately), to understand the inner workings of Pest. I think this could be a valuable addition to the package 🙂 |
Looks like that upstream PHPUnit bug was patched. Any momentum on this feature? Would be really useful to be able to run tests in separate processes. |
@paulshryock I hope this will be included in v2 version 🙂 |
I got same issue in 2023 :) when trying mock object by mockery |
@dingo-d @nunomaduro would love to know if there's been any progress here, or any specific blockers for getting this PR into Pest. |
@robjmills As it stands now, this PR is unusable, as it was made with version 1 of Pest. And there was an upstream bug that blocked this. I hadn't checked the v2 version, but I know the underlying architecture changed quite a lot because of PHPUnit 10, so this feature should be made from scratch. |
Thanks for the update @dingo-d 👍🏻 |
Just ran into this because I need to use |
Btw Pest 2 has these flags: --process-isolation ............................ Run each test in a separate PHP process
--globals-backup ............................... Backup and restore $GLOBALS for each test
--static-backup ................................ Backup and restore static properties for each test Did you try using some of these in your tests @edalzell? |
|
I ended up splitting out this test onto it's own, and running it via |
@edalzell sorry for tagging you in an older ticket, but I am also running into this. How did you setup running pest and phpunit in the same project? Pest interferes when you try running phpunit commands in groups or folders:
Or are you just running 1 test file via phpunit, which seems the only way it works:
|
Same here, curious for the answer ! |
I'm trying to attempt to have tests run in a separate process. The prototype PHPUnit test (that is passing for me) looks like this:
And I have a function
cacheable
insrc/functions.php
The test passes, because of
annotations. I poked a bit at the PHPUnit, and I noticed some setters for all these functionalities inside
PHPUnit\Framework\TestCase
abstract class.So I added a
runInSeparateProcess()
chainable method that sets the propertyseparateProcess
totrue
inside theTestCaseFactory
. Using that property I'm trying to add these methods to the test case created in Pest.So far it has not been successful 😅 I've tried debugging it and I'm not sure what is different. I've checked these properties for both tests (Pest and PHPUnit) using xDebug, and they look the same, but the Pest ones are failing. So I'm obviously missing something.
I'll try to play around it some more, but any help is welcomed 🙂 Would really like to have this feature in Pest 😄