Conditions | 8 |
Paths | 19 |
Total Lines | 53 |
Code Lines | 40 |
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 |
||
21 | public function before(\Codeception\Event\SuiteEvent $e) |
||
22 | { |
||
23 | $suite = $e->getSuite(); |
||
|
|||
24 | $tests = $suite->tests(); |
||
25 | foreach ($tests as $id => $test) { |
||
26 | if (get_class($test) == 'Codeception\Test\Cest') { |
||
27 | $testClass = $test->getTestClass(); |
||
28 | $testMethod = $test->getTestMethod(); |
||
29 | $testFile = $test->getMetadata()->getFilename(); |
||
30 | $testActor = $test->getMetadata()->getCurrent('actor'); |
||
31 | $dataMethod = Annotation::forMethod($testClass, $testMethod)->fetch('dataprovider'); |
||
32 | if (false === empty($dataMethod)) { |
||
33 | if (false === is_callable([$testClass, $testMethod])) { |
||
34 | throw new TestParseException( |
||
35 | $testFile, "DataProvider for ${testClass}->${testMethod} is invalid or not callable" |
||
36 | . PHP_EOL . |
||
37 | "Make sure this is a public static function." |
||
38 | ); |
||
39 | } |
||
40 | try { |
||
41 | $dataProvider = new \PHPUnit_Framework_TestSuite_DataProvider(); |
||
42 | $examples = $testClass::$dataMethod(); |
||
43 | foreach ($examples as $example) { |
||
44 | if ($example === null) { |
||
45 | throw new TestParseException( |
||
46 | $testFile, "Values return by DataProvider for ${testClass}->${testMethod} is invalid" |
||
47 | ); |
||
48 | } |
||
49 | $dataTest = new CestFormat($testClass, $testMethod, $testFile); |
||
50 | $dataTest->getMetadata()->setServices([ |
||
51 | 'di' => $test->getMetadata()->getService('di'), |
||
52 | 'dispatcher' => $test->getMetadata()->getService('dispatcher'), |
||
53 | 'modules' => $test->getMetadata()->getService('modules') |
||
54 | ]); |
||
55 | $dataTest->getMetadata()->setCurrent(['actor' => $testActor, 'example' => $example]); |
||
56 | $step = new Comment('', $dataTest->getMetadata()->getCurrent('example')); |
||
57 | $dataTest->getScenario()->setFeature($dataTest->getSpecFromMethod() . ' | '. $step->getArgumentsAsString(100)); |
||
58 | $groups = Annotation::forMethod($testClass, $testMethod)->fetchAll('group'); |
||
59 | $dataProvider->addTest($dataTest, $groups); |
||
60 | } |
||
61 | $tests[$id] = $dataProvider; |
||
62 | } catch(\Exception $e) { |
||
63 | throw new TestParseException( |
||
64 | $testFile, "DataProvider for ${testClass}->${testMethod} is invalid or not callable" |
||
65 | . PHP_EOL . |
||
66 | "Make sure this is a public static function." |
||
67 | ); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | $suite->setTests($tests); |
||
73 | } |
||
74 | |||
76 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: