Skip to content

Commit

Permalink
Add path logic to test_app
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlinc committed Aug 2, 2016
1 parent 4979a79 commit 24f1dcd
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
35 changes: 35 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
</php>

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="Search Test Suite">
<directory>./tests/TestCase</directory>
</testsuite>
</testsuites>

<!-- Setup a listener for fixtures -->
<listeners>
<listener class="\Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager"/>
</arguments>
</listener>
</listeners>

<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>
104 changes: 104 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
// @codingStandardsIgnoreFile

use Cake\Routing\Router;
use Croogo\Core\Plugin;

$findVendor = function () {
$root = dirname(dirname(dirname(dirname(dirname(__DIR__)))));
if (is_dir($root . '/vendor/cakephp/cakephp')) {
return $root . DS. 'vendor' . DS;
}
};

if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}

define('VENDOR', $findVendor());

/**
* Configure paths required to find CakePHP + general filepath
* constants
*/
require dirname(dirname(__DIR__)) . DS . 'tests' . DS . 'test_app' . DS . 'config' . DS . '/paths.php';

// Use composer to load the autoloader.
require VENDOR . 'autoload.php';

/**
* Bootstrap CakePHP.
*
* Does the various bits of setup that CakePHP needs to do.
* This includes:
*
* - Registering the CakePHP autoloader.
* - Setting the default application paths.
*/
require CORE_PATH . 'config' . DS . 'bootstrap.php';

Cake\Core\Configure::write('App', [
'namespace' => 'App',
'paths' => [
'plugins' => [ROOT . DS . 'plugins' . DS],
'templates' => [APP . 'Template' . DS],
'locales' => [APP . 'Locale' . DS],
]
]);
Cake\Core\Configure::write('debug', true);

$TMP = new \Cake\Filesystem\Folder(TMP);
$TMP->create(TMP . 'cache/models', 0777);
$TMP->create(TMP . 'cache/persistent', 0777);
$TMP->create(TMP . 'cache/views', 0777);

$cache = [
'default' => [
'engine' => 'File'
],
'_cake_core_' => [
'className' => 'File',
'prefix' => 'croogo_core_myapp_cake_core_',
'path' => CACHE . 'persistent/',
'serialize' => true,
'duration' => '+10 seconds'
],
'_cake_model_' => [
'className' => 'File',
'prefix' => 'croogo_core_my_app_cake_model_',
'path' => CACHE . 'models/',
'serialize' => 'File',
'duration' => '+10 seconds'
]
];

Cake\Cache\Cache::config($cache);
Cake\Core\Configure::write('Session', [
'defaults' => 'php'
]);

// Ensure default test connection is defined
if (!getenv('db_dsn')) {
putenv('db_dsn=sqlite:///:memory:');
}

Cake\Datasource\ConnectionManager::config('test', [
'url' => getenv('db_dsn'),
'timezone' => 'UTC'
]);

$settingsFixture = new \Croogo\Core\Test\Fixture\SettingsFixture();

\Cake\Datasource\ConnectionManager::alias('test', 'default');
$settingsFixture->create(\Cake\Datasource\ConnectionManager::get('default'));
$settingsFixture->insert(\Cake\Datasource\ConnectionManager::get('default'));

Plugin::load('Croogo/Core', ['bootstrap' => true, 'routes' => true]);
Plugin::load('Croogo/Settings', ['bootstrap' => true, 'routes' => true]);

Cake\Routing\DispatcherFactory::add('Routing');
Cake\Routing\DispatcherFactory::add('ControllerFactory');

class_alias('Croogo\Core\TestSuite\TestCase', 'Croogo\Core\TestSuite\CroogoTestCase');

Plugin::routes();

0 comments on commit 24f1dcd

Please sign in to comment.