| | 57 | Index: PHPUnit/Tests/_files/PartialMockTestClass.php |
|---|
| | 58 | =================================================================== |
|---|
| | 59 | --- PHPUnit/Tests/_files/PartialMockTestClass.php (revision 0) |
|---|
| | 60 | +++ PHPUnit/Tests/_files/PartialMockTestClass.php (revision 0) |
|---|
| | 61 | @@ -0,0 +1,71 @@ |
|---|
| | 62 | +<?php |
|---|
| | 63 | +/** |
|---|
| | 64 | + * PHPUnit |
|---|
| | 65 | + * |
|---|
| | 66 | + * Copyright (c) 2002-2008, Sebastian Bergmann <sb@sebastian-bergmann.de>. |
|---|
| | 67 | + * All rights reserved. |
|---|
| | 68 | + * |
|---|
| | 69 | + * Redistribution and use in source and binary forms, with or without |
|---|
| | 70 | + * modification, are permitted provided that the following conditions |
|---|
| | 71 | + * are met: |
|---|
| | 72 | + * |
|---|
| | 73 | + * * Redistributions of source code must retain the above copyright |
|---|
| | 74 | + * notice, this list of conditions and the following disclaimer. |
|---|
| | 75 | + * |
|---|
| | 76 | + * * Redistributions in binary form must reproduce the above copyright |
|---|
| | 77 | + * notice, this list of conditions and the following disclaimer in |
|---|
| | 78 | + * the documentation and/or other materials provided with the |
|---|
| | 79 | + * distribution. |
|---|
| | 80 | + * |
|---|
| | 81 | + * * Neither the name of Sebastian Bergmann nor the names of his |
|---|
| | 82 | + * contributors may be used to endorse or promote products derived |
|---|
| | 83 | + * from this software without specific prior written permission. |
|---|
| | 84 | + * |
|---|
| | 85 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| | 86 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|---|
| | 87 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|---|
| | 88 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
|---|
| | 89 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
|---|
| | 90 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|---|
| | 91 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|---|
| | 92 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|---|
| | 93 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|---|
| | 94 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|---|
| | 95 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|---|
| | 96 | + * POSSIBILITY OF SUCH DAMAGE. |
|---|
| | 97 | + * |
|---|
| | 98 | + * @category Testing |
|---|
| | 99 | + * @package PHPUnit |
|---|
| | 100 | + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> |
|---|
| | 101 | + * @author Frank Kleine <mikey@stubbles.net> |
|---|
| | 102 | + * @copyright 2002-2008 Sebastian Bergmann <sb@sebastian-bergmann.de> |
|---|
| | 103 | + * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|---|
| | 104 | + * @version SVN: $Id: AnInterface.php 1985 2007-12-26 18:11:55Z sb $ |
|---|
| | 105 | + * @link http://www.phpunit.de/ |
|---|
| | 106 | + * @since File available since Release 3.2.12 |
|---|
| | 107 | + */ |
|---|
| | 108 | + |
|---|
| | 109 | +require_once 'PHPUnit/Util/Filter.php'; |
|---|
| | 110 | + |
|---|
| | 111 | +PHPUnit_Util_Filter::addFileToFilter(__FILE__); |
|---|
| | 112 | + |
|---|
| | 113 | +/** |
|---|
| | 114 | + * |
|---|
| | 115 | + * |
|---|
| | 116 | + * @category Testing |
|---|
| | 117 | + * @package PHPUnit |
|---|
| | 118 | + * @author Sebastian Bergmann <sb@sebastian-bergmann.de> |
|---|
| | 119 | + * @author Frank Kleine <mikey@stubbles.net> |
|---|
| | 120 | + * @copyright 2002-2008 Sebastian Bergmann <sb@sebastian-bergmann.de> |
|---|
| | 121 | + * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|---|
| | 122 | + * @version Release: @package_version@ |
|---|
| | 123 | + * @link http://www.phpunit.de/ |
|---|
| | 124 | + * @since Class available since Release 3.2.12 |
|---|
| | 125 | + */ |
|---|
| | 126 | +class PartialMockTestClass |
|---|
| | 127 | +{ |
|---|
| | 128 | + public function doSomething() { } |
|---|
| | 129 | + |
|---|
| | 130 | + public function doAnotherThing() { } |
|---|
| | 131 | +} |
|---|
| | 132 | +?> |
|---|
| | 133 | Index: PHPUnit/Tests/Framework/MockObjectTest.php |
|---|
| | 134 | =================================================================== |
|---|
| | 135 | --- PHPUnit/Tests/Framework/MockObjectTest.php (revision 2269) |
|---|
| | 136 | +++ PHPUnit/Tests/Framework/MockObjectTest.php (working copy) |
|---|
| | 137 | @@ -47,6 +47,7 @@ |
|---|
| | 138 | require_once 'PHPUnit/Framework/TestCase.php'; |
|---|
| | 139 | |
|---|
| | 140 | require_once '_files/AnInterface.php'; |
|---|
| | 141 | +require_once '_files/PartialMockTestClass.php'; |
|---|
| | 142 | |
|---|
| | 143 | /** |
|---|
| | 144 | * |
|---|
| | 145 | @@ -55,6 +56,7 @@ |
|---|
| | 146 | * @package PHPUnit |
|---|
| | 147 | * @author Sebastian Bergmann <sb@sebastian-bergmann.de> |
|---|
| | 148 | * @author Patrick M??ller <elias0@gmx.net> |
|---|
| | 149 | + * @author Frank Kleine <mikey@stubbles.net> |
|---|
| | 150 | * @copyright 2002-2008 Sebastian Bergmann <sb@sebastian-bergmann.de> |
|---|
| | 151 | * @license http://www.opensource.org/licenses/bsd-license.php BSD License |
|---|
| | 152 | * @version Release: @package_version@ |
|---|
| | 153 | @@ -145,5 +147,29 @@ |
|---|
| | 154 | |
|---|
| | 155 | $this->assertEquals('something', $mock->doSomething()); |
|---|
| | 156 | } |
|---|
| | 157 | + |
|---|
| | 158 | + public function testMockClassOnlyGeneratedOnce() |
|---|
| | 159 | + { |
|---|
| | 160 | + $mock1 = $this->getMock('AnInterface'); |
|---|
| | 161 | + $mock2 = $this->getMock('AnInterface'); |
|---|
| | 162 | + $this->assertEquals(get_class($mock1), get_class($mock2)); |
|---|
| | 163 | + } |
|---|
| | 164 | + |
|---|
| | 165 | + public function testMockClassDifferentForPartialMocks() |
|---|
| | 166 | + { |
|---|
| | 167 | + $mock1 = $this->getMock('PartialMockTestClass'); |
|---|
| | 168 | + $mock2 = $this->getMock('PartialMockTestClass', array('doSomething')); |
|---|
| | 169 | + $mock3 = $this->getMock('PartialMockTestClass', array('doSomething')); |
|---|
| | 170 | + $mock4 = $this->getMock('PartialMockTestClass', array('doAnotherThing')); |
|---|
| | 171 | + $mock5 = $this->getMock('PartialMockTestClass', array('doAnotherThing')); |
|---|
| | 172 | + $this->assertNotEquals(get_class($mock1), get_class($mock2)); |
|---|
| | 173 | + $this->assertNotEquals(get_class($mock1), get_class($mock3)); |
|---|
| | 174 | + $this->assertNotEquals(get_class($mock1), get_class($mock4)); |
|---|
| | 175 | + $this->assertNotEquals(get_class($mock1), get_class($mock5)); |
|---|
| | 176 | + $this->assertEquals(get_class($mock2), get_class($mock3)); |
|---|
| | 177 | + $this->assertNotEquals(get_class($mock2), get_class($mock4)); |
|---|
| | 178 | + $this->assertNotEquals(get_class($mock2), get_class($mock5)); |
|---|
| | 179 | + $this->assertEquals(get_class($mock4), get_class($mock5)); |
|---|
| | 180 | + } |
|---|
| | 181 | } |
|---|
| | 182 | ?> |
|---|