diff --git a/src/Registration/Autoloader.php b/src/Registration/Autoloader.php new file mode 100644 index 0000000..0039e9e --- /dev/null +++ b/src/Registration/Autoloader.php @@ -0,0 +1,39 @@ +assertEquals($expected, Autoloader::getPathFor($class)); + } + + public function testRegisterPSR4 () : void { + $class = Foo::class; + $this->assertFalse( + class_exists($class), + "Please reconfigure the test suite not to include the $class class." + ); + + Autoloader::registerPSR4("Acme\\MockLib\\", __DIR__ . "/MockLib"); + $this->assertTrue(class_exists($class)); + } + + public function testGetLibraryPath () : void { + $this->assertStringStartsWith( + dirname(Autoloader::getLibraryPath()), // lib is in /src + __DIR__ // we are in /tests/… + ); + } + + public function testRegister () : void { + $count = count(spl_autoload_functions()); + + Autoloader::selfRegister(); + + $this->assertEquals(++$count, count(spl_autoload_functions())); + } + + /// + /// Data provider + /// + + public function providePaths () : iterable { + // Example from PSR-4 canonical document + yield ['File_Writer', 'File_Writer.php']; + yield ['Response\Status', 'Response/Status.php']; + yield ['Request', 'Request.php']; + } + +} diff --git a/tests/Registration/MockLib/Foo.php b/tests/Registration/MockLib/Foo.php new file mode 100644 index 0000000..cd1b3fa --- /dev/null +++ b/tests/Registration/MockLib/Foo.php @@ -0,0 +1,15 @@ +