0

I have a bad situation where a class i want to test is extending another class that has a pretty complex public static method. This wouldn't be such an issue if the parent class wasn't extending other classes that are required. In specific, I need \Illuminate\Database\Eloquent\Model to still be extended. My hands are tied regarding possible refactor to make this easier to test.

Is there any way to stub or change the parents of the class in question, while still allowing the Model class to perform?

2 Answers 2

2

Maybe you could create a YourClassTestCase that extends the class you are testing. Then, in YourClassTestCase override static method with a simplified return and launch the test over YourClassTestCase.

So you will have YourTest -> yourClassTestCase -> YourClass -> ParentWithStaticMethod.

0

You should use Mock Objects. See here:https://phpunit.de/manual/current/en/test-doubles.html#test-doubles.mock-objects

1
  • Standard mocks don't do the trick here. I have to find a way to completely stub the parent class, while keeping the grandparent, or find a way to replace the parent with a different parent. Trying to stub the single static method in the parent would work if I could isolate the scope of alias to just the parent. Commented Sep 27, 2017 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.