Skip to content

Create a StripeFactory to be testable/mockable #4

Description

@Nightbr

Hey,

I think we shouldn't directly call Stripe/Stripe::Method or $stripeEventApi = new Stripe\Event(); because it is mockable and so untestable.

In Stripe folder we can create a StripeFactory which is a class declare as a service and we can inject it into our controller, service, ...

public function handleAction(Request $request, StripeFactory $stripeFactory)

And we can use $stripeFactory->createEvent();

Thanks to this pattern we can easily mock the StripeFactory and mock Stripe method in order to make tests.

Add to this, the factory can be exposed and used outside the bundle (in main App).

What do you think of this?

EDIT: we can be inspired by this StripeClient: https://github.com/flo-sch/stripe-bundle/blob/master/Stripe/StripeClient.php for our factory.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions