| Conditions | 4 |
| Paths | 6 |
| Total Lines | 73 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 20 | public function testSuccessInitialization() |
||
| 21 | { |
||
| 22 | $name = 'valid_schema'; |
||
| 23 | $schemaConfig = $this->schemaFixtures[$name]; |
||
| 24 | |||
| 25 | $schema = new Schema( |
||
| 26 | $name, |
||
| 27 | $schemaConfig['client'], |
||
|
|
|||
| 28 | $schemaConfig['document_unique_field'], |
||
| 29 | $schemaConfig['fields'], |
||
| 30 | $schemaConfig['config_entity_fields'] |
||
| 31 | ); |
||
| 32 | |||
| 33 | $fieldNames = array_flip( |
||
| 34 | array_map( |
||
| 35 | function($fieldConfig) { return $fieldConfig['entity_field_name']; }, |
||
| 36 | $schemaConfig['fields'] |
||
| 37 | ) |
||
| 38 | ); |
||
| 39 | |||
| 40 | $documentFieldNames = array_flip( |
||
| 41 | array_map( |
||
| 42 | function($fieldConfig) { return $fieldConfig['document_field_name']; }, |
||
| 43 | $schemaConfig['fields'] |
||
| 44 | ) |
||
| 45 | ); |
||
| 46 | |||
| 47 | $configFieldNames = array_flip( |
||
| 48 | array_map( |
||
| 49 | function($configFieldConfig) { return $configFieldConfig['config_field_name']; }, |
||
| 50 | $schemaConfig['config_entity_fields']) |
||
| 51 | ); |
||
| 52 | |||
| 53 | $documentConfigFieldNames = array_flip( |
||
| 54 | array_map( |
||
| 55 | function($configFieldConfig) { return $configFieldConfig['document_field_name']; }, |
||
| 56 | $schemaConfig['config_entity_fields']) |
||
| 57 | ); |
||
| 58 | |||
| 59 | $this->assertEquals($name, $schema->getName()); |
||
| 60 | $this->assertEquals($schemaConfig['client'], $schema->getClient()); |
||
| 61 | $configFields = $schema->getConfigEntityFields(); |
||
| 62 | |||
| 63 | $discriminator = false; |
||
| 64 | foreach($configFields as $configField) { |
||
| 65 | $this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField', $configField); |
||
| 66 | $discriminator = $discriminator ? $discriminator : $configField->isDiscriminator(); |
||
| 67 | $this->assertArrayHasKey($configField->getConfigFieldName(), $configFieldNames); |
||
| 68 | $this->assertArrayHasKey($configField->getDocumentFieldName(), $documentConfigFieldNames); |
||
| 69 | } |
||
| 70 | |||
| 71 | $this->assertEquals(true, $discriminator); |
||
| 72 | |||
| 73 | $uniqueDocumentField = $schema->getDocumentUniqueField(); |
||
| 74 | $this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\DocumentUniqueField', $uniqueDocumentField); |
||
| 75 | $this->assertEquals($schemaConfig['document_unique_field']['name'], $uniqueDocumentField->getName()); |
||
| 76 | |||
| 77 | $primaryKeyField = $schema->getEntityPrimaryKeyField(); |
||
| 78 | $this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field', $primaryKeyField); |
||
| 79 | $this->assertEquals('id', $primaryKeyField->getEntityFieldName()); |
||
| 80 | $this->assertEquals('d_id', $primaryKeyField->getDocumentFieldName()); |
||
| 81 | |||
| 82 | $fields = $schema->getFields(); |
||
| 83 | foreach($fields as $field) { |
||
| 84 | $this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field', $field); |
||
| 85 | $this->assertArrayHasKey($field->getEntityFieldName(), $fieldNames); |
||
| 86 | $this->assertArrayHasKey($field->getDocumentFieldName(), $documentFieldNames); |
||
| 87 | } |
||
| 88 | |||
| 89 | $titleField = $schema->getFieldByEntityFieldName('title'); |
||
| 90 | $this->assertInstanceOf('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field', $titleField); |
||
| 91 | $this->assertEquals('title', $titleField->getEntityFieldName()); |
||
| 92 | $this->assertEquals('d_title', $titleField->getDocumentFieldName()); |
||
| 93 | } |
||
| 94 | } |