Add RunnableTestCase to run fixed code in a test#3089
Add RunnableTestCase to run fixed code in a test#3089TomasVotruba merged 1 commit intorectorphp:masterfrom
Conversation
|
@TomasVotruba |
|
The composer command doesn't include all the actions. |
Had a quick look at the Is this something that you can provide quickly on master? Happy to fix any open issues in my PR as long as I get the corresponding feedback locally as the feedback loop via github actions only takes too long for that :/ |
7939a04 to
23485f2
Compare
|
It's usually the last I might get into it in 1-2 hours and update the |
|
It seems most of issues are gone. To apply Rector, just run: It's seems there EDIT: fixed 17f9efc |
|
How long does a (Running in Docker on a Windows 10 Host) |
23485f2 to
b4889a6
Compare
|
I never run it locally, so I don't know. How could be the performance improved there? |
| $loadable = (string) Strings::replace($loadable, '#\\s*namespace.*;#', ''); | ||
| $loadable = (string) Strings::replace($loadable, '#class\\s+(\\S*)\\s+#', sprintf('class %s ', $className)); | ||
| eval($loadable); | ||
| if (is_a($className, RunnableInterface::class, true)) { |
There was a problem hiding this comment.
This should be right under $className = $this->getTemporaryClassName(); with early reaturn,
as it can skipp all the Strings::replace()
There was a problem hiding this comment.
Don't think that would work.
is_a will only be able to recognize the class after eval has made it available to php
There was a problem hiding this comment.
Ah, I didn't notice. Is there a way to handle this withou eval()?
That opens big black door.
There was a problem hiding this comment.
Well, to be fair you already have an unchecked require_once in \Rector\Core\Testing\PHPUnit\FixtureSplitter::splitContentToOriginalFileAndExpectedFile (which is basically the same) :)
Only way to work around this is to split the "orignal" file and the "fixed" files into separate files and also use different class names and proper autoloading. However, this clashes with the current way fixtures are written and checked (e.g. it won't be possible to do a full "equality" check of the contents any longer because the class names will be different - which I think is very helpful).
If you keep the "goal" in mind (i.e. "reuse existing test files and simply add an additional layer of validation), I'm afraid there is no way around using something that dymically injects code.
- added RunnableTestCase::assertOriginalAndFixedFileYieldSameResult($file) that takes a fixture file and expects fixture classes that implement the new RunnableInterface which exposes a run() method - the fixture class is dynamically renamed to avoid naming conflicts and loaded via eval() - fixtures that don't implement the RunnableInterface are ignored otherwise the run() method is called on the original class as well as on the fixed one and the output is expected to be equal (via assertSame)
b4889a6 to
016124b
Compare
|
@TomasVotruba |
|
Looks good me to me 👍 |
RunnableTestCase::assertOriginalAndFixedFileYieldSameResult($file)that takes a fixture file and expects fixture classes that implement the
new RunnableInterface which exposes a
run()methodand loaded via
eval()RunnableInterfaceare ignoredotherwise the
run()method is called on the original class as wellas on the fixed one and the output is expected to be equal
(via
assertSame()) by default$assertioncallable