Fix manifest tests

This commit is contained in:
Damian Mooyman 2017-06-13 15:23:52 +12:00
parent ca03395251
commit a0ae723514
9 changed files with 50 additions and 31 deletions

View File

@ -58,7 +58,7 @@ class AppKernel extends CoreKernel
// Config loader
// @todo refactor CoreConfigFactory
$configFactory = new CoreConfigFactory($manifestCacheFactory, $this->getEnvironment());
$configFactory = new CoreConfigFactory($manifestCacheFactory);
$configManifest = $configFactory->createRoot();
$configLoader = ConfigLoader::inst();
$configLoader->pushManifest($configManifest);
@ -76,17 +76,17 @@ class AppKernel extends CoreKernel
public function getEnvironment()
{
// Check set
if ($this->enviroment) {
return $this->enviroment;
}
// Check saved session
$env = $this->sessionEnvironment();
if ($env) {
return $env;
}
// Check set
if ($this->enviroment) {
return $this->enviroment;
}
// Check getenv
if ($env = getenv('SS_ENVIRONMENT_TYPE')) {
return $env;

View File

@ -10,6 +10,8 @@ use SilverStripe\Config\Transformer\YamlTransformer;
use SilverStripe\Core\Cache\CacheFactory;
use SilverStripe\Core\Config\Middleware\ExtensionMiddleware;
use SilverStripe\Core\Config\Middleware\InheritanceMiddleware;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;
use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\Core\Manifest\ModuleLoader;
use Symfony\Component\Finder\Finder;
@ -25,14 +27,13 @@ class CoreConfigFactory
protected $cacheFactory = null;
/**
* @var string
* Create factory
*
* @param CacheFactory $cacheFactory
*/
protected $environment = null;
public function __construct(CacheFactory $cacheFactory, $environment)
public function __construct(CacheFactory $cacheFactory = null)
{
$this->cacheFactory = $cacheFactory;
$this->environment = $environment;
}
/**
@ -47,10 +48,12 @@ class CoreConfigFactory
$instance = new CachedConfigCollection();
// Create config cache
$cache = $this->cacheFactory->create(CacheInterface::class.'.configcache', [
'namespace' => 'configcache'
]);
$instance->setCache($cache);
if ($this->cacheFactory) {
$cache = $this->cacheFactory->create(CacheInterface::class . '.configcache', [
'namespace' => 'configcache'
]);
$instance->setCache($cache);
}
// Set collection creator
$instance->setCollectionCreator(function () {
@ -162,7 +165,11 @@ class CoreConfigFactory
}
)
->addRule('environment', function ($env) {
return strtolower($this->environment) === strtolower($env);
// Note: The below relies on direct assignment of kernel to injector instance,
// and will fail if failing back to config service locator
/** @var Kernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
return strtolower($kernel->getEnvironment()) === strtolower($env);
})
->addRule('moduleexists', function ($module) {
return ModuleLoader::inst()->getManifest()->moduleExists($module);

View File

@ -9,8 +9,8 @@ class TestKernel extends AppKernel
{
public function __construct($flush = true)
{
parent::__construct($flush);
$this->setEnvironment(self::DEV);
parent::__construct($flush);
}
/**

View File

@ -36,10 +36,12 @@ class ClassLoaderTest extends SapphireTest
{
parent::setUp();
$this->baseManifest1 = dirname(__FILE__) . '/fixtures/classmanifest';
$this->baseManifest2 = dirname(__FILE__) . '/fixtures/classmanifest_other';
$this->testManifest1 = new ClassManifest($this->baseManifest1, false);
$this->testManifest2 = new ClassManifest($this->baseManifest2, false);
$this->baseManifest1 = __DIR__ . '/fixtures/classmanifest';
$this->baseManifest2 = __DIR__ . '/fixtures/classmanifest_other';
$this->testManifest1 = new ClassManifest($this->baseManifest1);
$this->testManifest2 = new ClassManifest($this->baseManifest2);
$this->testManifest1->init();
$this->testManifest2->init();
}
public function testExclusive()

View File

@ -32,8 +32,10 @@ class ClassManifestTest extends SapphireTest
parent::setUp();
$this->base = dirname(__FILE__) . '/fixtures/classmanifest';
$this->manifest = new ClassManifest($this->base, false);
$this->manifestTests = new ClassManifest($this->base, true);
$this->manifest = new ClassManifest($this->base);
$this->manifest->init(false);
$this->manifestTests = new ClassManifest($this->base);
$this->manifestTests->init(true);
}
public function testGetItemPath()
@ -155,6 +157,7 @@ class ClassManifestTest extends SapphireTest
public function testManifestWarnsAboutDuplicateClasses()
{
$this->expectException(Exception::class);
new ClassManifest(dirname(__FILE__) . '/fixtures/classmanifest_duplicates', false);
$manifest = new ClassManifest(dirname(__FILE__) . '/fixtures/classmanifest_duplicates');
$manifest->init();
}
}

View File

@ -4,8 +4,9 @@ namespace SilverStripe\Core\Tests\Manifest;
use Dotenv\Loader;
use SilverStripe\Config\Collections\MemoryConfigCollection;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\CoreConfigFactory;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Core\Manifest\ModuleManifest;
use SilverStripe\Dev\SapphireTest;
@ -17,6 +18,7 @@ class ConfigManifestTest extends SapphireTest
parent::setUp();
$moduleManifest = new ModuleManifest(dirname(__FILE__) . '/fixtures/configmanifest');
$moduleManifest->init();
ModuleLoader::inst()->pushManifest($moduleManifest);
}
@ -45,7 +47,8 @@ class ConfigManifestTest extends SapphireTest
public function getTestConfig()
{
$config = new MemoryConfigCollection();
$transformer = CoreConfigFactory::inst()->buildYamlTransformerForPath(dirname(__FILE__) . '/fixtures/configmanifest');
$factory = new CoreConfigFactory();
$transformer = $factory->buildYamlTransformerForPath(dirname(__FILE__) . '/fixtures/configmanifest');
$config->transform([$transformer]);
return $config;
}
@ -173,8 +176,10 @@ class ConfigManifestTest extends SapphireTest
public function testEnvironmentRules()
{
/** @var Kernel $kernel */
$kernel = Injector::inst()->get(Kernel::class);
foreach (array('dev', 'test', 'live') as $env) {
Director::set_environment_type($env);
$kernel->setEnvironment($env);
$config = $this->getConfigFixtureValue('Environment');
foreach (array('dev', 'test', 'live') as $check) {

View File

@ -1,6 +1,5 @@
<?php
namespace SilverStripe\Core\Tests\Manifest;
use SilverStripe\Core\Manifest\ModuleManifest;
@ -23,7 +22,8 @@ class ModuleManifestTest extends SapphireTest
parent::setUp();
$this->base = dirname(__FILE__) . '/fixtures/classmanifest';
$this->manifest = new ModuleManifest($this->base, false);
$this->manifest = new ModuleManifest($this->base);
$this->manifest->init();
}
public function testGetModules()

View File

@ -28,7 +28,8 @@ class NamespacedClassManifestTest extends SapphireTest
parent::setUp();
$this->base = dirname(__FILE__) . '/fixtures/namespaced_classmanifest';
$this->manifest = new ClassManifest($this->base, false);
$this->manifest = new ClassManifest($this->base);
$this->manifest->init();
ClassLoader::inst()->pushManifest($this->manifest, false);
}

View File

@ -36,7 +36,8 @@ class ThemeResourceLoaderTest extends SapphireTest
// Fake project root
$this->base = dirname(__FILE__) . '/fixtures/templatemanifest';
// New ThemeManifest for that root
$this->manifest = new ThemeManifest($this->base, 'myproject', false);
$this->manifest = new ThemeManifest($this->base, 'myproject');
$this->manifest->init();
// New Loader for that root
$this->loader = new ThemeResourceLoader($this->base);
$this->loader->addSet('$default', $this->manifest);