Skip to content

Commit

Permalink
Check both the function and the method for the existence via '@requires
Browse files Browse the repository at this point in the history
… function' annotation
  • Loading branch information
rybakit committed Jul 7, 2014
1 parent 9edd518 commit 18852ac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,20 +583,25 @@ protected function checkRequirements()
);
}

foreach ($this->required['functions'] as $requiredFunction) {
if (!function_exists($requiredFunction)) {
$missingRequirements[] = sprintf(
'Function %s is required.',
$requiredFunction
);
foreach ($this->required['functions'] as $function) {
$pieces = explode('::', $function);
if (2 === count($pieces) && method_exists($pieces[0], $pieces[1])) {
continue;
}
if (function_exists($function)) {
continue;
}
$missingRequirements[] = sprintf(
'Function %s is required.',
$function
);
}

foreach ($this->required['extensions'] as $requiredExtension) {
if (!extension_loaded($requiredExtension)) {
foreach ($this->required['extensions'] as $extension) {
if (!extension_loaded($extension)) {
$missingRequirements[] = sprintf(
'Extension %s is required.',
$requiredExtension
$extension
);
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Framework/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ public function testSkipsProvidesMessagesForAllSkippingReasons()
);
}

public function testRequiringAnExistingMethodDoesNotSkip()
{
$test = new RequirementsTest('testExistingMethod');
$result = $test->run();
$this->assertEquals(0, $result->skippedCount());
}

public function testRequiringAnExistingFunctionDoesNotSkip()
{
$test = new RequirementsTest('testExistingFunction');
Expand Down
7 changes: 7 additions & 0 deletions tests/_files/RequirementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public function testExistingFunction()
{
}

/**
* @requires function ReflectionMethod::setAccessible
*/
public function testExistingMethod()
{
}

/**
* @requires extension spl
*/
Expand Down

0 comments on commit 18852ac

Please sign in to comment.