diff --git a/features/use_data_providers_in_examples.feature b/features/use_data_providers_in_examples.feature index 7037c96..c3018ca 100644 --- a/features/use_data_providers_in_examples.feature +++ b/features/use_data_providers_in_examples.feature @@ -71,3 +71,65 @@ class String And I should see "✔ 3) it convert input value into string" And I should see "✔ 4) it convert input value into string" + Scenario: Positive match with Coduo matcher with trailing phpspec's test double arguments + Given the PhpSpecDataProviderExtension is enabled + When I write a spec "spec/Coduo/Date/DateRangeSpec.php" with following code + """ +beConstructedWith($inputValue, $date); + + $date->format('Ymd')->willReturn('2035-10-28'); + + $this->getFormattedRange()->shouldBeLike('1985-10-26 - 2035-10-28'); + } + + public function positiveConversionExamples() + { + return array( + array(new \DateTime('1985-10-26')), + ); + } +} + """ + And I write a class "src/Coduo/Date/DateRange.php" with following code + """ +start = $start; + $this->end = $end; + } + + public function getFormattedRange() + { + return $this->start->format('Y-m-d') . ' - ' . $this->end->format('Ymd'); + } +} + """ + And I run phpspec + Then it should pass + And I should see "✔ returns a formatted date range" + And I should see "✔ 1) it returns a formatted date range" + diff --git a/spec/Coduo/PhpSpec/DataProvider/Annotation/ParserSpec.php b/spec/Coduo/PhpSpec/DataProvider/Annotation/ParserSpec.php index 486de9f..dea1413 100644 --- a/spec/Coduo/PhpSpec/DataProvider/Annotation/ParserSpec.php +++ b/spec/Coduo/PhpSpec/DataProvider/Annotation/ParserSpec.php @@ -1,6 +1,6 @@ getExampleNumber($example->getTitle()); $providedData = $this->getDataFromProvider($example); + if (! array_key_exists($exampleNum, $providedData)) { return ; } $data = $providedData[$exampleNum]; + foreach ($example->getFunctionReflection()->getParameters() as $position => $parameter) { + if (!isset($data[$position])) { + continue; + } $collaborators->set($parameter->getName(), $data[$position]); } } @@ -85,7 +90,7 @@ private function haveValidDataProvider(ExampleNode $example) $exampleParamsCount = count($example->getFunctionReflection()->getParameters()); foreach ($providedData as $dataRow) { - if (!is_array($dataRow) || count($dataRow) != $exampleParamsCount) { + if (!is_array($dataRow)) { return false; } }