예제 #1
0
 /**
  * @expectedException        Message\Cog\Config\Exception
  * @expectedExceptionMessage Config file `vfs://config/myconfig.yml` is not readable
  */
 public function testExceptionThrownWhenConfigFileNotReadable()
 {
     vfsStream::setup('config');
     vfsStream::newFile('myconfig.yml', 0333)->at(vfsStreamWrapper::getRoot());
     $env = new FauxEnvironment();
     $env->set('staging');
     $loader = new Loader(vfsStream::url('config'), $env);
     $registry = new NonLoadingRegistry($loader);
     $loader->load($registry);
 }
예제 #2
0
 public function testSavingToCache()
 {
     $dir = realpath(__DIR__) . '/fixtures';
     $cache = new \Message\Cog\Cache\Instance(new FauxCache());
     $env = new FauxEnvironment();
     $loader = new LoaderCache($dir, $env, $cache);
     $registry = new NonLoadingRegistry($loader);
     $expected = (include 'expected_groups.php');
     $env->set('live');
     $env->setInstallation('server6');
     $loader->load($registry);
     $this->assertEquals($cache->fetch($loader->getCacheKey()), $expected);
 }
예제 #3
0
    /**
     * Set up everything that is assumed for this bootstrap to run.
     *
     * This is mostly services that are used by other services that are defined
     * earlier.
     *
     * @todo This is a god awful mess. Find a way to improve it.
     */
    public function setUp()
    {
        // Set the command-line arguments (override the phpunit ones)
        $_SERVER['argv'] = array('/usr/bin/php', 'foo:bar1');
        $this->_container = new FauxContainer();
        $this->_bootstrap = new ServicesBootstrap();
        $requestContext = $this->getMock('Message\\Cog\\Routing\\RequestContext');
        $routeCollection = new \Symfony\Component\Routing\RouteCollection();
        // Add config directory as the config loader needs it
        vfsStream::setup('root');
        vfsStream::newDirectory('config')->at(vfsStreamWrapper::getRoot());
        vfsStream::newDirectory('translations')->at(vfsStreamWrapper::getRoot());
        vfsStream::newFile('db.yml', 0777)->at(VfsStreamWrapper::getRoot()->getChild('config'))->setContent('hostname: 127.0.0.1
user: user
pass: password
name: table_name
charset: utf8');
        vfsStream::newFile('app.yml', 0777)->at(VfsStreamWrapper::getRoot()->getChild('config'))->setContent('name: My Application
base-url: default.com
default-contact-email: dev@message.co.uk
default-email-from:
  email: noreply@default.com
  name: My Application
csrf-secret: CHANGE THIS FOR EACH INSTALLATION
session-namespace: cog');
        // Define services normally defined in Application\Loader
        //	$classLoaderMock = $this->getMock('Composer\\Autoload\\ClassLoader');
        $this->_container['class.loader'] = $this->_container->factory(function ($c) {
            return require getcwd() . '/vendor/autoload.php';
        });
        $this->_container['app.loader'] = $this->_container->factory(function ($c) {
            $loader = new AppFauxLoader($c['class.loader'], vfsStream::url('root'));
            $loader->setServiceContainer($c);
            return $loader;
        });
        $env = new FauxEnvironment();
        $env->set('test');
        $this->_container['environment'] = function () use($env) {
            return $env;
        };
        $this->_container['env'] = $this->_container->factory(function ($c) {
            return $c['environment']->get();
        });
        $cacheAdapter = $this->getMockBuilder('Message\\Cog\\Cache\\Adapter\\Filesystem')->disableOriginalConstructor()->getMock();
        $cache = $this->getMockBuilder('Message\\Cog\\Cache\\Instance')->disableOriginalConstructor()->getMock();
        $this->_container['cache.adapter'] = function () use($cacheAdapter) {
            return $cacheAdapter;
        };
        $this->_container['cache'] = function ($c) use($cache) {
            $cache->setPrefix(implode('.', array($c['app.loader']->getAppName(), $c['environment']->get(), $c['environment']->installation())));
            return $cache;
        };
        $this->_container['bootstrap.loader'] = $this->_container->factory(function ($c) {
            return new BootstrapFauxLoader($c);
        });
        $this->_container['routes.compiled'] = $this->_container->factory(function () use($routeCollection) {
            return $routeCollection;
        });
        $this->_container['http.request.context'] = $this->_container->factory(function () use($requestContext) {
            return $requestContext;
        });
        $this->_bootstrap->registerServices($this->_container);
    }