Skip to content
This repository
Browse code

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...
commit 32f5dbb86083cdc6c38a62be0bf53b766236ac05 1 parent c36c4ad
Dave Marshall authored September 23, 2012
1  library/Mockery/Generator.php
@@ -155,6 +155,7 @@ public static function applyMockeryTo(\ReflectionClass $class,
155 155
             && $method->getName() !== '__wakeup'
156 156
             && $method->getName() !== '__set'
157 157
             && $method->getName() !== '__get'
  158
+            && $method->getName() !== '__toString'
158 159
             && $method->getName() !== '__isset') {
159 160
                 $definition .= self::_replacePublicMethod($method);
160 161
             }
16  tests/Mockery/ContainerTest.php
@@ -662,6 +662,17 @@ public function testCallingSelfOnlyReturnsLastMockCreatedOrCurrentMockBeingProgr
662 662
         //$this->assertTrue(\Mockery::self() instanceof MockeryTestFoo);
663 663
         \Mockery::resetContainer();
664 664
     }
  665
+
  666
+    /**
  667
+     * @issue issue/89
  668
+     */
  669
+    public function testCreatingMockOfClassWithExistingToStringMethodDoesntCreateClassWithTwoToStringMethods()
  670
+    {
  671
+        \Mockery::setContainer($this->container);
  672
+        $m = $this->container->mock('MockeryTest_WithToString'); // this would fatal
  673
+        $m->shouldReceive("__toString")->andReturn('dave');
  674
+        $this->assertEquals("dave", "$m");
  675
+    }
665 676
     
666 677
     public function testGetExpectationCount_freshContainer()
667 678
     {
@@ -841,3 +852,8 @@ class MockeryTest_MockCallableTypeHint {
841 852
         public function foo(callable $baz) {$baz();}
842 853
     }
843 854
 }
  855
+
  856
+class MockeryTest_WithToString {
  857
+    public function __toString() {}
  858
+}
  859
+

0 notes on commit 32f5dbb

Please sign in to comment.
Something went wrong with that request. Please try again.