Skip to content

Commit 859dd52

Browse files
Minimize the cost of computing the path to the test directory
1 parent b041601 commit 859dd52

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tests/AbstractTestCase.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
abstract class AbstractTestCase extends TestCase
88
{
9+
protected $testDirectory = '';
10+
911
protected function createTestDirectory()
1012
{
1113
if (!is_dir($this->getTestDirectory())) {
@@ -15,16 +17,20 @@ protected function createTestDirectory()
1517

1618
protected function getTestDirectory()
1719
{
18-
$inheritingClassFQCN = get_class($this);
19-
$inheritingClassName = substr($inheritingClassFQCN, strrpos($inheritingClassFQCN, '\\') + 1);
20+
if ($this->testDirectory === '') {
21+
$inheritingClassFQCN = get_class($this);
22+
$inheritingClassName = substr($inheritingClassFQCN, strrpos($inheritingClassFQCN, '\\') + 1);
23+
24+
try {
25+
$inheritingClassDirectory = dirname((new \ReflectionClass($inheritingClassFQCN))->getFileName());
26+
} catch (\ReflectionException $exception) {
27+
$inheritingClassDirectory = __DIR__;
28+
}
2029

21-
try {
22-
$inheritingClassDirectory = dirname((new \ReflectionClass($inheritingClassFQCN))->getFileName());
23-
} catch (\ReflectionException $exception) {
24-
$inheritingClassDirectory = __DIR__;
30+
$this->testDirectory = $inheritingClassDirectory.'/'.$inheritingClassName;
2531
}
2632

27-
return $inheritingClassDirectory.'/'.$inheritingClassName;
33+
return $this->testDirectory;
2834
}
2935

3036
protected function removeTestDirectory()

0 commit comments

Comments
 (0)