Conditions | 1 |
Paths | 1 |
Total Lines | 104 |
Code Lines | 4 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
144 | protected function getFeatureContextSkelet() |
||
145 | { |
||
146 | return <<<'PHP' |
||
147 | <?php |
||
148 | |||
149 | namespace %NAMESPACE%; |
||
150 | |||
151 | use SilverStripe\BehatExtension\Context\SilverStripeContext, |
||
152 | SilverStripe\BehatExtension\Context\BasicContext, |
||
153 | SilverStripe\BehatExtension\Context\LoginContext, |
||
154 | SilverStripe\BehatExtension\Context\FixtureContext, |
||
155 | SilverStripe\Framework\Test\Behaviour\CmsFormsContext, |
||
156 | SilverStripe\Framework\Test\Behaviour\CmsUiContext, |
||
157 | SilverStripe\Cms\Test\Behaviour; |
||
158 | |||
159 | /** |
||
160 | * Features context |
||
161 | * |
||
162 | * Context automatically loaded by Behat. |
||
163 | * Uses subcontexts to extend functionality. |
||
164 | */ |
||
165 | class FeatureContext extends SilverStripeContext { |
||
166 | |||
167 | /** |
||
168 | * @var FixtureFactory |
||
169 | */ |
||
170 | protected $fixtureFactory; |
||
171 | |||
172 | /** |
||
173 | * Initializes context. |
||
174 | * Every scenario gets it's own context object. |
||
175 | * |
||
176 | * @param array $parameters context parameters (set them up through behat.yml) |
||
177 | */ |
||
178 | public function __construct(array $parameters) { |
||
179 | parent::__construct($parameters); |
||
180 | |||
181 | $this->useContext('BasicContext', new BasicContext($parameters)); |
||
182 | $this->useContext('LoginContext', new LoginContext($parameters)); |
||
183 | $this->useContext('CmsFormsContext', new CmsFormsContext($parameters)); |
||
184 | $this->useContext('CmsUiContext', new CmsUiContext($parameters)); |
||
185 | |||
186 | $fixtureContext = new FixtureContext($parameters); |
||
187 | $fixtureContext->setFixtureFactory($this->getFixtureFactory()); |
||
188 | $this->useContext('FixtureContext', $fixtureContext); |
||
189 | |||
190 | // Use blueprints to set user name from identifier |
||
191 | $factory = $fixtureContext->getFixtureFactory(); |
||
192 | $blueprint = \Injector::inst()->create('FixtureBlueprint', 'Member'); |
||
193 | $blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) { |
||
194 | if(!isset($data['FirstName'])) $data['FirstName'] = $identifier; |
||
195 | }); |
||
196 | $factory->define('Member', $blueprint); |
||
197 | |||
198 | // Auto-publish pages |
||
199 | if (class_exists('SiteTree')) { |
||
200 | foreach(\ClassInfo::subclassesFor('SiteTree') as $id => $class) { |
||
201 | $blueprint = \Injector::inst()->create('FixtureBlueprint', $class); |
||
202 | $blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) { |
||
203 | $obj->publish('Stage', 'Live'); |
||
204 | }); |
||
205 | $factory->define($class, $blueprint); |
||
206 | } |
||
207 | } |
||
208 | } |
||
209 | |||
210 | public function setMinkParameters(array $parameters) { |
||
211 | parent::setMinkParameters($parameters); |
||
212 | |||
213 | if(isset($parameters['files_path'])) { |
||
214 | $this->getSubcontext('FixtureContext')->setFilesPath($parameters['files_path']); |
||
215 | } |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @return FixtureFactory |
||
220 | */ |
||
221 | public function getFixtureFactory() { |
||
222 | if(!$this->fixtureFactory) { |
||
223 | $this->fixtureFactory = \Injector::inst()->create('BehatFixtureFactory'); |
||
224 | } |
||
225 | |||
226 | return $this->fixtureFactory; |
||
227 | } |
||
228 | |||
229 | public function setFixtureFactory(FixtureFactory $factory) { |
||
230 | $this->fixtureFactory = $factory; |
||
231 | } |
||
232 | |||
233 | // |
||
234 | // Place your definition and hook methods here: |
||
235 | // |
||
236 | // /** |
||
237 | // * @Given /^I have done something with "([^"]*)"$/ |
||
238 | // */ |
||
239 | // public function iHaveDoneSomethingWith($argument) { |
||
240 | // $container = $this->kernel->getContainer(); |
||
241 | // $container->get('some_service')->doSomethingWith($argument); |
||
242 | // } |
||
243 | // |
||
244 | } |
||
245 | |||
246 | PHP; |
||
247 | } |
||
248 | } |
||
249 |