Skip to content

No error when method does not exist on class #78

MarkRoddy opened this Issue Jan 27, 2012 · 1 comment

2 participants


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));

This is covered by #12.

@whatthejeff whatthejeff closed this Nov 9, 2013
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.