Skip to content

Commit 002a289

Browse files
committed
Add starter testing files.
1 parent 538701e commit 002a289

4 files changed

Lines changed: 98 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ app/tmp/*
55
app/[Cc]onfig/core.php
66
app/[Cc]onfig/database.php
77
!empty
8+
/vendor/*

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@
2020
"source": "https://github.com/loadsys/CakePHP-ConfigReadShell"
2121
},
2222
"require": {
23-
"php": ">=5.4.19",
23+
"php": ">=5.4",
24+
"cakephp/cakephp": "~3.0",
2425
"composer/installers": "~1.0"
2526
},
27+
"require-dev": {
28+
"phpunit/phpunit": "~4.1",
29+
"squizlabs/php_codesniffer": "~2.0",
30+
"satooshi/php-coveralls": "dev-master"
31+
},
2632
"autoload": {
2733
"psr-4": {
2834
"ConfigRead\\": "src"
2935
}
3036
},
3137
"autoload-dev": {
3238
"psr-4": {
33-
"ConfigRead\\Test\\": "tests",
34-
"Cake\\Test\\": "vendor/cakephp/cakephp/test"
39+
"Cake\\Test\\": "vendor/cakephp/cakephp/test",
40+
"ConfigRead\\Test\\": "tests"
3541
}
3642
}
3743
}

phpunit.xml.dist

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
processIsolation="false"
7+
stopOnFailure="false"
8+
syntaxCheck="false"
9+
bootstrap="./tests/bootstrap.php"
10+
>
11+
12+
<testsuites>
13+
<testsuite name="ConfigReadShell Test Suite">
14+
<directory>./tests/TestCase</directory>
15+
</testsuite>
16+
</testsuites>
17+
18+
<!-- Prevent coverage reports from looking in tests and vendors -->
19+
<filter>
20+
<blacklist>
21+
<directory suffix=".php">./vendor/</directory>
22+
<directory suffix=".ctp">./vendor/</directory>
23+
24+
<directory suffix=".php">./tests/</directory>
25+
<directory suffix=".ctp">./tests/</directory>
26+
</blacklist>
27+
</filter>
28+
29+
</phpunit>

tests/bootstrap.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* For full copyright and license information, please see the LICENSE.txt
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11+
* @link http://cakephp.org CakePHP(tm) Project
12+
* @since 0.1.0
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
16+
// @codingStandardsIgnoreFile
17+
18+
use Cake\Core\Configure;
19+
use Cake\Core\Plugin;
20+
use Cake\Datasource\ConnectionManager;
21+
22+
$findRoot = function ($root) {
23+
do {
24+
$lastRoot = $root;
25+
$root = dirname($root);
26+
if (is_dir($root . '/vendor/cakephp/cakephp')) {
27+
return $root;
28+
}
29+
} while ($root !== $lastRoot);
30+
throw new Exception('Cannot find the root of the application, unable to run tests');
31+
};
32+
$root = $findRoot(__FILE__);
33+
unset($findRoot);
34+
chdir($root);
35+
36+
require_once 'vendor/cakephp/cakephp/src/basics.php';
37+
require_once 'vendor/autoload.php';
38+
39+
define('ROOT', $root . DS . 'tests' . DS . 'test_app' . DS);
40+
define('APP', ROOT . 'App' . DS);
41+
define('TMP', sys_get_temp_dir() . DS);
42+
43+
Configure::write('debug', true);
44+
Configure::write('App', [
45+
'namespace' => 'App',
46+
'paths' => [
47+
'plugins' => [ROOT . 'Plugin' . DS],
48+
'templates' => [ROOT . 'App' . DS . 'Template' . DS]
49+
]
50+
]);
51+
52+
if (!getenv('db_dsn')) {
53+
putenv('db_dsn=sqlite:///:memory:');
54+
}
55+
ConnectionManager::config('test', ['url' => getenv('db_dsn')]);
56+
57+
Plugin::load('ConfigReadShell', [
58+
'path' => dirname(dirname(__FILE__)) . DS,
59+
]);

0 commit comments

Comments
 (0)