[Bug] Class Alias DeveloperProvidedFormRequest breaks parallel testing
See original GitHub issueBug report
What I did
Ran PestPHP tests in parallel that check CRUD controllers validation is working
What I expected to happen
The tests in parallel should pass as they do in singular
What happened
ErrorException: Cannot declare class DeveloperProvidedFormRequest, because the name is already in use in /Users/name/Sites/app-name/vendor/backpack/crud/src/app/Library/CrudPanel/Traits/Validation.php:207
What I’ve already tried to fix it
Running tests singularly works. Wrapping the class_alias code in a class_exists check works
Is it a bug in the latest version of Backpack?
After I run composer update backpack/crud
the bug… is it still there?
Yes
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version
the output is:
### PHP VERSION:
PHP 8.0.19 (cli) (built: May 12 2022 09:09:32) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.19, Copyright (c) Zend Technologies
with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans
with Zend OPcache v8.0.19, Copyright (c), by Zend Technologies
### LARAVEL VERSION:
v9.13.0@87b6cc8bc41d1cf85c7c1401cddde8570a3b95bb
### BACKPACK VERSION:
5.0.18@06ea421e44c353604ba56669e1fd3ac7a18981df
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
MSTest executing all my tests simultaneously breaks tests
Since it tries to run all its tests at the same time it gets an error when a test tries to access the...
Read more >Mixing sequential and parallel tests. - Google Groups
Hello,. I'm a bit stub with mixing parallel and sequential tests. Let's say I have: class mixParallelAndSequentialTest extends FreeSpec with Logging{.
Read more >NAME — GNU Parallel 20221222 documentation
Due to a bug in Bash, aliases containing newlines must be followed by a newline in the command. Some systems are not affected...
Read more >What is Parallel Testing and How Does it Work? - Semaphore CI
Parallel testing is an indispensable technique for reducing wait times. And mastering it is key to getting the most out of CI/CD.
Read more >Allow parallel tests to run for all orgs - IdeaExchange
Many of our unit tests running on any SF org version Summer '13 and above are now randomly failing with the error: "UNABLE_TO_LOCK_ROW,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @spoyntersmith
It could be a possible solution, yes … I’ve talked with some peers and the suggestions I got, are doing like you are saying, or creating some king of
FormRequest Factory
.I am still not sure if any of the solutions would cover the scenario that we are dealing with here, I think i’ve tried before getting into this solution and it would not fully fix our issue here, but I cannot fully recall so I need to try to redo it from scratch.
Problem is, for example, if you have the FormRequest (that you give crud with
$this->crud->setValidation(FormRequest::class)
) and let’s say you configure$stopOnFirstFailure
and a special validator withpublic function withValidator(...)
in this request. Then you add a field, and you say that this field have the rulemin:1
.So we have a FormRequest class, and an array of validation rules at this point.
We want that
min:1
rule to be validated, but also to run thewithValidation
, stop on the first failure and also redirect the user to wherever the developer defined in the request.From my understanding those configurations done in the
FormRequest
will not go throughDeveloperProvidedRequest
, we will give it the $formRequest, but will be the same as we have before creating the anonymous class, we still need to add those rules into the request and validate it at once so all the request rules are respected.The only problem I am aware with this solution is the fact that we have to create an alias for the $formRequest, because we cannot use
someClass extends $someVariable
otherwise I would just doDeveloperProvidedRequest extends $formRequest
. Also, from my knowledge it’s not possible to remove an alias after creating it. 😐Like I said, this solution was either a f*king genius idea, or the most stupid one. Time will tell me!
Hey @spoyntersmith
Thanks for the report 🙏
Ok … I think I get the issue … Let me think about the best way to solve it.
I think we have two options here:
first as you described, checking if class already exists (but I am not sure that when using paralellism the class is refering to the same crud as expected) Imagine crud A and B, crud A validates, and when crud B runs validation we check if class already exists (and it will exist from crud A, not crud B validation). Not 100% sure about this theory but it’s possible.
destroy the class after using it. (probably the best and permanent solution since we don’t need it anymore.
Can you help me to debug if my theory from crud A to crud B holds? What’s your outputs when you use
class_exists()
? OR you are validating the same crud multiple times ?Cheers