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

Allow to mock internal php classes #21

Merged
merged 2 commits into from
Feb 23, 2015
Merged

Conversation

tomaszdurka
Copy link
Owner

Problems:

  • Cannot extract reflection method paramaters from some method.
  • Throwing exception when mocking internal php classes which use reserved keywords for method names (e.g. GearmanClient::clone())

@tomaszdurka tomaszdurka self-assigned this Jan 2, 2015
@tomaszdurka tomaszdurka changed the title Throwing exception when mocking internal php classes which use reserved keywords for method names (e.g. GearmanClient) Allow to mock internal php classes Jan 2, 2015
@alexispeter
Copy link
Contributor

First problem refers to default values for optional parameters in internal php classes.
See Notes at http://php.net/manual/en/reflectionparameter.getdefaultvalue.php

Note:
Due to implementation details, it is not possible to get the default value of built-in functions or methods of built-in classes. Trying to do this will result a ReflectionException being thrown.

@tomaszdurka
Copy link
Owner Author

I forgot to update issue as I did some research last friday.

The problem with optional paramter default value is solvable by checking 'isDefaultValueAvailable`. I am not sure how it works exactly as it seems you sometimes cannot access it, but it doesn't matter it doesn't exist. I don't believe there is workaroud for that.

Another problem is that those php extensions sometimes use reserved keywords for method names (like clone for gearman). It's actually bad code of those extensions to use those reserved keyowrds. Only solution would be to not mock those methods - ignore them. Problem is that there is no built-in function to get all actual (for current version) php reserved keywords. I would need to hardcode them.

@alexispeter any ideas?

@alexispeter
Copy link
Contributor

I messed around with runkit for a while, but unfortunately it doesn't allow manipulation of internal classes.
I would simply hardcode reserved keywords and ignore methods with keywords as names, seems phpunit does something similar with their mock framework (You can't perform assertions on "reserved keyword functions".)

@tomaszdurka
Copy link
Owner Author

fyi @alexispeter

tomaszdurka added a commit that referenced this pull request Feb 23, 2015
@tomaszdurka tomaszdurka merged commit 1541bad into master Feb 23, 2015
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

Successfully merging this pull request may close these issues.

None yet

2 participants