MockBuilderTest.php (3458B)
1 <?php 2 /* 3 * This file is part of the PHPUnit_MockObject package. 4 * 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> 6 * 7 * For the full copyright and license information, please view the LICENSE 8 * file that was distributed with this source code. 9 */ 10 11 /** 12 * @since File available since Release 1.0.0 13 */ 14 class Framework_MockBuilderTest extends PHPUnit_Framework_TestCase 15 { 16 public function testMockBuilderRequiresClassName() 17 { 18 $spec = $this->getMockBuilder('Mockable'); 19 $mock = $spec->getMock(); 20 $this->assertTrue($mock instanceof Mockable); 21 } 22 23 public function testByDefaultMocksAllMethods() 24 { 25 $spec = $this->getMockBuilder('Mockable'); 26 $mock = $spec->getMock(); 27 $this->assertNull($mock->mockableMethod()); 28 $this->assertNull($mock->anotherMockableMethod()); 29 } 30 31 public function testMethodsToMockCanBeSpecified() 32 { 33 $spec = $this->getMockBuilder('Mockable'); 34 $spec->setMethods(array('mockableMethod')); 35 $mock = $spec->getMock(); 36 $this->assertNull($mock->mockableMethod()); 37 $this->assertTrue($mock->anotherMockableMethod()); 38 } 39 40 public function testByDefaultDoesNotPassArgumentsToTheConstructor() 41 { 42 $spec = $this->getMockBuilder('Mockable'); 43 $mock = $spec->getMock(); 44 $this->assertEquals(array(null, null), $mock->constructorArgs); 45 } 46 47 public function testMockClassNameCanBeSpecified() 48 { 49 $spec = $this->getMockBuilder('Mockable'); 50 $spec->setMockClassName('ACustomClassName'); 51 $mock = $spec->getMock(); 52 $this->assertTrue($mock instanceof ACustomClassName); 53 } 54 55 public function testConstructorArgumentsCanBeSpecified() 56 { 57 $spec = $this->getMockBuilder('Mockable'); 58 $spec->setConstructorArgs($expected = array(23, 42)); 59 $mock = $spec->getMock(); 60 $this->assertEquals($expected, $mock->constructorArgs); 61 } 62 63 public function testOriginalConstructorCanBeDisabled() 64 { 65 $spec = $this->getMockBuilder('Mockable'); 66 $spec->disableOriginalConstructor(); 67 $mock = $spec->getMock(); 68 $this->assertNull($mock->constructorArgs); 69 } 70 71 public function testByDefaultOriginalCloneIsPreserved() 72 { 73 $spec = $this->getMockBuilder('Mockable'); 74 $mock = $spec->getMock(); 75 $cloned = clone $mock; 76 $this->assertTrue($cloned->cloned); 77 } 78 79 public function testOriginalCloneCanBeDisabled() 80 { 81 $spec = $this->getMockBuilder('Mockable'); 82 $spec->disableOriginalClone(); 83 $mock = $spec->getMock(); 84 $mock->cloned = false; 85 $cloned = clone $mock; 86 $this->assertFalse($cloned->cloned); 87 } 88 89 public function testCallingAutoloadCanBeDisabled() 90 { 91 // it is not clear to me how to test this nor the difference 92 // between calling it or not 93 $this->markTestIncomplete(); 94 } 95 96 public function testProvidesAFluentInterface() 97 { 98 $spec = $this->getMockBuilder('Mockable') 99 ->setMethods(array('mockableMethod')) 100 ->setConstructorArgs(array()) 101 ->setMockClassName('DummyClassName') 102 ->disableOriginalConstructor() 103 ->disableOriginalClone() 104 ->disableAutoload(); 105 $this->assertTrue($spec instanceof PHPUnit_Framework_MockObject_MockBuilder); 106 } 107 }