| Conditions | 1 |
| Paths | 1 |
| Total Lines | 116 |
| 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 |
||
| 26 | public function testConfigureOptions() |
||
| 27 | { |
||
| 28 | $resolver = new OptionsResolver(); |
||
| 29 | |||
| 30 | $applicationConfiguration = new ApplicationConfiguration(); |
||
| 31 | $applicationConfiguration->configureOptions($resolver); |
||
| 32 | $parameters = $resolver->resolve([ |
||
| 33 | 'enable_extra_configuration' => true, |
||
| 34 | 'title' => 'My Title', |
||
| 35 | 'description' => 'Test', |
||
| 36 | 'locale' => 'fr', |
||
| 37 | 'base_template' => 'LAGAdminBundle::admin.layout.html.twig', |
||
| 38 | 'block_template' => 'LAGAdminBundle:Form:fields.html.twig', |
||
| 39 | 'bootstrap' => true, |
||
| 40 | 'date_format' => 'd/m/YYYY', |
||
| 41 | 'string_length' => 100, |
||
| 42 | 'string_length_truncate' => '....', |
||
| 43 | 'routing' => [ |
||
| 44 | 'url_pattern' => '/{admin}/{action}', |
||
| 45 | 'name_pattern' => 'lag.admin.{admin}.{action}', |
||
| 46 | ], |
||
| 47 | 'translation' => [ |
||
| 48 | 'enabled' => true, |
||
| 49 | 'pattern' => 'lag.admin.{key}', |
||
| 50 | ], |
||
| 51 | 'max_per_page' => 25, |
||
| 52 | 'fields_mapping' => [ |
||
| 53 | 'custom' => 'custom', |
||
| 54 | ], |
||
| 55 | ]); |
||
| 56 | $applicationConfiguration->setParameters($parameters); |
||
| 57 | |||
| 58 | $this->assertEquals(true, $applicationConfiguration->getParameter('enable_extra_configuration')); |
||
| 59 | $this->assertEquals('My Title', $applicationConfiguration->getParameter('title')); |
||
| 60 | $this->assertEquals('Test', $applicationConfiguration->getParameter('description')); |
||
| 61 | $this->assertEquals('fr', $applicationConfiguration->getParameter('locale')); |
||
| 62 | $this->assertEquals('LAGAdminBundle::admin.layout.html.twig', $applicationConfiguration->getParameter('base_template')); |
||
| 63 | $this->assertEquals('LAGAdminBundle:Form:fields.html.twig', $applicationConfiguration->getParameter('block_template')); |
||
| 64 | $this->assertEquals(true, $applicationConfiguration->getParameter('bootstrap')); |
||
| 65 | $this->assertEquals('d/m/YYYY', $applicationConfiguration->getParameter('date_format')); |
||
| 66 | $this->assertEquals(100, $applicationConfiguration->getParameter('string_length')); |
||
| 67 | $this->assertEquals('....', $applicationConfiguration->getParameter('string_length_truncate')); |
||
| 68 | $this->assertEquals('lag.admin.{admin}.{action}', $applicationConfiguration->getParameter('routing')['name_pattern']); |
||
| 69 | $this->assertEquals('/{admin}/{action}', $applicationConfiguration->getParameter('routing')['url_pattern']); |
||
| 70 | $this->assertEquals('lag.admin.{key}', $applicationConfiguration->getParameter('translation')['pattern']); |
||
| 71 | $this->assertEquals(25, $applicationConfiguration->getParameter('max_per_page')); |
||
| 72 | $this->assertEquals([ |
||
| 73 | 'custom' => 'custom', |
||
| 74 | AbstractField::TYPE_STRING => StringField::class, |
||
| 75 | AbstractField::TYPE_ARRAY => ArrayField::class, |
||
| 76 | AbstractField::TYPE_ACTION => Action::class, |
||
| 77 | AbstractField::TYPE_COLLECTION => Collection::class, |
||
| 78 | AbstractField::TYPE_BOOLEAN => Boolean::class, |
||
| 79 | AbstractField::TYPE_MAPPED => Mapped::class, |
||
| 80 | AbstractField::TYPE_ACTION_COLLECTION => ActionCollection::class, |
||
| 81 | AbstractField::TYPE_LINK => Link::class, |
||
| 82 | AbstractField::TYPE_DATE => Date::class, |
||
| 83 | AbstractField::TYPE_COUNT => Count::class, |
||
| 84 | ], $applicationConfiguration->getParameter('fields_mapping')); |
||
| 85 | |||
| 86 | // test exception raising |
||
| 87 | $this->assertExceptionRaised(InvalidOptionsException::class, function() use ($resolver) { |
||
| 88 | $resolver->resolve([ |
||
| 89 | 'routing' => [ |
||
| 90 | 'url_pattern' => '/wrong/{action}', |
||
| 91 | ], |
||
| 92 | ]); |
||
| 93 | }); |
||
| 94 | $this->assertExceptionRaised(InvalidOptionsException::class, function() use ($resolver) { |
||
| 95 | $resolver->resolve([ |
||
| 96 | 'routing' => [ |
||
| 97 | 'url_pattern' => '/{admin}/wrong', |
||
| 98 | ], |
||
| 99 | ]); |
||
| 100 | }); |
||
| 101 | $this->assertExceptionRaised(InvalidOptionsException::class, function() use ($resolver) { |
||
| 102 | $resolver->resolve([ |
||
| 103 | 'routing' => [ |
||
| 104 | 'name_pattern' => 'wrong.{action}', |
||
| 105 | ], |
||
| 106 | ]); |
||
| 107 | }); |
||
| 108 | $this->assertExceptionRaised(InvalidOptionsException::class, function() use ($resolver) { |
||
| 109 | $resolver->resolve([ |
||
| 110 | 'routing' => [ |
||
| 111 | 'name_pattern' => '{admin}.wrong', |
||
| 112 | ], |
||
| 113 | ]); |
||
| 114 | }); |
||
| 115 | $this->assertExceptionRaised(InvalidOptionsException::class, function() use ($resolver) { |
||
| 116 | $resolver->resolve([ |
||
| 117 | 'translation' => [ |
||
| 118 | 'enabled' => 'true', |
||
| 119 | ], |
||
| 120 | ]); |
||
| 121 | }); |
||
| 122 | $this->assertExceptionRaised(InvalidOptionsException::class, function() use ($resolver) { |
||
| 123 | $resolver->resolve([ |
||
| 124 | 'translation' => [ |
||
| 125 | ], |
||
| 126 | ]); |
||
| 127 | }); |
||
| 128 | $resolver->resolve([ |
||
| 129 | 'translation' => [ |
||
| 130 | 'enabled' => true |
||
| 131 | ], |
||
| 132 | ]); |
||
| 133 | $this->assertExceptionRaised(InvalidOptionsException::class, function() use ($resolver) { |
||
| 134 | $resolver->resolve([ |
||
| 135 | 'translation' => [ |
||
| 136 | 'enabled' => true, |
||
| 137 | 'pattern' => 'wrong_pattern' |
||
| 138 | ], |
||
| 139 | ]); |
||
| 140 | }); |
||
| 141 | } |
||
| 142 | } |
||
| 143 |