Skip to content
This repository

No error when method does not exist on class #78

MarkRoddy opened this Issue · 1 comment

2 participants

MarkRoddy Jeff Welch

There are two method calls that accept the names of methods to be mocked or stubbed on a mock object that when given a method that does not exist on the actual object do not result in an error or warning. This makes typos very difficult to diagnoise.

In the code samples below, the ExampleClass has methods foo() and bar().

As seen below, when setting an expectation for a method, there is a typo in the name of the method specified. Ideally this would raise an error and cause the test to fail so it could be quickly corrected. Also good would be if a warning was issued that the method does not exist. Currently, there is no indication that anything is wrong. This at best leads to difficult to diagnose errors, at worst it could lead to tests which pass when they should not.

    public function testTypoForMockExpectation() {
    $sut = $this->getMockBuilder("ExampleClass")
        $this->assertEquals(5, $sut->bar(1));

Additionly, the same problem exists when specifying a set of methods to to be set at mock creation time.

   public function testTypoWhenCreatingMock() {
        $sut = $this->getMockBuilder("ExampleClass_ErrorInMethodNameOverride")
        $this->assertEquals(5, $sut->bar(1));
Jeff Welch

This is covered by #12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.