Skip to content

Commit 46fc70e

Browse files
committed
Rewrite FromDirectory source to use lang.reflection.Type::instantiable()
...instead of checking for interfaces, traits and abstract classes
1 parent 097d4c0 commit 46fc70e

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
## ?.?.? / ????-??-??
55

6+
## 2.1.0 / 2024-03-28
7+
8+
* Made `FromDirectory` consistent with other source implementations in
9+
regard to how it filters the types returned
10+
(@thekid)
11+
612
## 2.0.0 / 2024-03-23
713

814
This second major release upgrades this library to support only the latest

src/main/php/test/source/FromDirectory.class.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php namespace test\source;
22

33
use io\{Folder, Path};
4-
use lang\{ClassLoader, FileSystemClassLoader, IllegalArgumentException};
4+
use lang\{ClassLoader, FileSystemClassLoader, IllegalArgumentException, Reflection};
55
use test\execution\TestClass;
66

77
class FromDirectory extends Source {
@@ -42,7 +42,7 @@ private function testClassesIn($cl, $folder) {
4242
} else if (($p= strpos($entry->name(), '.')) && 0 === substr_compare($entry->name(), 'Test', $p - 4, 4)) {
4343
$uri= $entry->asURI();
4444
if ($loader= $cl->findUri($uri)) {
45-
yield $loader->loadUri($uri);
45+
yield Reflection::type($loader->loadUri($uri));
4646
}
4747
}
4848
}
@@ -51,8 +51,9 @@ private function testClassesIn($cl, $folder) {
5151
/** @return iterable */
5252
public function groups() {
5353
foreach ($this->testClassesIn(ClassLoader::getDefault(), $this->folder) as $class) {
54-
if ($class->isInterface() || $class->isTrait() || $class->getModifiers() & MODIFIER_ABSTRACT) continue;
55-
yield new TestClass($class);
54+
if ($class->instantiable()) {
55+
yield new TestClass($class);
56+
}
5657
}
5758
}
5859

src/main/php/test/source/FromFile.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ public function __construct($arg) {
1717
}
1818

1919
if ($loader= ClassLoader::getDefault()->findUri($this->path)) {
20-
$this->type= $loader->loadUri($this->path);
20+
$this->type= Reflection::type($loader->loadUri($this->path));
2121
return;
2222
}
2323

2424
throw new IllegalArgumentException($this->path.' is not in class path');
2525
}
2626

2727
/** Returns the type discovered from the file */
28-
public function type(): Type { return Reflection::type($this->type); }
28+
public function type(): Type { return $this->type; }
2929

3030
/** @return iterable */
3131
public function groups() {
32-
yield new TestClass($this->type());
32+
yield new TestClass($this->type);
3333
}
3434

3535
/** @return string */

src/main/php/test/source/FromPackage.class.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ private function typesIn($package) {
3535
/** @return iterable */
3636
public function groups() {
3737
foreach ($this->typesIn($this->package) as $type) {
38-
if ($type->instantiable() && 0 === substr_compare($type->name(), 'Test', -4, 4)) yield new TestClass($type);
38+
if ($type->instantiable() && 0 === substr_compare($type->name(), 'Test', -4, 4)) {
39+
yield new TestClass($type);
40+
}
3941
}
4042
}
4143

0 commit comments

Comments
 (0)