-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support for Property Hooks in Test Doubles #5948
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❌ We are unable to process any of the uploaded JUnit XML files. Please ensure your files are in the right format. Additional details and impacted files@@ Coverage Diff @@
## main #5948 +/- ##
============================================
+ Coverage 94.66% 94.69% +0.02%
- Complexity 6745 6779 +34
============================================
Files 712 716 +4
Lines 20354 20467 +113
============================================
+ Hits 19269 19381 +112
- Misses 1085 1086 +1 ☔ View full report in Codecov by Sentry. |
I know this still in draft, but we should also support mocking abstract properties in abstract classes using similar functionality to the above. |
7cfd5df
to
5992c83
Compare
771d2ed
to
97375eb
Compare
27266e7
to
6963b30
Compare
@joseph-sentry Can you provide insight as to why we get |
FYI I'm playing around with what you have so far (thank you for this!!), and found the following bug when mocking a nullable property getter: use PHPUnit\Framework\TestCase;
interface Foo
{
public ?Bar $bar { get; }
}
interface Bar {}
class MyTest extends TestCase
{
public function testNullablePropertyGetter(): void
{
$bar = $this->createMock(\Bar::class);
$foo = $this->createMock(\Foo::class);
$foo->method('$bar::get')
->willReturn($bar);
// Dummy assertion...
$this->assertTrue(true);
}
} Running this test will give you the following error:
|
Thank you, but that is expected. At least for me ;-) Jokes aside, yes, I know that not all bases are covered yet when it comes to type declarations. |
The codecov JUnit error is due to a parser error on our end where I assumed that a |
This reverts commit 1d34cc7.
This reverts commit 23607f9.
… exist for PhpStorm
2e3e0a9
to
e3ce86c
Compare
Please try again with the current state of the branch. |
Please note that while ...
... still works, you should use |
Updated to the latest commit in this branch, but now I'm back to the same error I got before you implemented the feature, which is
Running
|
You need the current state of PHP 8.4 (with php/php-src@d75a289 and php/php-src@2fce0bb). |
Ah, good catch. Compiled latest on |
PHP 8.4 introduces property hooks.
PHPUnit's test double functionality should support doubling property hooks and allow the configuration of return values for get hooks and expectations for set hooks.
Here is an example of what configuring test stubs and mock objects for the interface
I
shown above could look like:Support for abstract classes with abstract property hooks will not be implemented as
getMockForAbstractClass()
is deprecated and will be removed in PHPUnit 12.