Skip to content

Commit ea0a87e

Browse files
Closes #1064
1 parent 72a906b commit ea0a87e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

ChangeLog-12.0.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [12.0.5] - 2025-MM-DD
6+
7+
### Fixed
8+
9+
* [#1064](https://github.com/sebastianbergmann/php-code-coverage/issues/1064): Code Coverage targets are handled in case-sensitive manner
10+
511
## [12.0.4] - 2025-02-25
612

713
### Fixed
@@ -39,6 +45,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
3945
* This component is no longer supported on PHP 8.2
4046
* This component no longer supports Xdebug versions before Xdebug 3.1
4147

48+
[12.0.5]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.4...main
4249
[12.0.4]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.3...12.0.4
4350
[12.0.3]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.2...12.0.3
4451
[12.0.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/12.0.1...12.0.2

src/Target/Mapper.php

+8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
*/
1010
namespace SebastianBergmann\CodeCoverage\Test\Target;
1111

12+
use function array_keys;
1213
use function array_merge;
1314
use function array_unique;
15+
use function strcasecmp;
1416

1517
/**
1618
* @phpstan-type TargetMap array{namespaces: TargetMapPart, traits: TargetMapPart, classes: TargetMapPart, classesThatExtendClass: TargetMapPart, classesThatImplementInterface: TargetMapPart, methods: TargetMapPart, functions: TargetMapPart, reverseLookup: ReverseLookup}
@@ -71,6 +73,12 @@ public function mapTarget(Target $target): array
7173
return $this->map[$target->key()][$target->target()];
7274
}
7375

76+
foreach (array_keys($this->map[$target->key()]) as $key) {
77+
if (strcasecmp($key, $target->target()) === 0) {
78+
return $this->map[$target->key()][$key];
79+
}
80+
}
81+
7482
throw new InvalidCodeCoverageTargetException($target);
7583
}
7684

tests/tests/Target/MapperTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
use function array_merge;
1414
use function range;
1515
use function realpath;
16+
use function strtolower;
1617
use PHPUnit\Framework\Attributes\CoversClass;
1718
use PHPUnit\Framework\Attributes\DataProvider;
1819
use PHPUnit\Framework\Attributes\Small;
1920
use PHPUnit\Framework\Attributes\TestDox;
21+
use PHPUnit\Framework\Attributes\Ticket;
2022
use PHPUnit\Framework\TestCase;
2123
use SebastianBergmann\CodeCoverage\Filter;
2224
use SebastianBergmann\CodeCoverage\StaticAnalysis\ParsingFileAnalyser;
25+
use SebastianBergmann\CodeCoverage\TestFixture\Target\TargetClass;
2326
use SebastianBergmann\CodeCoverage\TestFixture\Target\TargetEnumeration;
2427
use SebastianBergmann\CodeCoverage\TestFixture\Target\TraitOne;
2528

@@ -257,6 +260,22 @@ public function testCannotMapInvalidTargets(string $exceptionMessage, TargetColl
257260
$this->mapper([])->mapTargets($targets);
258261
}
259262

263+
#[Ticket('https://github.com/sebastianbergmann/php-code-coverage/issues/1064')]
264+
public function testCodeUnitTargetingIsCaseInsensitive(): void
265+
{
266+
$path = realpath(__DIR__ . '/../../_files/Target/TargetClass.php');
267+
$mapper = $this->mapper([$path]);
268+
269+
$this->assertSame(
270+
[
271+
$path => range(4, 9),
272+
],
273+
$mapper->mapTarget(
274+
Target::forClass(strtolower(TargetClass::class)),
275+
),
276+
);
277+
}
278+
260279
/**
261280
* @param list<non-empty-string> $files
262281
*/

0 commit comments

Comments
 (0)