Changeset 1289
- Timestamp:
- 01/23/08 20:49:17 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/experiments/general/PHPUnit/phpunit_mock.patch
r1284 r1289 1 1 Index: PHPUnit/Framework/TestCase.php 2 2 =================================================================== 3 --- PHPUnit/Framework/TestCase.php (revision 226 9)3 --- PHPUnit/Framework/TestCase.php (revision 2263) 4 4 +++ PHPUnit/Framework/TestCase.php (working copy) 5 5 @@ -217,6 +217,12 @@ … … 16 16 * 17 17 * @param string $name 18 @@ -621,18 +627, 28@@18 @@ -621,18 +627,32 @@ 19 19 throw new InvalidArgumentException; 20 20 } … … 29 29 - ); 30 30 + $key = md5($className . serialize($methods)); 31 + if (isset(self::$mockClasses[$key]) === false ) {31 + if (isset(self::$mockClasses[$key]) === false || empty($mockClassName) === false) { 32 32 + $mock = PHPUnit_Framework_MockObject_Mock::generate( 33 33 + $className, … … 38 38 + $callAutoload 39 39 + ); 40 +41 + self::$mockClasses[$key] = $mock->mockClassName;42 + }43 40 44 41 - $mockClass = new ReflectionClass($mock->mockClassName); 45 42 - $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 + } 46 50 47 51 + if (count($arguments) === 0) { 48 + $mockObject = new self::$mockClasses[$key]();52 + $mockObject = new $mockClassName(); 49 53 + } else { 50 + $mockClass = new ReflectionClass( self::$mockClasses[$key]);54 + $mockClass = new ReflectionClass($mockClassName); 51 55 + $mockObject = $mockClass->newInstanceArgs($arguments); 52 56 + } … … 133 137 Index: PHPUnit/Tests/Framework/MockObjectTest.php 134 138 =================================================================== 135 --- PHPUnit/Tests/Framework/MockObjectTest.php (revision 226 9)139 --- PHPUnit/Tests/Framework/MockObjectTest.php (revision 2263) 136 140 +++ PHPUnit/Tests/Framework/MockObjectTest.php (working copy) 137 141 @@ -47,6 +47,7 @@ … … 151 155 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 152 156 * @version Release: @package_version@ 153 @@ -145,5 +147, 29@@157 @@ -145,5 +147,54 @@ 154 158 155 159 $this->assertEquals('something', $mock->doSomething()); … … 179 183 + $this->assertEquals(get_class($mock4), get_class($mock5)); 180 184 + } 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 + } 181 210 } 182 211 ?>
