You Are Here: Home Documentation Code Snippets Stub Method Calls

Enhance PHP Unit Testing And Mocking Framework improve the quality

Stub Method Calls

Here are some examples of using a stub in Enhance PHP. A stub is similar to a mock, but is not used to pass or fail a test - it is simply there to enable the test to happen!

Getting A Stub Class

$stub = \Enhance\StubFactory::createStub('myClassName');

To get a stub class, simply ask the StubFactory to create a stub and pass in the name of the class. What makes this a stub rather than a mock? We won't make the call to verifyExpectations at the end of our test.

Typical Usage

Normally, you would only need set the following for a stub:

$stub->addExpectation(\Enhance\Expect::method('GetSomething')->returns('Something'));

You can optionally add the with() clause, for example if you wanted to return different values based on the arguments passed in. You can specify a times() clause, but this is not normally needed for a stub. If you want to set a times() clause, do you actually want to use a mock instead?