Conditions | 7 |
Paths | 19 |
Total Lines | 53 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 2 | 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 |
||
18 | public function before(\Codeception\Event\SuiteEvent $se) |
||
19 | { |
||
20 | $suite = $se->getSuite(); |
||
21 | $tests = $suite->tests(); |
||
22 | foreach ($tests as $id => $test) { |
||
23 | if (is_a($test, 'Codeception\Test\Cest')) { |
||
24 | |||
25 | $testClass = $test->getTestClass(); |
||
26 | $testClassName = get_class($testClass); |
||
27 | $testMethod = $test->getTestMethod(); |
||
28 | $testFile = $test->getMetadata()->getFilename(); |
||
29 | $testActor = $test->getMetadata()->getCurrent('actor'); |
||
30 | |||
31 | $dataMethod = Annotation::forMethod($testClass, $testMethod)->fetch('dataprovider'); |
||
32 | |||
33 | try { |
||
34 | if (false === is_callable([$testClass, $dataMethod])) { |
||
35 | throw new Exception(); |
||
36 | } |
||
37 | |||
38 | $dataProvider = new \PHPUnit_Framework_TestSuite_DataProvider(); |
||
39 | $examples = $testClassName::$dataMethod(); |
||
40 | foreach ($examples as $example) { |
||
41 | if ($example === null) { |
||
42 | throw new TestParseException( |
||
43 | $testFile, "Invalid values format returned by DataProvider {$dataMethod} for ${testClassName}->${testMethod}." |
||
44 | ); |
||
45 | } |
||
46 | $dataTest = new CestFormat($testClass, $testMethod, $testFile); |
||
47 | $dataTest->getMetadata()->setServices([ |
||
48 | 'di' => $test->getMetadata()->getService('di'), |
||
49 | 'dispatcher' => $test->getMetadata()->getService('dispatcher'), |
||
50 | 'modules' => $test->getMetadata()->getService('modules') |
||
51 | ]); |
||
52 | $dataTest->getMetadata()->setCurrent(['actor' => $testActor, 'example' => $example]); |
||
53 | $step = new Comment('', $dataTest->getMetadata()->getCurrent('example')); |
||
54 | $dataTest->getScenario()->setFeature($dataTest->getSpecFromMethod() . ' | ' . $step->getArgumentsAsString(100)); |
||
55 | $groups = Annotation::forMethod($testClass, $testMethod)->fetchAll('group'); |
||
56 | $dataProvider->addTest($dataTest, $groups); |
||
57 | } |
||
58 | $tests[$id] = $dataProvider; |
||
59 | |||
60 | } catch (\Exception $e) { |
||
61 | throw new TestParseException( |
||
62 | $testFile, "DataProvider {$dataMethod} for ${testClassName}->${testMethod} is invalid or not callable." |
||
63 | . PHP_EOL . |
||
64 | "Make sure this is a public static function." |
||
65 | ); |
||
66 | } |
||
67 | } |
||
68 | } |
||
69 | $suite->setTests($tests); |
||
70 | } |
||
71 | |||
73 |