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

#40 Sender instance passed to the Factory #50

Merged
merged 3 commits into from
Mar 2, 2021

Conversation

danbilauca
Copy link
Collaborator

@danbilauca danbilauca commented Feb 19, 2021

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.


$message = $this->message_factory->create( $message_args );
[ $message_args, $recipients_args, $sender_args ] = $this->validate( $args );
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

*
* @return WPNotify_Sender
*/
public function create( string $name ): WPNotify_Sender;
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Comment on lines +8 to +21
$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' ) );
Copy link
Collaborator

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.

@raaaahman raaaahman added [Scope] Model Definition of the data used in the WP Notify project [Type] Feature Describe a feature to be added to the project labels Mar 1, 2021
@raaaahman raaaahman merged commit e6a437d into develop Mar 2, 2021
@raaaahman raaaahman deleted the (Feature)-factory-with-sender branch March 2, 2021 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Scope] Model Definition of the data used in the WP Notify project [Type] Feature Describe a feature to be added to the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants