2013-10-18 17:00:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\BehatExtension\Compiler;
|
|
|
|
|
2017-06-21 08:17:18 +02:00
|
|
|
use SilverStripe\Control\CLIRequestBuilder;
|
|
|
|
use SilverStripe\Control\Controller;
|
|
|
|
use SilverStripe\Control\HTTPApplication;
|
|
|
|
use SilverStripe\Control\HTTPRequest;
|
|
|
|
use SilverStripe\Core\CoreKernel;
|
2014-08-02 08:30:27 +02:00
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
2017-06-21 08:17:18 +02:00
|
|
|
use SilverStripe\ORM\DataObject;
|
2016-08-10 03:35:13 +02:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
2013-10-18 17:00:07 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads SilverStripe core. Required to initialize autoloading.
|
|
|
|
*/
|
|
|
|
class CoreInitializationPass implements CompilerPassInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Loads kernel file.
|
|
|
|
*
|
|
|
|
* @param ContainerBuilder $container
|
|
|
|
*/
|
|
|
|
public function process(ContainerBuilder $container)
|
|
|
|
{
|
2017-06-21 08:17:18 +02:00
|
|
|
// Note: Moved from SilverStripeAwareInitializer
|
|
|
|
file_put_contents('php://stdout', 'Bootstrapping' . PHP_EOL);
|
|
|
|
|
2013-10-18 17:00:07 +02:00
|
|
|
// Connect to database and build manifest
|
2017-02-27 22:53:41 +01:00
|
|
|
if (!getenv('SS_ENVIRONMENT_TYPE')) {
|
|
|
|
putenv('SS_ENVIRONMENT_TYPE=dev');
|
|
|
|
}
|
2016-09-01 06:22:47 +02:00
|
|
|
|
2017-02-27 03:49:31 +01:00
|
|
|
// Include bootstrap file
|
2014-08-02 08:30:27 +02:00
|
|
|
$bootstrapFile = $container->getParameter('silverstripe_extension.bootstrap_file');
|
2017-02-27 03:49:31 +01:00
|
|
|
if ($bootstrapFile) {
|
|
|
|
require_once $bootstrapFile;
|
|
|
|
}
|
2015-08-28 06:50:51 +02:00
|
|
|
|
2017-06-21 08:17:18 +02:00
|
|
|
// Copied from SapphireTest
|
|
|
|
$request = CLIRequestBuilder::createFromEnvironment();
|
|
|
|
$kernel = new CoreKernel(BASE_PATH);
|
|
|
|
$app = new HTTPApplication($kernel);
|
|
|
|
$app->execute($request, function (HTTPRequest $request) {
|
|
|
|
// Start session and execute
|
2017-06-27 00:51:39 +02:00
|
|
|
$request->getSession()->init($request);
|
2017-06-21 08:17:18 +02:00
|
|
|
|
|
|
|
// Invalidate classname spec since the test manifest will now pull out new subclasses for each internal class
|
|
|
|
// (e.g. Member will now have various subclasses of DataObjects that implement TestOnly)
|
|
|
|
DataObject::reset();
|
|
|
|
|
|
|
|
// Set dummy controller;
|
|
|
|
$controller = Controller::create();
|
|
|
|
$controller->setRequest($request);
|
|
|
|
$controller->pushCurrent();
|
|
|
|
$controller->doInit();
|
|
|
|
}, true);
|
|
|
|
|
2014-08-02 08:30:27 +02:00
|
|
|
// Register all paths
|
2017-05-19 04:47:02 +02:00
|
|
|
foreach (ModuleLoader::inst()->getManifest()->getModules() as $module) {
|
2014-08-02 08:30:27 +02:00
|
|
|
$container->setParameter('paths.modules.'.$module->getShortName(), $module->getPath());
|
|
|
|
$composerName = $module->getComposerName();
|
|
|
|
if ($composerName) {
|
|
|
|
list($vendor,$name) = explode('/', $composerName);
|
|
|
|
$container->setParameter('paths.modules.'.$vendor.'.'.$name, $module->getPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-18 17:00:07 +02:00
|
|
|
// Remove the error handler so that PHPUnit can add its own
|
|
|
|
restore_error_handler();
|
|
|
|
}
|
2016-08-10 03:35:13 +02:00
|
|
|
}
|