|
|
|
|
|
by jrockway
5014 days ago
|
|
So does PHP not let you mock things by actually writing classes in the test file, like: class FakeFooBar(FooBar):
def my_method(self, *args):
self.last_my_method_args = args
return self.result
class TestFooBar(TestCase):
def test_my_method(self):
foobar = FakeFooBar()
foobar.result = 42
self.assertEquals(
foobar.use_my_method('hello world'), 'forty two')
self.assertEquals(
foobar.last_my_method_args, ['hello world'])
This is more verbose than mocking things out, but the control flow is more obvious and you don't have to rewrite the entire test case every time you change one tiny implementation detail (which is what I've had to do with every mox test I've ever written).Actually, it's not even that verbose compared to mox :) |
|
Defining mocks manually is my preferred method. I find things like Phake and Mockery to be a little too opaque and hard to debug when you get subtle problems. I think they also add to the learning curve when getting new devs up to speed.
IMO one reason a lot of PHP devs avoid the manual method of defining mocks is just laziness.