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 | ||
| 5 | class AsymmetricTest extends \PHPUnit_Framework_TestCase | ||
| 6 | { | ||
| 7 | /** | ||
| 8 | * @var \PHPUnit_Framework_MockObject_MockObject | ||
| 9 | */ | ||
| 10 | private $algorithm; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * @var Asymmetric | ||
| 14 | */ | ||
| 15 | private $encryption; | ||
| 16 | |||
| 17 | public function setUp() | ||
| 23 | |||
| 24 | /** | ||
| 25 | * @expectedException \RuntimeException | ||
| 26 | */ | ||
| 27 | public function testGetPrivateKeyUnavailable() | ||
| 31 | |||
| 32 | public function testPrivateKey() | ||
| 40 | |||
| 41 | /** | ||
| 42 | * @expectedException \RuntimeException | ||
| 43 | */ | ||
| 44 | public function testGetPublicKeyUnavailable() | ||
| 48 | |||
| 49 | public function testPublicKey() | ||
| 57 | |||
| 58 | /** | ||
| 59 | * @expectedException \RuntimeException | ||
| 60 | * @expectedExceptionMessage No private key available for encryption. | ||
| 61 | */ | ||
| 62 | public function testEncryptNoPrivateKey() | ||
| 69 | |||
| 70 | View Code Duplication | public function testEncrypt() | |
| 85 | |||
| 86 | /** | ||
| 87 | * @expectedException \RuntimeException | ||
| 88 | * @expectedExceptionMessage No public key available for verification. | ||
| 89 | */ | ||
| 90 | public function testVerifyNoPublicKey() | ||
| 97 | |||
| 98 | View Code Duplication | public function testVerify() | |
| 114 | } | ||
| 115 |