GeneratorTest.php (2947B)
1 <?php 2 class Framework_MockObject_GeneratorTest extends PHPUnit_Framework_TestCase 3 { 4 /** 5 * @covers PHPUnit_Framework_MockObject_Generator::getMock 6 * @expectedException PHPUnit_Framework_Exception 7 */ 8 public function testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock() 9 { 10 PHPUnit_Framework_MockObject_Generator::getMock('StdClass', array(0)); 11 } 12 13 /** 14 * @covers PHPUnit_Framework_MockObject_Generator::getMock 15 */ 16 public function testGetMockCanCreateNonExistingFunctions() 17 { 18 $mock = PHPUnit_Framework_MockObject_Generator::getMock('StdClass', array('testFunction')); 19 $this->assertTrue(method_exists($mock, 'testFunction')); 20 } 21 22 /** 23 * @covers PHPUnit_Framework_MockObject_Generator::getMock 24 * @expectedException PHPUnit_Framework_Exception 25 * @expectedExceptionMessage duplicates: "foo, foo" 26 */ 27 public function testGetMockGeneratorFails() 28 { 29 $mock = PHPUnit_Framework_MockObject_Generator::getMock('StdClass', array('foo', 'foo')); 30 } 31 32 /** 33 * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass 34 */ 35 public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces() 36 { 37 $mock = PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass('Countable'); 38 $this->assertTrue(method_exists($mock, 'count')); 39 } 40 41 /** 42 * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass 43 */ 44 public function testGetMockForAbstractClassStubbingAbstractClass() 45 { 46 $mock = PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass('AbstractMockTestClass'); 47 $this->assertTrue(method_exists($mock, 'doSomething')); 48 } 49 50 /** 51 * @dataProvider getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider 52 * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass 53 * @expectedException PHPUnit_Framework_Exception 54 */ 55 public function testGetMockForAbstractClassExpectingInvalidArgumentException($className, $mockClassName) 56 { 57 $mock = PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass($className, array(), $mockClassName); 58 } 59 60 /** 61 * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass 62 * @expectedException PHPUnit_Framework_Exception 63 */ 64 public function testGetMockForAbstractClassAnstractClassDoesNotExist() 65 { 66 $mock = PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass('Tux'); 67 } 68 69 /** 70 * Dataprovider for test "testGetMockForAbstractClassExpectingInvalidArgumentException" 71 */ 72 public static function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider() 73 { 74 return array( 75 'className not a string' => array(array(), ''), 76 'mockClassName not a string' => array('Countable', new StdClass), 77 ); 78 } 79 }