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 |
||
| 36 | class SolrConfigurationStatusTest extends IntegrationTest |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * @test |
||
| 40 | */ |
||
| 41 | public function canGetGreenReportAgainstTestServer() |
||
| 42 | { |
||
| 43 | $this->importDataSetFromFixture('can_get_green_solr_configuration_status_report.xml'); |
||
| 44 | |||
| 45 | /** @var $solrConfigurationStatus \ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus */ |
||
| 46 | $solrConfigurationStatus = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus'); |
||
| 47 | $violations = $solrConfigurationStatus->getStatus(); |
||
| 48 | $this->assertEmpty($violations, 'We did not get an empty response from the solr configuration status report! Something is wrong'); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @test |
||
| 53 | */ |
||
| 54 | public function canDetectMissingDomainRecord() |
||
| 55 | { |
||
| 56 | $this->importDataSetFromFixture('can_detect_missing_domain_record.xml'); |
||
| 57 | |||
| 58 | /** @var $solrConfigurationStatus \ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus */ |
||
| 59 | $solrConfigurationStatus = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus'); |
||
| 60 | $violations = $solrConfigurationStatus->getStatus(); |
||
| 61 | |||
| 62 | $this->assertCount(1, $violations, 'Asserting to contain only one violation.'); |
||
| 63 | |||
| 64 | $firstViolation = array_pop($violations); |
||
| 65 | $this->assertContains('Domain records missing', $firstViolation->getValue(), 'Did not get a domain record violation'); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @test |
||
| 70 | */ |
||
| 71 | public function canDetectMissingRootPage() |
||
| 72 | { |
||
| 73 | $this->importDataSetFromFixture('can_detect_missing_rootpage.xml'); |
||
| 74 | |||
| 75 | /** @var $solrConfigurationStatus \ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus */ |
||
| 76 | $solrConfigurationStatus = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus'); |
||
| 77 | $violations = $solrConfigurationStatus->getStatus(); |
||
| 78 | |||
| 79 | $this->assertCount(1, $violations, 'Asserting to contain only one violation.'); |
||
| 80 | |||
| 81 | $firstViolation = array_pop($violations); |
||
| 82 | $this->assertContains('No sites', $firstViolation->getValue(), 'Did not get a no sites found violation'); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @test |
||
| 87 | */ |
||
| 88 | public function canDetectIndexingDisabled() |
||
| 89 | { |
||
| 90 | $this->importDataSetFromFixture('can_detect_indexing_disabled.xml'); |
||
| 91 | |||
| 92 | /** @var $solrConfigurationStatus \ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus */ |
||
| 93 | $solrConfigurationStatus = GeneralUtility::makeInstance('ApacheSolrForTypo3\Solr\Report\SolrConfigurationStatus'); |
||
| 94 | $violations = $solrConfigurationStatus->getStatus(); |
||
| 95 | |||
| 96 | $this->assertCount(1, $violations, 'Asserting to contain only one violation.'); |
||
| 97 | |||
| 98 | $firstViolation = array_pop($violations); |
||
| 99 | $this->assertContains('Indexing is disabled', $firstViolation->getValue(), 'Did not get a no sites found violation'); |
||
| 100 | } |
||
| 101 | } |
||
| 102 |