-
-
Notifications
You must be signed in to change notification settings - Fork 7
Conversation
src/HigherOrderExpectation.php
Outdated
|
||
/** | ||
* Creates a new higher order expectation. | ||
*/ | ||
public function __construct(Expectation $original, string $property) | ||
public function __construct(Expectation $original, string $name, bool $asMethod = false, ...$arguments) |
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.
Could the $asMethod
and $arguments
be passed in a separate method?
return (new HigherOrderExpectation($this, $method))->asMethod(...$parameters);
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.
I thought exactly this but went with parameters to allow the expectation set-up to happen in the constructor?
I'm not sure of a clean way to defer the setup of the expectation in the class without having everywhere that calls $this->expectation
to instead call $this->expectation()
and have that method as:
private function expectation()
{
return $this->expectation ??= // Set up the expectation here
}
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.
@lukeraymonddowning - I've added static constructors as one way at solving this:
return HigherOrderExpectation::forProperty($this, $name)
return HigherOrderExpectation::forMethod($this, $name, ...$parameters)
I'm not sure if static constructors are in fitting with this project's code style but I thought it was at least worth presenting it.
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.
Could we instead assume asMethod
if the constructor received more than 2 arguments? Perhaps remove the varadic and have it as an array.
Just thinking that when you look at the static constructors they're actually remarkably similar and properties will never have arguments.
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.
@lukeraymonddowning chef's kiss. Great call, thank you 🔥
Wow, amazing! @nunomaduro, should I start on something for the docs, or do you have more things brewing? 😀 |
@nedwors please crack on and start work on the docs 👌 |
I'll get on it tonight 👍 |
@nedwors Thank you! |
@nunomaduro, @lukeraymonddowning PR opened - pestphp/docs#57. Any and all suggestions welcome! |
Hi!
Thanks for the amazing package 🚀
This is a PR to allow properties to be dynamically accessed from the expectation value. For example, given a User, the following is possible:
I appreciate this PR is quite heavy on additions - eg. changing how the
__get
method functions inExpectation
- and I may have missed something along the way. So, it might not even be desired. But I thought it was a cool feature to submit and see what everyone thinks. Happy to hear all thoughts and suggestions.Thanks!
Update:
Support for methods has been added. So now the following would be possible:
And even: