Permalink
Browse files

Fix regression from #81, __toString added twice

If __toString already exists on a class, we don't need to include it in the
class definition twice, so skip it during the public method replacement phase.
  • Loading branch information...
1 parent c36c4ad commit 32f5dbb86083cdc6c38a62be0bf53b766236ac05 @davedevelopment davedevelopment committed Sep 23, 2012
Showing with 17 additions and 0 deletions.
  1. +1 −0 library/Mockery/Generator.php
  2. +16 −0 tests/Mockery/ContainerTest.php
@@ -155,6 +155,7 @@ public static function applyMockeryTo(\ReflectionClass $class,
&& $method->getName() !== '__wakeup'
&& $method->getName() !== '__set'
&& $method->getName() !== '__get'
+ && $method->getName() !== '__toString'
&& $method->getName() !== '__isset') {
$definition .= self::_replacePublicMethod($method);
}
@@ -662,6 +662,17 @@ public function testCallingSelfOnlyReturnsLastMockCreatedOrCurrentMockBeingProgr
//$this->assertTrue(\Mockery::self() instanceof MockeryTestFoo);
\Mockery::resetContainer();
}
+
+ /**
+ * @issue issue/89
+ */
+ public function testCreatingMockOfClassWithExistingToStringMethodDoesntCreateClassWithTwoToStringMethods()
+ {
+ \Mockery::setContainer($this->container);
+ $m = $this->container->mock('MockeryTest_WithToString'); // this would fatal
+ $m->shouldReceive("__toString")->andReturn('dave');
+ $this->assertEquals("dave", "$m");
+ }
public function testGetExpectationCount_freshContainer()
{
@@ -841,3 +852,8 @@ class MockeryTest_MockCallableTypeHint {
public function foo(callable $baz) {$baz();}
}
}
+
+class MockeryTest_WithToString {
+ public function __toString() {}
+}
+

0 comments on commit 32f5dbb

Please sign in to comment.