Changeset 1289

Show
Ignore:
Timestamp:
01/23/08 20:49:17 (7 months ago)
Author:
mikey
Message:

changed PHPUnit patch to allow overruling of mock class cache (more bc stuff)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/experiments/general/PHPUnit/phpunit_mock.patch

    r1284 r1289  
    11Index: PHPUnit/Framework/TestCase.php 
    22=================================================================== 
    3 --- PHPUnit/Framework/TestCase.php  (revision 2269
     3--- PHPUnit/Framework/TestCase.php  (revision 2263
    44+++ PHPUnit/Framework/TestCase.php  (working copy) 
    55@@ -217,6 +217,12 @@ 
     
    1616      * 
    1717      * @param  string $name 
    18 @@ -621,18 +627,28 @@ 
     18@@ -621,18 +627,32 @@ 
    1919             throw new InvalidArgumentException; 
    2020         } 
     
    2929-        ); 
    3030+        $key = md5($className . serialize($methods)); 
    31 +        if (isset(self::$mockClasses[$key]) === false) { 
     31+        if (isset(self::$mockClasses[$key]) === false || empty($mockClassName) === false) { 
    3232+            $mock = PHPUnit_Framework_MockObject_Mock::generate( 
    3333+              $className, 
     
    3838+              $callAutoload 
    3939+            ); 
    40 +             
    41 +            self::$mockClasses[$key] = $mock->mockClassName; 
    42 +        } 
    4340  
    4441-        $mockClass  = new ReflectionClass($mock->mockClassName); 
    4542-        $mockObject = $mockClass->newInstanceArgs($arguments); 
     43+            if (empty($mockClassName) === true) { 
     44+                self::$mockClasses[$key] = $mock->mockClassName; 
     45+                $mockClassName           = $mock->mockClassName; 
     46+            } 
     47+        } else { 
     48+            $mockClassName = self::$mockClasses[$key]; 
     49+        } 
    4650  
    4751+        if (count($arguments) === 0) { 
    48 +            $mockObject = new self::$mockClasses[$key](); 
     52+            $mockObject = new $mockClassName(); 
    4953+        } else { 
    50 +            $mockClass  = new ReflectionClass(self::$mockClasses[$key]); 
     54+            $mockClass  = new ReflectionClass($mockClassName); 
    5155+            $mockObject = $mockClass->newInstanceArgs($arguments); 
    5256+        } 
     
    133137Index: PHPUnit/Tests/Framework/MockObjectTest.php 
    134138=================================================================== 
    135 --- PHPUnit/Tests/Framework/MockObjectTest.php  (revision 2269
     139--- PHPUnit/Tests/Framework/MockObjectTest.php  (revision 2263
    136140+++ PHPUnit/Tests/Framework/MockObjectTest.php  (working copy) 
    137141@@ -47,6 +47,7 @@ 
     
    151155  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License 
    152156  * @version    Release: @package_version@ 
    153 @@ -145,5 +147,29 @@ 
     157@@ -145,5 +147,54 @@ 
    154158  
    155159         $this->assertEquals('something', $mock->doSomething()); 
     
    179183+        $this->assertEquals(get_class($mock4), get_class($mock5)); 
    180184+    } 
     185+ 
     186+    public function testMockClassStoreOverrulable() 
     187+    { 
     188+        $mock1 = $this->getMock('PartialMockTestClass'); 
     189+        $mock2 = $this->getMock('PartialMockTestClass', array(), array(), 'MyMockClassNameForPartialMockTestClass1'); 
     190+        $mock3 = $this->getMock('PartialMockTestClass'); 
     191+        $mock4 = $this->getMock('PartialMockTestClass', array('doSomething'), array(), 'AnotherMockClassNameForPartialMockTestClass'); 
     192+        $mock5 = $this->getMock('PartialMockTestClass', array(), array(), 'MyMockClassNameForPartialMockTestClass2'); 
     193+        $this->assertNotEquals(get_class($mock1), get_class($mock2)); 
     194+        $this->assertEquals(get_class($mock1), get_class($mock3)); 
     195+        $this->assertNotEquals(get_class($mock1), get_class($mock4)); 
     196+        $this->assertNotEquals(get_class($mock2), get_class($mock3)); 
     197+        $this->assertNotEquals(get_class($mock2), get_class($mock4)); 
     198+        $this->assertNotEquals(get_class($mock2), get_class($mock5)); 
     199+        $this->assertNotEquals(get_class($mock3), get_class($mock4)); 
     200+        $this->assertNotEquals(get_class($mock3), get_class($mock5)); 
     201+        $this->assertNotEquals(get_class($mock4), get_class($mock5)); 
     202+    } 
     203+ 
     204+    public function testMockClassStoreOverruleSameClassNameThrowsException() 
     205+    { 
     206+        $mock1 = $this->getMock('PartialMockTestClass', array(), array(), __FUNCTION__); 
     207+        $this->setExpectedException('RuntimeException'); 
     208+        $mock2 = $this->getMock('PartialMockTestClass', array(), array(), __FUNCTION__); 
     209+    } 
    181210 } 
    182211 ?>