Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 20 | class TransactionHandlerTest extends \PHPUnit\Framework\TestCase |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Transaction handler to test. |
||
| 24 | * |
||
| 25 | * @var \eZ\Publish\Core\Persistence\Legacy\TransactionHandler |
||
| 26 | */ |
||
| 27 | protected $transactionHandler; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var \eZ\Publish\Core\Persistence\Database\DatabaseHandler|\PHPUnit\Framework\MockObject\MockObject |
||
| 31 | */ |
||
| 32 | protected $dbHandlerMock; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var \eZ\Publish\SPI\Persistence\Content\Type\Handler|\PHPUnit\Framework\MockObject\MockObject |
||
| 36 | */ |
||
| 37 | protected $contentTypeHandlerMock; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var \eZ\Publish\SPI\Persistence\Content\Language\Handler|\PHPUnit\Framework\MockObject\MockObject |
||
| 41 | */ |
||
| 42 | protected $languageHandlerMock; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @covers \eZ\Publish\Core\Persistence\Legacy\TransactionHandler::__construct |
||
| 46 | */ |
||
| 47 | public function testConstruct() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @covers \eZ\Publish\Core\Persistence\Legacy\TransactionHandler::beginTransaction |
||
| 70 | */ |
||
| 71 | public function testBeginTransaction() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @covers \eZ\Publish\Core\Persistence\Legacy\TransactionHandler::commit |
||
| 89 | */ |
||
| 90 | public function testCommit() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @covers \eZ\Publish\Core\Persistence\Legacy\TransactionHandler::commit |
||
| 108 | * |
||
| 109 | * @expectedException \RuntimeException |
||
| 110 | * @expectedExceptionMessage test |
||
| 111 | */ |
||
| 112 | View Code Duplication | public function testCommitException() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @covers \eZ\Publish\Core\Persistence\Legacy\TransactionHandler::rollback |
||
| 131 | */ |
||
| 132 | public function testRollback() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @covers \eZ\Publish\Core\Persistence\Legacy\TransactionHandler::rollback |
||
| 150 | * |
||
| 151 | * @expectedException \RuntimeException |
||
| 152 | * @expectedExceptionMessage test |
||
| 153 | */ |
||
| 154 | View Code Duplication | public function testRollbackException() |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Returns a mock object for the Content Gateway. |
||
| 173 | * |
||
| 174 | * @return \eZ\Publish\Core\Persistence\Legacy\TransactionHandler |
||
| 175 | */ |
||
| 176 | protected function getTransactionHandler() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Returns a mock object for the Content Gateway. |
||
| 191 | * |
||
| 192 | * @return \eZ\Publish\Core\Persistence\Database\DatabaseHandler|\PHPUnit\Framework\MockObject\MockObject |
||
| 193 | */ |
||
| 194 | protected function getDatabaseHandlerMock() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Returns a mock object for the Content Type Handler. |
||
| 205 | * |
||
| 206 | * @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\MemoryCachingHandler|\PHPUnit\Framework\MockObject\MockObject |
||
| 207 | */ |
||
| 208 | protected function getContentTypeHandlerMock() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Returns a mock object for the Content Language Gateway. |
||
| 219 | * |
||
| 220 | * @return \eZ\Publish\Core\Persistence\Legacy\Content\Language\CachingHandler|\PHPUnit\Framework\MockObject\MockObject |
||
| 221 | */ |
||
| 222 | protected function getLanguageHandlerMock() |
||
| 230 | } |
||
| 231 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.