Elgg\TestCase::bootstrap PHP Method

bootstrap() public static method

Bootstraps test suite
public static bootstrap ( ) : void
return void
    public static function bootstrap()
    {
        date_default_timezone_set('America/Los_Angeles');
        error_reporting(E_ALL | E_STRICT);
        $config = new Config((object) self::getTestingConfigArray());
        $sp = new ServiceProvider($config);
        $sp->setFactory('plugins', function (ServiceProvider $c) {
            $pool = new InMemory();
            return new TestingPlugins($pool, $c->pluginSettingsCache);
        });
        $sp->setValue('mailer', new InMemoryTransport());
        $sp->siteSecret->setTestingSecret('z1234567890123456789012345678901');
        // persistentLogin service needs this set to instantiate without calling DB
        $sp->config->getCookieConfig();
        $app = new Application($sp);
        Application::setTestingApplication(true);
        Application::$_instance = $app;
        // loadCore bails on repeated calls, so we need to manually inject this to make
        // sure it happens before each test.
        $app->loadCore();
        _elgg_services($sp);
        // Invalidate memcache
        _elgg_get_memcache('new_entity_cache')->clear();
        self::$_mocks = null;
        // reset mocking service
    }

Usage Example

Example #1
0
<?php

/**
 * Instead of relying on this bootstrap, which leads to unreliable global state,
 * test cases should extend \Elgg\TestCase, which resets service providers
 * during test initialization making sure altered state does not
 * flow over to the next test case.
 * 
 * @deprecated 2.3
 */
if (!defined('PHPUNIT_ELGG_TESTING_APPLICATION') || function_exists('_elgg_testing_application')) {
    // this value is set by phpunit.xml
    return;
}
\Elgg\TestCase::bootstrap();
/**
 * Get/set an Application for testing purposes
 *
 * @param \Elgg\Application $app Elgg Application
 * @return \Elgg\Application
 * @deprecated 2.3 Use elgg() instead
 */
function _elgg_testing_application(\Elgg\Application $app = null)
{
    if ($app) {
        \Elgg\Application::$_instance = $app;
    }
    return elgg();
}
/**
 * Set/get testing config