Search code examples
yii2phpunitstripe-paymentscodeception

How to mock Stripe classes in PHP Codeception


I am trying to mock a simple Stripe\Customer instance in a unit test. The method only uses this instance to retrieve the name property. In my test, the make statement looks like this:

$customer = $this->makeEmpty(Customer::class, ['name' => $cust_nm]);

Codeception returns the following error:

Could not add property name, class Stripe\Customer implements __set method, and no name property exists

I have also tried to use makeEmptyExcept but get the same error message. All I really want is to pass the object to a method and pull a property or two.

Any suggestions?


Solution

  • Don't mock it, simply create an instance and set a property.

    $customer = new Customer();
    $customer->name = $cust_nm;