Open pgee70 opened 3 years ago
What do you mean by shadow copy?
If you use Monkey Patching, the line numbers are different from the actual line numbers. Because it seems there is no way to patch without changing line numbers. With the old PHP-Parser, it was possible to patch without changing line numbers.
are there any setup tricks/tips i can have to help here?
I don't know.
The best solution is not to use Monkey Patching. But if your code is not clean, it must be impossible.
Monkey Patch hooks require
and read the source file and modifies it on the fly.
Thanks for your answer, it must be the monkey patching - I do use this. the code was written way before I did any unit testing and I have been bolted on unit testing on afterwards. and the upgrade to the new parser must have caused the issue that I am experiencing. thanks for your advice.
The feature of PHP-Parser may resolve this issue, but it is experimental and not yet complete.
Formatting-preserving pretty printing https://github.com/nikic/PHP-Parser/blob/master/doc/component/Pretty_printing.markdown#formatting-preserving-pretty-printing
I think this issue should be left open. The strange thing is that even with monkey patching, it used to work fine until we upgraded PHP/Xdebug to newer versions. So, if it used to work, there is probably a way to make it work again.
There is another thing that doesn't work anymore - codecoverage (for the same reason - wrong lines are reported by xdebug)
@kenjis how does PHP-Parser apply here?
@ipeevski This is the problem in PHP-Parser. Xdebug has nothing to do with. Monkey Patching reads a source file and parse it with PHP-Parser and modify it on the fly, and PHP executes the modified source code.
Note: If you use Monkey Patching with PHP-Parser 4.6 or later, the line number when an error occurs is probably different from the actual source code. Please check the cache file of the source that Monkey Patching creates. https://github.com/kenjis/ci-phpunit-test/blob/3.x/docs/HowToWriteTests.md#monkey-patching
For my use-case, debugging is only needed while I am doing test-driven development and not when I run all unit tests. so I turn off monkey patching, and then when I want to run all my unit-tests I turn it back on by manually editing the bootstrap file to toggle monkey patching For the most part I monkey-patch ini-set php memory - my test environment uses lots of ram and generally the site only a few methods need their memory tweaked. All tests failed when a test was run that set the php memory limit to a lower amount than the test environment needed. I refactored my code to not do ini-sets during the test environment - then I ran into other issues that opened up another can of worms, so I went back to manually editing the unit-test bootstrap file.
@kenjis That may be so (and explains why it happened after the upgrade, since as part of that we would have upgraded PHP-Parser to 4.13) and it helps with tracking things down when debugging manually, but still doesn't help with code coverage reports. Are there any leads you can give us as to how we might address those?
For the record, I can confirm that disabling monkey patching fixes the code coverage reports. We use MonkeyPatch in a few places to skip routing, recatcha, etc and won't be trivial to just turn off. Is our only option to rewrite those tests?
@ipeevski This is the problem in PHP-Parser. Xdebug has nothing to do with. Monkey Patching reads a source file and parse it with PHP-Parser and modify it on the fly, and PHP executes the modified source code.
Note: If you use Monkey Patching with PHP-Parser 4.6 or later, the line number when an error occurs is probably different from the actual source code. Please check the cache file of the source that Monkey Patching creates. https://github.com/kenjis/ci-phpunit-test/blob/3.x/docs/HowToWriteTests.md#monkey-patching
@ipeevski It seems there is no easy way to solve it.
develop PHP-Parser's Formatting-preserving pretty printing.
We use MonkeyPatch in a few places
Excluding tests that use Monkey Patching from coverage (and turn Monkey Patching off) seems to be easy.
Excluding tests that use Monkey Patching seems like the best we could do until we rewrite tests I think Thanks for your help.
Hi using:
the Intellij ultimate IDE. PHPUnit 8.4.3 by Sebastian Bergmann and contributors. i have version 3.0.1 of your framework installed in /vendor/kenjis/ci-phpunit-test
I find that when i run the unit tests from the command line the xdebug debugger opens the correct file, but the line numbers are out. the line number being executed is in the 'shadow copy' which i have set application/tests/_ but this copy is not selected by the debugger when the tests are run.
i am not sure how the mapping between the 'shadow copy' and the code is maintained in your framework, but it seems off.
it is very difficult to debug unit tests now, previously this used to work fine.
are there any setup tricks/tips i can have to help here?
thanks.