Exemplo n.º 1
0
 /**
  * @covers ::addTestModule
  */
 public function testAddingTestModule()
 {
     $framework = new Framework();
     $application = new TestApplication();
     $framework->configureApplication($application);
     $module = $this->getMockBuilder('Splot\\Framework\\Modules\\AbstractModule')->setMethods(array('getName', 'configure', 'run', 'setContainer'))->getMock();
     $module->expects($this->any())->method('getName')->will($this->returnValue('TestModule'));
     // make sure that container is injected to the module
     $module->expects($this->once())->method('setContainer')->with($this->callback(function ($container) use($application) {
         return $container === $application->getContainer();
     }));
     // make sure that module is allowed to be configured
     $module->expects($this->once())->method('configure');
     // make sure that module is allowed to be run
     $module->expects($this->once())->method('run');
     $application->addTestModule($module, array('test_setting' => 'proper value', 'another_setting' => true));
     $this->assertTrue($application->hasModule('TestModule'));
     $this->assertSame($module, $application->getModule('TestModule'));
     // make sure that config is set in the container and that config contains passed options
     $container = $application->getContainer();
     $this->assertTrue($container->has('config.TestModule'));
     $config = $container->get('config.TestModule');
     $this->assertInstanceOf('Splot\\Framework\\Config\\Config', $config);
     $this->assertEquals('proper value', $config->get('test_setting'));
     $this->assertEquals(true, $config->get('another_setting'));
 }
Exemplo n.º 2
0
 /**
  * Adds a module to the application for testing.
  *
  * The application should be already configured in order to be able to add
  * a test module to it.
  *
  * The module will be configured and ran.
  * 
  * @param AbstractModule $module Module to be added.
  * @param array $config [optional] Module config you may want to pass?
  */
 public function addTestModule(AbstractModule $module, array $config = array())
 {
     // apply the passed config through the application config
     $this->getConfig()->apply(array($module->getName() => $config));
     $this->setPhase(Framework::PHASE_BOOTSTRAP);
     $this->addModule($module);
     $container = $this->getContainer();
     $module->setContainer($container);
     // configure the module
     $this->setPhase(Framework::PHASE_CONFIGURE);
     $framework = new Framework();
     $framework->configureModule($module, $this, $container->getParameter('env'), $container->getParameter('debug'));
     $container->get('router')->readModuleRoutes($module);
     // run the module
     $this->setPhase(Framework::PHASE_RUN);
     $module->run();
 }
Exemplo n.º 3
0
 /**
  * Sets up the application before every test.
  * 
  * If you're overwriting this then be sure to call parent::setUp().
  */
 public function setUp()
 {
     if (!class_exists(static::$applicationClass)) {
         throw new \RuntimeException('Application class "' . static::$applicationClass . '" does not exist. Has it been properly loaded?');
     }
     $appClass = static::$applicationClass;
     $this->application = new $appClass();
     Framework::run($this->application, 'test', true, Framework::MODE_TEST);
 }
Exemplo n.º 4
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Splot\Framework\Framework;
use Application\App;
// detect env based on .tld
$tld = end(explode('.', $_SERVER['SERVER_NAME']));
$env = $tld === 'dev' ? 'dev' : 'prod';
$debug = $env === 'dev' ? true : false;
Framework::run(new App(), $env, $debug);
Exemplo n.º 5
0
 /**
  * Sets up the application before every test.
  * 
  * If you're overwriting this then be sure to call parent::setUp().
  */
 public function setUp()
 {
     $this->application = new TestApplication();
     Framework::run($this->application, 'test', true, Framework::MODE_TEST);
 }
Exemplo n.º 6
0
<?php

use Splot\Framework\Framework;
$rootDir = __DIR__ . '/..';
require_once $rootDir . '/vendor/autoload.php';
require_once $rootDir . '/app/Application.php';
Framework::run(new Application());
Exemplo n.º 7
0
 /**
  * @expectedException \InvalidArgumentException
  * @covers ::modeName
  */
 public function testInvalidModeName()
 {
     Framework::modeName(345);
 }
Exemplo n.º 8
0
 /**
  * Sets the current application phase.
  * 
  * @param int $phase One of `Framework::PHASE_*` constants.
  */
 public function setPhase($phase)
 {
     if ($phase < $this->phase) {
         throw new \RuntimeException('Cannot set an earlier phase than the current application phase, when trying to set "' . Framework::phaseName($phase) . '" (already on "' . Framework::phaseName($this->phase) . '").');
     }
     $this->phase = $phase;
 }