Skip to content
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

Breakpoint; debugging tests #399

Open
kale1d0code opened this issue Feb 1, 2022 · 4 comments
Open

Breakpoint; debugging tests #399

kale1d0code opened this issue Feb 1, 2022 · 4 comments

Comments

@kale1d0code
Copy link

Hi,

Thanks for Kahlan brilliant project,
however I have problems when it comes to debugging code I've written,
breakpoints won't trigger in files outside of the file where the test is defined

I understand that kahlan recreates code referenced in tests due to it's implementation etc and thats why the breakpoints aren't reached (because that file isn't actually being run)

Is there anyway around this or anything I can do in my IDE so that breakpoints work whilst tests are being run?

I'm using vscode

@jails
Copy link
Contributor

jails commented Feb 20, 2022

Hi,
You're totally right about your hypothesis. Indeed executed files are in the sys_get_temp_dir() so I guess your breakpoints should be setted on the files there.
It's indeed not ideal and it's more a hack that an answer to your question.
But unfortunately, I'm not quite familiar with PHP debugger just player once or twice with them and finally stopped using them.

@windaishi
Copy link

As I understand it, Kahlan does not test the original source code, but rather creates a copy and adds its own code to the copy. This is made to mock static methods, but I have noticed that there is additional code inserted at the beginning and end of functions.

I understand the purpose of these modifications, but as a developer, I would prefer if my code remains unchanged during testing. Is it possible to provide an option to disable the features that require copying and modification of the original source code, so that my code remains untouched during testing?

@windaishi
Copy link

windaishi commented Feb 10, 2023

Oh, after a short research I found that I can disable the patching via the following code in my kahlan-config.php:

$this->commandLine()->set('exclude', [
    'Namespace'
]);

This disables patching for all the classes in that namespace and now my breakpoints work again. Maybe it is a late reply @kale1d0code, but I hope it may still help you.

@michalfelski
Copy link
Collaborator

Did you try to add xdebug_break() in the code instead of breakpoints in your IDE? This should break in generated code as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants