Skip to content

Commit b21dba1

Browse files
Support namespaces with @Covers annotation.
1 parent c8f56f2 commit b21dba1

13 files changed

+359
-1
lines changed

PHP/CodeCoverage/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PHP_CodeCoverage_Util
6060
/**
6161
* @var string
6262
*/
63-
const REGEX = '/@covers[\s]+([\!<>\:\.\w]+)([\s]+<extended>)?/';
63+
const REGEX = '/@covers[\s]+([A-Za-z!<>:.\\\\]+)([\s]+<extended>)?/';
6464

6565
/**
6666
* @var array

Tests/PHP/CodeCoverage/UtilTest.php

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@
6565
require_once TEST_FILES_PATH . 'CoveragePublicTest.php';
6666
require_once TEST_FILES_PATH . 'CoveredClass.php';
6767

68+
if (version_compare(PHP_VERSION, '5.3', '>')) {
69+
require_once TEST_FILES_PATH . 'NamespaceCoverageClassExtendedTest.php';
70+
require_once TEST_FILES_PATH . 'NamespaceCoverageClassTest.php';
71+
require_once TEST_FILES_PATH . 'NamespaceCoverageMethodTest.php';
72+
require_once TEST_FILES_PATH . 'NamespaceCoverageNotPrivateTest.php';
73+
require_once TEST_FILES_PATH . 'NamespaceCoverageNotProtectedTest.php';
74+
require_once TEST_FILES_PATH . 'NamespaceCoverageNotPublicTest.php';
75+
require_once TEST_FILES_PATH . 'NamespaceCoveragePrivateTest.php';
76+
require_once TEST_FILES_PATH . 'NamespaceCoverageProtectedTest.php';
77+
require_once TEST_FILES_PATH . 'NamespaceCoveragePublicTest.php';
78+
require_once TEST_FILES_PATH . 'NamespaceCoveredClass.php';
79+
}
80+
6881
/**
6982
* Tests for the PHP_CodeCoverage_Util class.
7083
*
@@ -232,6 +245,194 @@ public function testGetLinesToBeCovered9()
232245
);
233246
}
234247

248+
/**
249+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
250+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
251+
*/
252+
public function testGetLinesToBeCovered10()
253+
{
254+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
255+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
256+
}
257+
258+
$this->assertEquals(
259+
array(
260+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => array_merge(
261+
range(21, 38), range(4, 19)
262+
)
263+
),
264+
PHP_CodeCoverage_Util::getLinesToBeCovered(
265+
'NamespaceCoverageClassExtendedTest', 'testPublicMethod'
266+
)
267+
);
268+
}
269+
270+
/**
271+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
272+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
273+
*/
274+
public function testGetLinesToBeCovered11()
275+
{
276+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
277+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
278+
}
279+
280+
$this->assertEquals(
281+
array(
282+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => range(21, 38)
283+
),
284+
PHP_CodeCoverage_Util::getLinesToBeCovered(
285+
'NamespaceCoverageClassTest', 'testPublicMethod'
286+
)
287+
);
288+
}
289+
290+
/**
291+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
292+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
293+
*/
294+
public function testGetLinesToBeCovered12()
295+
{
296+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
297+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
298+
}
299+
300+
$this->assertEquals(
301+
array(
302+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => range(33, 37)
303+
),
304+
PHP_CodeCoverage_Util::getLinesToBeCovered(
305+
'NamespaceCoverageMethodTest', 'testPublicMethod'
306+
)
307+
);
308+
}
309+
310+
/**
311+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
312+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
313+
*/
314+
public function testGetLinesToBeCovered13()
315+
{
316+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
317+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
318+
}
319+
320+
$this->assertEquals(
321+
array(
322+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => array_merge(
323+
range(27, 31), range(33, 37)
324+
)
325+
),
326+
PHP_CodeCoverage_Util::getLinesToBeCovered(
327+
'NamespaceCoverageNotPrivateTest', 'testPublicMethod'
328+
)
329+
);
330+
}
331+
332+
/**
333+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
334+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
335+
*/
336+
public function testGetLinesToBeCovered14()
337+
{
338+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
339+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
340+
}
341+
342+
$this->assertEquals(
343+
array(
344+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => array_merge(
345+
range(23, 25), range(33, 37)
346+
)
347+
),
348+
PHP_CodeCoverage_Util::getLinesToBeCovered(
349+
'NamespaceCoverageNotProtectedTest', 'testPublicMethod'
350+
)
351+
);
352+
}
353+
354+
/**
355+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
356+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
357+
*/
358+
public function testGetLinesToBeCovered15()
359+
{
360+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
361+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
362+
}
363+
364+
$this->assertEquals(
365+
array(
366+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => array_merge(
367+
range(23, 25), range(27, 31)
368+
)
369+
),
370+
PHP_CodeCoverage_Util::getLinesToBeCovered(
371+
'NamespaceCoverageNotPublicTest', 'testPublicMethod'
372+
)
373+
);
374+
}
375+
376+
/**
377+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
378+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
379+
*/
380+
public function testGetLinesToBeCovered16()
381+
{
382+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
383+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
384+
}
385+
386+
$this->assertEquals(
387+
array(
388+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => range(23, 25)
389+
),
390+
PHP_CodeCoverage_Util::getLinesToBeCovered(
391+
'NamespaceCoveragePrivateTest', 'testPublicMethod'
392+
)
393+
);
394+
}
395+
396+
/**
397+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
398+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
399+
*/
400+
public function testGetLinesToBeCovered17()
401+
{
402+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
403+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
404+
}
405+
406+
$this->assertEquals(
407+
array(
408+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => range(27, 31)
409+
),
410+
PHP_CodeCoverage_Util::getLinesToBeCovered(
411+
'NamespaceCoverageProtectedTest', 'testPublicMethod'
412+
)
413+
);
414+
}
415+
416+
/**
417+
* @covers PHP_CodeCoverage_Util::getLinesToBeCovered
418+
* @covers PHP_CodeCoverage_Util::resolveCoversToReflectionObjects
419+
*/
420+
public function testGetLinesToBeCovered18()
421+
{
422+
if (!version_compare(PHP_VERSION, '5.3', '>')) {
423+
$this->markTestSkipped('PHP 5.3 (or later) is required.');
424+
}
425+
426+
$this->assertEquals(
427+
array(
428+
TEST_FILES_PATH . 'NamespaceCoveredClass.php' => range(33, 37)
429+
),
430+
PHP_CodeCoverage_Util::getLinesToBeCovered(
431+
'NamespaceCoveragePublicTest', 'testPublicMethod'
432+
)
433+
);
434+
}
435+
235436
/**
236437
* @covers PHP_CodeCoverage_Util::getLinesToBeIgnored
237438
*/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoverageClassExtendedTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass<extended>
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoverageClassTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoverageMethodTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass::publicMethod
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoverageNotPrivateTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass::<!private>
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoverageNotProtectedTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass::<!protected>
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoverageNotPublicTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass::<!public>
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoveragePrivateTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass::<private>
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
class NamespaceCoverageProtectedTest extends PHPUnit_Framework_TestCase
3+
{
4+
/**
5+
* @covers Foo\CoveredClass::<protected>
6+
*/
7+
public function testPublicMethod()
8+
{
9+
$o = new Foo\CoveredClass;
10+
$o->publicMethod();
11+
}
12+
}

0 commit comments

Comments
 (0)