1
0
mirror of https://github.com/danog/class-finder.git synced 2024-11-30 04:29:03 +01:00

Add some minimal test harness.

This commit is contained in:
Hayden Pierce 2018-09-29 13:27:19 -05:00
parent f56e0b26d4
commit 77aa8b9460
7 changed files with 80 additions and 1 deletions

View File

@ -20,5 +20,9 @@
<file>test/app1/src/ClassmapTest.php</file> <file>test/app1/src/ClassmapTest.php</file>
<directory>test/unit/Classmap</directory> <directory>test/unit/Classmap</directory>
</testsuite> </testsuite>
<testsuite name="files">
<file>test/app1/src/FilesTest.php</file>
<directory>test/unit/Files</directory>
</testsuite>
</testsuites> </testsuites>
</phpunit> </phpunit>

View File

@ -18,6 +18,7 @@
"TestApp1\\": "src/", "TestApp1\\": "src/",
"TestApp1\\Multi\\": [ "multi/Jik/", "multi/Jiu/" ] "TestApp1\\Multi\\": [ "multi/Jik/", "multi/Jiu/" ]
}, },
"classmap": ["classmap/woc/", "classmap/wop/", "classmap/woj/" ] "classmap": ["classmap/woc/", "classmap/wop/", "classmap/woj/" ],
"files": ["files/files1.php", "files/files2.php", "files/more_files/Boom.php" ]
} }
} }

View File

@ -0,0 +1,3 @@
<?php
namespace TestApp1\FilesClasses;

View File

@ -0,0 +1,7 @@
<?php
namespace TestApp1\FilesClasses;
class Bam {};
class Wam {};
class Fam {};

View File

@ -0,0 +1,10 @@
<?php
// This is intentionally made global. There are intentionally classes here in and out of a namespace.
// PHPStorm is subborn in it's complaining about this - so I just turn off inspections for this file.
class my_global_class_name {}
namespace TestApp1\FilesClasses;
class Cam {}
class Lam {}

View File

@ -0,0 +1,7 @@
<?php
namespace MoreFiles;
class Boom {}
class Zoom {}
class Loom {}

View File

@ -0,0 +1,47 @@
<?php
namespace TestApp1;
require_once __DIR__ . '/../vendor/autoload.php';
use HaydenPierce\ClassFinder\ClassFinder;
class FilesTest extends \PHPUnit_Framework_TestCase
{
public function setup()
{
// Reset ClassFinder back to normal.
ClassFinder::setAppRoot(null);
}
/**
* @dataProvider classFinderDataProvider
*/
public function testClassFinder($namespace, $expected, $message)
{
try {
$classes = ClassFinder::getClassesInNamespace($namespace);
} catch (\Exception $e) {
$this->assertFalse(true, 'An exception occurred: ' . $e->getMessage());
$classes = array();
}
$this->assertEquals($expected, $classes, $message);
}
public function classFinderDataProvider()
{
return array(
array(
'TestApp1\FilesClasses',
array(
'TestApp1\FilesClasses\Bam',
'TestApp1\FilesClasses\Wam',
'TestApp1\FilesClasses\Fam',
'TestApp1\FilesClasses\Cam',
'TestApp1\FilesClasses\Lam',
),
'ClassFinder should be able to find 1st party classes included from `files` listed in composer.json.'
)
);
}
}