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

Let methods be redefined #12

Open
stevegrunwell opened this issue Sep 30, 2020 · 0 comments · May be fixed by #18
Open

Let methods be redefined #12

stevegrunwell opened this issue Sep 30, 2020 · 0 comments · May be fixed by #18
Labels
enhancement New feature or request
Milestone

Comments

@stevegrunwell
Copy link
Member

PHPUnit has mocking tools built in, but they have the following limitations:

⚠️ Limitation: final, private, and static methods

Please note that final, private, and static methods cannot be stubbed or mocked. They are ignored by PHPUnit’s test double functionality and retain their original behavior except for static methods that will be replaced by a method throwing a \PHPUnit\Framework\MockObject\BadMethodCallException exception.

In PHP 7.x, we can get around this by using anonymous classes, but users still supporting PHP 5.6 are stuck.

To get around this, a Methods trait should be added with the following methods:

  • defineMethod(string $class, string $method, callable $function, string $visibility = 'public', bool $static = false)
  • redefineMethod(string $class, string $method, callable $function)
  • deleteMethod(string $class, string $method)

Careful attention should be paid to the visibility of methods, as well as whether or not they should be treated as static — Reflection will likely be used to handle these, as well as streamlining the definition of method arguments within Runkit.

@stevegrunwell stevegrunwell added the enhancement New feature or request label Sep 30, 2020
@stevegrunwell stevegrunwell added this to the Version 0.2.0 milestone Sep 30, 2020
stevegrunwell added a commit that referenced this issue Nov 24, 2020
This trait exposes three methods:

1. `defineMethod(string $class, string $name, \Closure $closure, string $visibility = 'public', bool $static = false): self`
2. `redefineMethod(string $class, string $name, ?\Closure $closure, ?string $visibility = null, ?bool $static = null): self`
3. `deleteMethod(string $class, string $name): self`

Refs #12.
@stevegrunwell stevegrunwell linked a pull request Nov 24, 2020 that will close this issue
1 task
stevegrunwell added a commit that referenced this issue Nov 24, 2020
This trait exposes three methods:

1. `defineMethod(string $class, string $name, \Closure $closure, string $visibility = 'public', bool $static = false): self`
2. `redefineMethod(string $class, string $name, ?\Closure $closure, ?string $visibility = null, ?bool $static = null): self`
3. `deleteMethod(string $class, string $name): self`

Refs #12.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant