-
-
Notifications
You must be signed in to change notification settings - Fork 384
Closed
Description
I have a class function 'even' in which I filter an array with an anonymous function. Without testing 'even', I can achieve 100% code coverage on this function, and 0% code coverage on the anonymous function.
Obviously, if I test it I can achieve full coverage of the function. The issue seems to be related to how Code Coverage detects the end of the function, were it must be a closing brace and nothing more on a line.
The issue may be bypassed by altering Example.php to look as follows:
$numbers = array_filter($numbers,
function($number) {
return $number % 2 === 0;
}
);
Here is the contents of my files, so you may duplicate the issue. Please note I have commented out the test in TestExample.php so it will not run. You can expect 100% coverage if the test is run.
Example.php
<?php
class Example
{
public function even($numbers)
{
$numbers = array_filter($numbers, function($number) {
return $number % 2 === 0;
});
return array_merge($numbers);
}
}
TestExample.php
<?php
include "./Example.php";
class TestExample extends PHPUnit_Framework_TestCase
{
/*public function testReturnsEvenNumbers()
{
$numbers = range(1, 10);
$expect = range(2, 10, 2);
$example = new Example;
$numbers = $example->even($numbers);
$this->assertEquals($numbers, $expect);
}*/
}
phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit color="true"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
stopOnFailures="false"
syntaxCheck="false">
<testsuites>
<testsuite name="example">
<file>./TestExample.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<file>./Example.php</file>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./coverage" />
</logging>
</phpunit>
ttroyer-tcc
Metadata
Metadata
Assignees
Labels
No labels