2011-03-18 07:35:20 +01:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
2016-12-16 05:34:21 +01:00
|
|
|
namespace SilverStripe\Core\Tests\Manifest;
|
|
|
|
|
2017-03-14 03:20:51 +01:00
|
|
|
use Exception;
|
2016-09-09 08:43:05 +02:00
|
|
|
use SilverStripe\Core\Manifest\ClassManifest;
|
2016-08-19 00:51:35 +02:00
|
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
|
2011-03-18 07:35:20 +01:00
|
|
|
/**
|
2016-09-09 08:43:05 +02:00
|
|
|
* Tests for the {@link ClassManifest} class.
|
2011-03-18 07:35:20 +01:00
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
class ClassManifestTest extends SapphireTest
|
|
|
|
{
|
|
|
|
|
2017-03-14 03:20:51 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $base;
|
2017-03-14 03:20:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ClassManifest
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $manifest;
|
2017-03-14 03:20:51 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var ClassManifest
|
|
|
|
*/
|
2016-12-16 05:34:21 +01:00
|
|
|
protected $manifestTests;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->base = dirname(__FILE__) . '/fixtures/classmanifest';
|
2017-03-14 03:20:51 +01:00
|
|
|
$this->manifest = new ClassManifest($this->base, false);
|
|
|
|
$this->manifestTests = new ClassManifest($this->base, true);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetItemPath()
|
|
|
|
{
|
|
|
|
$expect = array(
|
|
|
|
'CLASSA' => 'module/classes/ClassA.php',
|
|
|
|
'ClassA' => 'module/classes/ClassA.php',
|
|
|
|
'classa' => 'module/classes/ClassA.php',
|
|
|
|
'INTERFACEA' => 'module/interfaces/InterfaceA.php',
|
|
|
|
'InterfaceA' => 'module/interfaces/InterfaceA.php',
|
|
|
|
'interfacea' => 'module/interfaces/InterfaceA.php',
|
|
|
|
'TestTraitA' => 'module/traits/TestTraitA.php',
|
|
|
|
'TestNamespace\Testing\TestTraitB' => 'module/traits/TestTraitB.php'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($expect as $name => $path) {
|
|
|
|
$this->assertEquals("{$this->base}/$path", $this->manifest->getItemPath($name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetClasses()
|
|
|
|
{
|
|
|
|
$expect = array(
|
|
|
|
'classa' => "{$this->base}/module/classes/ClassA.php",
|
|
|
|
'classb' => "{$this->base}/module/classes/ClassB.php",
|
|
|
|
'classc' => "{$this->base}/module/classes/ClassC.php",
|
|
|
|
'classd' => "{$this->base}/module/classes/ClassD.php",
|
2017-02-20 22:57:20 +01:00
|
|
|
'classe' => "{$this->base}/module/classes/ClassE.php",
|
2016-12-16 05:34:21 +01:00
|
|
|
);
|
|
|
|
$this->assertEquals($expect, $this->manifest->getClasses());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetClassNames()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
2017-02-28 21:29:31 +01:00
|
|
|
['classa', 'classb', 'classc', 'classd', 'classe'],
|
2016-12-16 05:34:21 +01:00
|
|
|
$this->manifest->getClassNames()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetTraitNames()
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
array('testtraita', 'testnamespace\testing\testtraitb'),
|
|
|
|
$this->manifest->getTraitNames()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDescendants()
|
|
|
|
{
|
|
|
|
$expect = array(
|
|
|
|
'classa' => array('ClassC', 'ClassD'),
|
|
|
|
'classc' => array('ClassD')
|
|
|
|
);
|
|
|
|
$this->assertEquals($expect, $this->manifest->getDescendants());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDescendantsOf()
|
|
|
|
{
|
|
|
|
$expect = array(
|
|
|
|
'CLASSA' => array('ClassC', 'ClassD'),
|
|
|
|
'classa' => array('ClassC', 'ClassD'),
|
|
|
|
'CLASSC' => array('ClassD'),
|
|
|
|
'classc' => array('ClassD')
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($expect as $class => $desc) {
|
|
|
|
$this->assertEquals($desc, $this->manifest->getDescendantsOf($class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetInterfaces()
|
|
|
|
{
|
|
|
|
$expect = array(
|
|
|
|
'interfacea' => "{$this->base}/module/interfaces/InterfaceA.php",
|
|
|
|
'interfaceb' => "{$this->base}/module/interfaces/InterfaceB.php"
|
|
|
|
);
|
|
|
|
$this->assertEquals($expect, $this->manifest->getInterfaces());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetImplementors()
|
|
|
|
{
|
|
|
|
$expect = array(
|
|
|
|
'interfacea' => array('ClassB'),
|
|
|
|
'interfaceb' => array('ClassC')
|
|
|
|
);
|
|
|
|
$this->assertEquals($expect, $this->manifest->getImplementors());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetImplementorsOf()
|
|
|
|
{
|
|
|
|
$expect = array(
|
|
|
|
'INTERFACEA' => array('ClassB'),
|
|
|
|
'interfacea' => array('ClassB'),
|
|
|
|
'INTERFACEB' => array('ClassC'),
|
|
|
|
'interfaceb' => array('ClassC')
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($expect as $interface => $impl) {
|
|
|
|
$this->assertEquals($impl, $this->manifest->getImplementorsOf($interface));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTestManifestIncludesTestClasses()
|
|
|
|
{
|
|
|
|
$this->assertNotContains('testclassa', array_keys($this->manifest->getClasses()));
|
|
|
|
$this->assertContains('testclassa', array_keys($this->manifestTests->getClasses()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testManifestExcludeFilesPrefixedWithUnderscore()
|
|
|
|
{
|
|
|
|
$this->assertNotContains('ignore', array_keys($this->manifest->getClasses()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that ClassManifest throws an exception when it encounters two files
|
|
|
|
* which contain classes with the same name
|
|
|
|
*/
|
|
|
|
public function testManifestWarnsAboutDuplicateClasses()
|
|
|
|
{
|
2017-03-14 03:20:51 +01:00
|
|
|
$this->setExpectedException(Exception::class);
|
|
|
|
new ClassManifest(dirname(__FILE__) . '/fixtures/classmanifest_duplicates', false);
|
2016-12-16 05:34:21 +01:00
|
|
|
}
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|