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 11class Framework_MockBuilderTest extends PHPUnit_Framework_TestCase 12{ 13 public function testMockBuilderRequiresClassName() 14 { 15 $mock = $this->getMockBuilder(Mockable::class)->getMock(); 16 17 $this->assertTrue($mock instanceof Mockable); 18 } 19 20 public function testByDefaultMocksAllMethods() 21 { 22 $mock = $this->getMockBuilder(Mockable::class)->getMock(); 23 24 $this->assertNull($mock->mockableMethod()); 25 $this->assertNull($mock->anotherMockableMethod()); 26 } 27 28 public function testMethodsToMockCanBeSpecified() 29 { 30 $mock = $this->getMockBuilder(Mockable::class) 31 ->setMethods(['mockableMethod']) 32 ->getMock(); 33 34 $this->assertNull($mock->mockableMethod()); 35 $this->assertTrue($mock->anotherMockableMethod()); 36 } 37 38 public function testMethodExceptionsToMockCanBeSpecified() 39 { 40 $mock = $this->getMockBuilder(Mockable::class) 41 ->setMethodsExcept(['mockableMethod']) 42 ->getMock(); 43 44 $this->assertTrue($mock->mockableMethod()); 45 $this->assertNull($mock->anotherMockableMethod()); 46 } 47 48 public function testEmptyMethodExceptionsToMockCanBeSpecified() 49 { 50 $mock = $this->getMockBuilder(Mockable::class) 51 ->setMethodsExcept() 52 ->getMock(); 53 54 $this->assertNull($mock->mockableMethod()); 55 $this->assertNull($mock->anotherMockableMethod()); 56 } 57 58 public function testByDefaultDoesNotPassArgumentsToTheConstructor() 59 { 60 $mock = $this->getMockBuilder(Mockable::class)->getMock(); 61 62 $this->assertEquals([null, null], $mock->constructorArgs); 63 } 64 65 public function testMockClassNameCanBeSpecified() 66 { 67 $mock = $this->getMockBuilder(Mockable::class) 68 ->setMockClassName('ACustomClassName') 69 ->getMock(); 70 71 $this->assertTrue($mock instanceof ACustomClassName); 72 } 73 74 public function testConstructorArgumentsCanBeSpecified() 75 { 76 $mock = $this->getMockBuilder(Mockable::class) 77 ->setConstructorArgs([23, 42]) 78 ->getMock(); 79 80 $this->assertEquals([23, 42], $mock->constructorArgs); 81 } 82 83 public function testOriginalConstructorCanBeDisabled() 84 { 85 $mock = $this->getMockBuilder(Mockable::class) 86 ->disableOriginalConstructor() 87 ->getMock(); 88 89 $this->assertNull($mock->constructorArgs); 90 } 91 92 public function testByDefaultOriginalCloneIsPreserved() 93 { 94 $mock = $this->getMockBuilder(Mockable::class) 95 ->getMock(); 96 97 $cloned = clone $mock; 98 99 $this->assertTrue($cloned->cloned); 100 } 101 102 public function testOriginalCloneCanBeDisabled() 103 { 104 $mock = $this->getMockBuilder(Mockable::class) 105 ->disableOriginalClone() 106 ->getMock(); 107 108 $mock->cloned = false; 109 $cloned = clone $mock; 110 111 $this->assertFalse($cloned->cloned); 112 } 113 114 public function testProvidesAFluentInterface() 115 { 116 $spec = $this->getMockBuilder(Mockable::class) 117 ->setMethods(['mockableMethod']) 118 ->setConstructorArgs([]) 119 ->setMockClassName('DummyClassName') 120 ->disableOriginalConstructor() 121 ->disableOriginalClone() 122 ->disableAutoload(); 123 124 $this->assertTrue($spec instanceof PHPUnit_Framework_MockObject_MockBuilder); 125 } 126} 127