Skip to content

Commit d4e4655

Browse files
Implement SchemaFinder::available()
1 parent 78b6f7e commit d4e4655

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/Util/Xml/SchemaFinder.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,43 @@
99
*/
1010
namespace PHPUnit\Util\Xml;
1111

12+
use function assert;
1213
use function defined;
1314
use function is_file;
15+
use function rsort;
1416
use function sprintf;
17+
use DirectoryIterator;
1518
use PHPUnit\Runner\Version;
1619

1720
/**
1821
* @internal This class is not covered by the backward compatibility promise for PHPUnit
1922
*/
2023
final class SchemaFinder
2124
{
25+
/**
26+
* @psalm-return non-empty-list<non-empty-string>
27+
*/
28+
public function available(): array
29+
{
30+
$result = [Version::series()];
31+
32+
foreach ((new DirectoryIterator($this->path() . 'schema')) as $file) {
33+
if ($file->isDot()) {
34+
continue;
35+
}
36+
37+
$version = $file->getBasename('.xsd');
38+
39+
assert(!empty($version));
40+
41+
$result[] = $version;
42+
}
43+
44+
rsort($result);
45+
46+
return $result;
47+
}
48+
2249
/**
2350
* @throws Exception
2451
*/

tests/unit/Util/Xml/SchemaFinderTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
namespace PHPUnit\Util\Xml;
1111

12+
use function count;
1213
use PHPUnit\Framework\TestCase;
1314
use PHPUnit\Runner\Version;
1415

@@ -19,12 +20,20 @@
1920
*/
2021
final class SchemaFinderTest extends TestCase
2122
{
22-
public function testFindsExistingSchemaForComposerInstallation(): void
23+
public function testListsAvailableSchemas(): void
24+
{
25+
$schemas = (new SchemaFinder)->available();
26+
27+
$this->assertSame((new Version)->series(), $schemas[0]);
28+
$this->assertSame('8.5', $schemas[count($schemas) - 1]);
29+
}
30+
31+
public function testFindsExistingSchema(): void
2332
{
2433
$this->assertFileExists((new SchemaFinder)->find((new Version)->series()));
2534
}
2635

27-
public function testDoesNotFindNonExistentSchemaForComposerInstallation(): void
36+
public function testDoesNotFindNonExistentSchema(): void
2837
{
2938
$this->expectException(Exception::class);
3039

0 commit comments

Comments
 (0)