-
Notifications
You must be signed in to change notification settings - Fork 19
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
#40 Sender instance passed to the Factory #50
Conversation
includes/Factory.php
Outdated
|
||
$message = $this->message_factory->create( $message_args ); | ||
[ $message_args, $recipients_args, $sender_args ] = $this->validate( $args ); |
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.
Short array syntax is not in the WordPress coding standards...
We should configure the PHP Code Sniffer to help us with these standards.
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've fixed it by using array
includes/senders/SenderFactory.php
Outdated
* | ||
* @return WPNotify_Sender | ||
*/ | ||
public function create( string $name ): WPNotify_Sender; |
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'm not sure if we should use static type hinting or not.
What would be the benefits in your opinion?
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.
yep, fixed it by removing it
$vendor_sender = $this->createMock( 'WPNotify_Sender' ); | ||
|
||
$message_factory = $this->getMockBuilder( 'WPNotify_MessageFactory' ) | ||
->setMethods( array( 'create', 'accepts' ) ) | ||
->getMock(); | ||
|
||
$message_factory->method( 'create' )->willReturn( $this->createMock( 'WPNotify_Message' ) ); | ||
$message_factory->method( 'accepts' )->willReturn( true ); | ||
|
||
$sender_factory = $this->getMockBuilder( 'WPNotify_SenderFactory' ) | ||
->setMethods( array( 'create' ) ) | ||
->getMock(); | ||
|
||
$sender_factory->method( 'create' )->willReturn( $this->createMock( 'WPNotify_Sender' ) ); |
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.
Good. With all these mocks, you won't have to rewrite your test each time we change the code of any of these factories.
I've chosen to implement a Sender Factory and send it along to Factory's constructor in order to have code consistency and have it processed/validated by Factory's logic.