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 |
||
| 17 | class GitAccessCommandTest extends CommandTestCase |
||
| 18 | { |
||
| 19 | protected $client; |
||
| 20 | |||
| 21 | protected function setUp(): void: void |
||
|
|
|||
| 22 | { |
||
| 23 | $this->client = self::createClient(); |
||
| 24 | $this->client->startIsolation(); |
||
| 25 | } |
||
| 26 | |||
| 27 | public function tearDown(): void |
||
| 28 | { |
||
| 29 | $this->client->stopIsolation(); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function testSimpleCreateCase() |
||
| 33 | { |
||
| 34 | list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git-access create barbaz admin master 1 1'); |
||
| 35 | |||
| 36 | $this->assertEquals(0, $statusCode, 'statusCode is equal to 0'); |
||
| 37 | $this->assertEquals("The git-access was successfully created!\n", $output); |
||
| 38 | |||
| 39 | $doctrine = $this->client->getKernel()->getContainer()->get('doctrine'); |
||
| 40 | |||
| 41 | $project = $doctrine->getRepository('FabricaCoreBundle:Project')->findOneBySlug('barbaz'); |
||
| 42 | $role = $doctrine->getRepository('FabricaCoreBundle:Role')->findOneBySlug('admin'); |
||
| 43 | $gitAccess = $doctrine->getRepository('FabricaCoreBundle:ProjectGitAccess')->findOneBy(array( |
||
| 44 | 'project' => $project, |
||
| 45 | 'role' => $role, |
||
| 46 | 'reference' => 'master', |
||
| 47 | )); |
||
| 48 | |||
| 49 | $this->assertNotNull($gitAccess); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function testSimpleDeleteCase() |
||
| 53 | { |
||
| 54 | list($statusCode ,$output) = $this->runCommand($this->client, 'fabrica:git-access delete foobar visitor *'); |
||
| 55 | |||
| 56 | $this->assertEquals(0, $statusCode, 'statusCode is equal to 0'); |
||
| 57 | $this->assertEquals("The git-access was successfully deleted!\n", $output); |
||
| 58 | |||
| 59 | $doctrine = $this->client->getKernel()->getContainer()->get('doctrine'); |
||
| 60 | |||
| 61 | $project = $doctrine->getRepository('FabricaCoreBundle:Project')->findOneBySlug('foobar'); |
||
| 62 | $role = $doctrine->getRepository('FabricaCoreBundle:Role')->findOneBySlug('visitor'); |
||
| 63 | $gitAccess = $doctrine->getRepository('FabricaCoreBundle:ProjectGitAccess')->findOneBy(array( |
||
| 64 | 'project' => $project, |
||
| 65 | 'role' => $role, |
||
| 66 | 'reference' => 'master', |
||
| 67 | )); |
||
| 68 | |||
| 69 | $this->assertNull($gitAccess); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |