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

Add getService methods to StripeClient and AbstractServiceFactory to allow mocking #1381

Conversation

pakrym-stripe
Copy link
Contributor

@pakrym-stripe pakrym-stripe commented Oct 17, 2022

Mocking magic methods is problematic. Add named methods that customers can override.

$mock = Mockery::mock(\Stripe\StripeClient::class);

$terminalMock = Mockery::mock(\Stripe\Service\Terminal\TerminalServiceFactory::class);

$mock->shouldReceive('getService')
    ->with("terminal")
    ->once()
    ->andReturn($terminalMock);

$terminalMock->shouldReceive('getService')
    ->with("readers")
    ->once()
    ->andReturn($reader);

var_dump($mock->terminal->readers);

Fixes #1350.

@pakrym-stripe pakrym-stripe enabled auto-merge (squash) January 19, 2023 19:05
@pakrym-stripe pakrym-stripe merged commit fcee249 into master Jan 19, 2023
@remi-stripe remi-stripe deleted the pakrym/Add_getService_methods_to_StripeClient_and_AbstractServiceFactory_to_allow_mocking branch September 28, 2023 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants