Skip to content

Commit

Permalink
updating testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
nateiler committed Jun 18, 2018
1 parent cc6d540 commit 512c0a3
Show file tree
Hide file tree
Showing 10 changed files with 1,729 additions and 104 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,5 @@
composer.phar
composer.lock
.DS_Store
.idea
.idea
.env
21 changes: 11 additions & 10 deletions codeception.yml
Expand Up @@ -5,6 +5,8 @@ paths:
support: tests/_support
envs: tests/_envs
actor_suffix: Tester
params:
- .env
settings:
bootstrap: _bootstrap.php
coverage:
Expand All @@ -19,14 +21,13 @@ extensions:
modules:
config:
Yii2:
configFile: 'tests/_config/test.php'
configFile: 'tests/_craft/config/test.php'
enabled:
# - Db:
# dsn: 'mysql:host=127.0.0.1;dbname=%TEST_DB_NAME%;'
# user: '%TEST_DB_USER%'
# password: '%TEST_DB_PASS%'
# dump: 'tests/_data/dump.sql'
# populate: true
# cleanup: true
# reconnect: true

- Db:
dsn: 'mysql:host=%TEST_DB_SERVER%;dbname=%TEST_DB_DATABASE%;'
user: '%TEST_DB_USER%'
password: '%TEST_DB_PASSWORD%'
dump: 'tests/_data/dump.sql'
populate: true
cleanup: true
reconnect: true
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -30,7 +30,8 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.2",
"codeception/codeception": "^2.4"
"codeception/codeception": "^2.4",
"vlucas/phpdotenv": "^2.4"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 15 additions & 0 deletions tests/_bootstrap.php
@@ -0,0 +1,15 @@
<?php

define('CRAFT_ENVIRONMENT', 'test');
define('YII_ENV', 'test');
define('YII_DEBUG', true);

// Set path constants
define('CRAFT_BASE_PATH', __DIR__.'/_craft');
define('CRAFT_STORAGE_PATH', __DIR__.'/_craft/storage');
define('CRAFT_TEMPLATES_PATH', __DIR__.'/_craft/templates');
define('CRAFT_CONFIG_PATH', __DIR__.'/_craft/config');
define('CRAFT_VENDOR_PATH', __DIR__.'/../vendor');

// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH.'/autoload.php';
47 changes: 0 additions & 47 deletions tests/_config/test.php

This file was deleted.

1 change: 1 addition & 0 deletions tests/_craft/.gitignore
@@ -0,0 +1 @@
config/license.key
18 changes: 18 additions & 0 deletions tests/_craft/config/db.php
@@ -0,0 +1,18 @@
<?php

/**
* Database Configuration.
*
* All of your system's database configuration settings go in here.
* You can see a list of the default settings in craft/app/config/defaults/db.php
*/

return [
'*' => [
'tablePrefix' => 'craft',
'server' => getenv('TEST_DB_SERVER'),
'database' => getenv('TEST_DB_DATABASE'),
'user' => getenv('TEST_DB_USER'),
'password' => getenv('TEST_DB_PASSWORD'),
],
];
39 changes: 39 additions & 0 deletions tests/_craft/config/test.php
@@ -0,0 +1,39 @@
<?php

use craft\helpers\ArrayHelper;
use craft\services\Config;

// Paths
$basePath = dirname(__DIR__, 3);
$vendorPath = $basePath . '/vendor';
$craftSrcPath = $vendorPath . '/craftcms/cms/src';
$craftTestPath = dirname(__DIR__);

// The environment variable
$environment = 'TEST';

// Create config service
$configService = new Config(
[
'env' => $environment,
'configDir' => $craftTestPath . '/config',
'appDefaultsDir' => $craftTestPath . '/config/defaults'
]
);

// Set config component
$components = [
'config' => $configService,
];

return ArrayHelper::merge(
[
'vendorPath' => $vendorPath,
'env' => $environment,
'components' => $components,
],
require $craftSrcPath . "/config/app.php",
require $craftSrcPath . "/config/app.web.php",
$configService->getConfigFromFile('app'),
$configService->getConfigFromFile('app.web')
);

0 comments on commit 512c0a3

Please sign in to comment.