-
-
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
Let the DocBlock::ofMethod handle an ~optional~ className #3885
Changes from 4 commits
7170404
c39d04e
48d3752
d3d5909
d5c349c
e59d87b
78811f4
0d41055
e6f1e6d
79c42c9
f57f550
058d6ab
89bfa40
c70d792
649b496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,10 @@ public static function ofClass(\ReflectionClass $class): self | |
); | ||
} | ||
|
||
public static function ofMethod(\ReflectionMethod $method): self | ||
/** | ||
* @psalm-param class-string $className | ||
*/ | ||
public static function ofMethod(\ReflectionMethod $method, string $className = null): self | ||
{ | ||
return new self( | ||
(string) $method->getDocComment(), | ||
|
@@ -111,7 +114,7 @@ public static function ofMethod(\ReflectionMethod $method): self | |
$method->getEndLine(), | ||
$method->getFileName(), | ||
$method->getName(), | ||
$method->getDeclaringClass()->getName() | ||
$className ?? $method->getDeclaringClass()->getName() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If fetching the specific class is the use-case, then I suggest making the new argument mandatory, and naming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely, it's not optional. |
||
); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ public function forClassName(string $class): DocBlock | |
|
||
/** | ||
* @throws Exception | ||
* @psalm-param class-string $className | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ow, not sure how this made it through 😱 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's with this psalm-param? I do not really understand it, I copied it to more locations, seemed logical to me There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a restriction on the All good BTW 👍 |
||
* @psalm-param class-string $class | ||
*/ | ||
public function forMethod(string $class, string $method): DocBlock | ||
{ | ||
|
@@ -80,6 +80,6 @@ public function forMethod(string $class, string $method): DocBlock | |
); | ||
} | ||
|
||
return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection); | ||
return $this->methodDocBlocks[$class][$method] = DocBlock::ofMethod($reflection, $class); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of PHPUnit. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
abstract class AbstractVariousIterableDataProviderTest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is being tested with this added fixture? I suggest adding a test for what this is checking. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solved |
||
{ | ||
abstract public function asArrayProvider(); | ||
|
||
abstract public function asIteratorProvider(); | ||
|
||
abstract public function asTraversableProvider(); | ||
|
||
public function asArrayProviderInParent() | ||
{ | ||
return [ | ||
['J'], | ||
['K'], | ||
['L'], | ||
]; | ||
} | ||
|
||
public function asIteratorProviderInParent() | ||
{ | ||
yield ['M']; | ||
|
||
yield ['N']; | ||
|
||
yield ['O']; | ||
} | ||
|
||
public function asTraversableProviderInParent() | ||
{ | ||
return new WrapperIteratorAggregate([ | ||
['P'], | ||
['Q'], | ||
['R'], | ||
]); | ||
} | ||
|
||
/** | ||
* @dataProvider asArrayProvider | ||
* @dataProvider asIteratorProvider | ||
* @dataProvider asTraversableProvider | ||
* @dataProvider asArrayProviderInParent | ||
* @dataProvider asIteratorProviderInParent | ||
* @dataProvider asTraversableProviderInParent | ||
*/ | ||
public function testAbstract(): void | ||
{ | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ | |
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
class VariousIterableDataProviderTest | ||
class VariousIterableDataProviderTest extends AbstractVariousIterableDataProviderTest | ||
{ | ||
public static function asArrayProvider() | ||
public function asArrayProvider() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would suggest not changing these as part of thr patch: write independent/new fixtures instead. Changing this means changing tests that might be affected by the bug and/or fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed them and wrote similar tests. I hope it is clear, would be happy to hear how it could be done better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd generally suggest reverting the old asset changes: they do prevent regressions (like the one that you are fixing - and BTW thanks very much for your efforts!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now kept the old test, but named it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
{ | ||
return [ | ||
['A'], | ||
|
@@ -18,7 +18,7 @@ public static function asArrayProvider() | |
]; | ||
} | ||
|
||
public static function asIteratorProvider() | ||
public function asIteratorProvider() | ||
{ | ||
yield ['D']; | ||
|
||
|
@@ -27,7 +27,7 @@ public static function asIteratorProvider() | |
yield ['F']; | ||
} | ||
|
||
public static function asTraversableProvider() | ||
public function asTraversableProvider() | ||
{ | ||
return new WrapperIteratorAggregate([ | ||
['G'], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there are two ways to create DocBlock object
Unfortunately, you can not obtain class namespace from method reflection object, only class that declares method.
Maybe it's better to describe only one method to create a DocBlock object e.g.
or make a public constructor
@Ocramius what do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about separate named ctors (as separate static methods)?
Also, please keep the ctor private: that's what gave us this flexibility in first place 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a difference between docblocks of classes and those of methods right? I think the current structure makes that quite clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, all good with that