Page MenuHomeDevCentral

D1618.diff
No OneTemporary

D1618.diff

diff --git a/tests/Registration/AutoloaderTest.php b/tests/Registration/AutoloaderTest.php
--- a/tests/Registration/AutoloaderTest.php
+++ b/tests/Registration/AutoloaderTest.php
@@ -4,12 +4,15 @@
namespace Keruald\OmniTools\Tests\Registration;
use Keruald\OmniTools\Registration\Autoloader;
+use Keruald\OmniTools\Tests\WithData;
use PHPUnit\Framework\TestCase;
use Acme\MockLib\Foo; // a mock class in a mock namespace to test autoload.
class AutoloaderTest extends TestCase {
+ use WithData;
+
public function testRegisterPSR4 () : void {
$class = Foo::class;
$this->assertFalse(
@@ -17,7 +20,7 @@
"Please reconfigure the test suite not to include the $class class."
);
- Autoloader::registerPSR4("Acme\\MockLib\\", __DIR__ . "/MockLib");
+ Autoloader::registerPSR4("Acme\\MockLib\\", $this->getDataPath("MockLib"));
$this->assertTrue(class_exists($class));
}
@@ -37,7 +40,7 @@
}
public function testCanInclude () : void {
- $file = __DIR__ . "/MockLib/Foo.php";
+ $file = $this->getDataPath("MockLib/Foo.php");
$this->assertTrue(Autoloader::canInclude($file));
$this->assertFalse(Autoloader::canInclude("/notexisting"));
diff --git a/tests/WithData.php b/tests/WithData.php
new file mode 100644
--- /dev/null
+++ b/tests/WithData.php
@@ -0,0 +1,16 @@
+<?php
+declare(strict_types=1);
+
+namespace Keruald\OmniTools\Tests;
+
+trait WithData {
+
+ protected function getDataPath (string $file) : string {
+ return $this->getDataDirectory() . "/" . $file;
+ }
+
+ protected function getDataDirectory () : string {
+ return __DIR__ . "/data";
+ }
+
+}
diff --git a/tests/Registration/MockLib/Foo.php b/tests/data/MockLib/Foo.php
rename from tests/Registration/MockLib/Foo.php
rename to tests/data/MockLib/Foo.php

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 19, 02:19 (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2251679
Default Alt Text
D1618.diff (1 KB)

Event Timeline