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 NullIOTest extends \PHPUnit_Framework_TestCase |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Tests NullIO::isInteractive |
||
| 9 | */ |
||
| 10 | public function testIsInteractive() |
||
| 11 | { |
||
| 12 | $io = new NullIO(); |
||
| 13 | $this->assertFalse($io->isInteractive()); |
||
| 14 | } |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Tests NullIO::isDebug |
||
| 18 | */ |
||
| 19 | public function testIsDebug() |
||
| 20 | { |
||
| 21 | $io = new NullIO(); |
||
| 22 | $this->assertFalse($io->isDebug()); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Tests NullIO::isVerbose |
||
| 27 | */ |
||
| 28 | public function testIsVerbose() |
||
| 29 | { |
||
| 30 | $io = new NullIO(); |
||
| 31 | $this->assertFalse($io->isVerbose()); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Tests NullIO::isVeryVerbose |
||
| 36 | */ |
||
| 37 | public function testIsVeryVerbose() |
||
| 38 | { |
||
| 39 | $io = new NullIO(); |
||
| 40 | $this->assertFalse($io->isVeryVerbose()); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Tests NullIO::writeError |
||
| 45 | */ |
||
| 46 | public function testWriteError() |
||
| 47 | { |
||
| 48 | $io = new NullIO(); |
||
| 49 | $io->writeError('foo'); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Tests NullIO::ask |
||
| 54 | */ |
||
| 55 | public function testAsk() |
||
| 56 | { |
||
| 57 | $io = new NullIO(); |
||
| 58 | $this->assertEquals('bar', $io->ask('foo', 'bar')); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Tests NullIO::askConfirmation |
||
| 63 | */ |
||
| 64 | public function testAskConfirmation() |
||
| 65 | { |
||
| 66 | $io = new NullIO(); |
||
| 67 | $this->assertEquals(true, $io->askConfirmation('foo', true)); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Tests NullIO::askAbdValidate |
||
| 72 | */ |
||
| 73 | public function testAskAndValidate() |
||
| 74 | { |
||
| 75 | $io = new NullIO(); |
||
| 76 | $this->assertEquals( |
||
| 77 | true, |
||
| 78 | $io->askAndValidate( |
||
| 79 | 'foo', |
||
| 80 | function() { |
||
| 81 | return true; |
||
| 82 | }, |
||
| 83 | false, |
||
| 84 | true |
||
| 85 | ) |
||
| 86 | ); |
||
| 87 | } |
||
| 88 | } |
||
| 89 |