/**
  * Initializes test environment
  * @param string $moduleName
  * @param array $modulesToBeLoaded (only used if > 1 module to be loaded)
  */
 public static function init($moduleName, $modulesToBeLoaded = NULL)
 {
     // assign module name
     self::$moduleName = $moduleName;
     // load main app config file
     $testConfig = (require __DIR__ . '/config/application.config.php');
     // override 'modules' key
     unset($testConfig['modules']);
     // load other modules (if defined)
     if ($modulesToBeLoaded) {
         foreach ($modulesToBeLoaded as $item) {
             $testConfig['modules'][] = $item;
         }
     } else {
         // just load one module
         $testConfig['modules'] = array(self::$moduleName);
     }
     // load the module and set up test autoloading
     $zf2ModulePaths = array();
     if (isset($testConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $testConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $serviceManager = new ServiceManager(new ServiceManagerConfig());
     $serviceManager->setService('ApplicationConfig', $config);
     $serviceManager->get('ModuleManager')->loadModules();
     $config = $serviceManager->get('Config');
     //var_dump($config); exit;
     static::$serviceManager = $serviceManager;
     static::$config = $config;
 }
Exemple #2
0
 public function testUrl()
 {
     $user = new User();
     $user->username = '******';
     $this->assertEquals(TestBootstrap::app('base_url') . 'users/test', $user->url());
 }
 private function createVolunteerApp()
 {
     $uid = TestBootstrap::app('user')->id();
     if ((new VolunteerApplication($uid))->exists()) {
         return;
     }
     self::$app = new VolunteerApplication();
     self::$app->grantAllPermissions();
     self::$app->create(['uid' => $uid, 'first_name' => 'Test', 'middle_name' => 'meh', 'last_name' => 'User', 'address' => 'abc st', 'city' => 'Tulsa', 'state' => 'OK', 'zip_code' => '74104', 'phone' => '1234567890', 'alternate_phone' => '1234567899', 'birth_date' => strtotime('21 years ago')]);
 }
 /**
  * @depends testCreate
  */
 public function testDelete()
 {
     $user = TestBootstrap::app('user');
     self::$hour->grantAllPermissions();
     $this->assertTrue(self::$hour->delete());
     $user->load();
     $this->assertEquals(6, $user->volunteer_hours);
 }
 public function testGetBogusReport()
 {
     $this->assertFalse(Report::getReport(TestBootstrap::app(), self::$org, 'blah', time() - 3600, time() + 3600));
 }
 /**
  * @depends testCreate
  */
 public function testCreateNonUnique()
 {
     $errorStack = TestBootstrap::app('errors');
     $errorStack->clear();
     $place = new VolunteerPlace();
     $this->assertFalse($place->create(['organization' => self::$org->id(), 'name' => 'Internal', 'address' => '83 West Miller Street, Orlando, FL 32806', 'place_type' => VolunteerPlace::INTERNAL]));
     $errors = $errorStack->errors('VolunteerPlace.create');
     $expected = [['error' => 'place_name_taken', 'message' => 'A volunteer place named Internal already exists. Please use the existing place or choose a different name.', 'context' => 'VolunteerPlace.create', 'params' => ['place_name' => 'Internal']]];
     $this->assertEquals($expected, $errors);
 }
Exemple #7
0
<?php

/*
 *  [ TestBootstrap.php ]
 * 
 *  Filename : engine/Bootstrap.php
 *      Date : 11.04.2012
 * 
 *  Бутстрап для тестов.
 */
define('PATH_APPLICATION', dirname(__FILE__) . '/../application');
define('PATH_ENGINE', dirname(__FILE__));
require_once PATH_ENGINE . '/Bootstrap.php';
class TestBootstrap extends Bootstrap
{
    public function run()
    {
        Application::getInstance()->getRequest()->connectDb('mysqli_test.php');
    }
}
TestBootstrap::getInstance()->autoload()->run();
 /**
  * @depends testCreate
  */
 public function testTopVolunteers()
 {
     $start = mktime(0, 0, 0, 5, 11, 2013);
     $end = mktime(0, 0, 0, 5, 15, 2013);
     $topVolunteers = self::$org->topVolunteers(5, $start, $end);
     $this->assertCount(2, $topVolunteers);
     $this->assertEquals(TestBootstrap::app('user')->id(), $topVolunteers[0]['user']->id());
     $this->assertEquals(15, $topVolunteers[0]['hours']);
     $this->assertEquals(-3, $topVolunteers[1]['user']->id());
     $this->assertEquals(5, $topVolunteers[1]['hours']);
 }
<?php

/**
 * bootstrap.php
 * 
 * Designed to be included in all unit tests for the application
 * NOTE: there is executable code at the top of this file!
 * 
 * @copyright Copyright (c) 2012 Etholutions, LLC. (http://www.ethoultions.net)
 * 
 */
error_reporting(E_ALL | E_STRICT);
chdir(__DIR__);
require __DIR__ . '/../../../tests/TestBootstrap.php';
/**
 * TestBootstrap::init('ModuleName' [, array('Modules','In_Order')])
 */
TestBootstrap::init('Application');