-
-
Notifications
You must be signed in to change notification settings - Fork 708
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
Add RunnableTestCase to run fixed code in a test #3089
Add RunnableTestCase to run fixed code in a test #3089
Conversation
@TomasVotruba |
The composer command doesn't include all the actions. |
.../ArrayKeysAndInArrayToArrayKeyExistsRector/ArrayKeysAndInArrayToArrayKeyExistsRectorTest.php
Outdated
Show resolved
Hide resolved
...lity/tests/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector/Fixture/fixture.php.inc
Show resolved
Hide resolved
...quality/tests/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector/RunnableTestCase.php
Outdated
Show resolved
Hide resolved
...quality/tests/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector/RunnableTestCase.php
Outdated
Show resolved
Hide resolved
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? |
...tests/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector/AbstractRunnableTestCase.php
Outdated
Show resolved
Hide resolved
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
.../ArrayKeysAndInArrayToArrayKeyExistsRector/ArrayKeysAndInArrayToArrayKeyExistsRectorTest.php
Show resolved
Hide resolved
- 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()
RunnableInterface
are 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$assertion
callable