mirror of
https://github.com/chylex/Lightning-Tracker.git
synced 2025-08-10 22:40:41 +02:00
Install Codeception testing framework
This commit is contained in:
parent
d9da7bf038
commit
5f29bba060
.gitignore
.idea
LightningTracker.imlcodeception.xml
README.mdinspectionProfiles
misc.xmlphp-test-framework.xmlrunConfigurations
build
codecept.batcodeception.ymlcomposer.jsoncomposer.locktests
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
||||
/build/node_modules/
|
||||
/out/
|
||||
/server/
|
||||
/vendor/
|
||||
|
@ -3,8 +3,10 @@
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/out" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/server" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
12
.idea/codeception.xml
Normal file
12
.idea/codeception.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Codeception">
|
||||
<option name="configurations">
|
||||
<list>
|
||||
<Configuration>
|
||||
<option name="path" value="$PROJECT_DIR$/tests" />
|
||||
</Configuration>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -406,6 +406,11 @@
|
||||
<option name="EXTENSIONS" value="php,js,css,inc" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PhpClassNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="Tests" level="WARNING" enabled="true">
|
||||
<option name="m_regex" value="[A-Z][A-Za-z\d_]*" />
|
||||
<option name="m_minLength" value="0" />
|
||||
<option name="m_maxLength" value="0" />
|
||||
</scope>
|
||||
<option name="m_minLength" value="0" />
|
||||
<option name="m_maxLength" value="0" />
|
||||
</inspection_tool>
|
||||
@ -432,6 +437,11 @@
|
||||
<inspection_tool class="PhpLoopCanBeConvertedToArrayFilterInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PhpLoopCanBeConvertedToArrayMapInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
<inspection_tool class="PhpMethodNamingConventionInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<scope name="Tests" level="WARNING" enabled="true">
|
||||
<option name="m_regex" value="_?[a-z][A-Za-z\d]*" />
|
||||
<option name="m_minLength" value="0" />
|
||||
<option name="m_maxLength" value="0" />
|
||||
</scope>
|
||||
<option name="m_minLength" value="0" />
|
||||
<option name="m_maxLength" value="0" />
|
||||
</inspection_tool>
|
||||
@ -465,9 +475,15 @@
|
||||
<inspection_tool class="PhpUndefinedClassConstantInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="DOWNGRADE_SEVERITY" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PhpUndefinedClassInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="DONT_REPORT_MULTI_RESOLVE" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PhpUndefinedMethodInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="DOWNGRADE_SEVERITY" value="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PhpUnhandledExceptionInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<scope name="Tests" level="INFORMATION" enabled="true" />
|
||||
</inspection_tool>
|
||||
<inspection_tool class="PhpUnused" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<option name="SHOW_UNUSED_BY_ENTRIES" value="false" />
|
||||
</inspection_tool>
|
||||
|
@ -9,5 +9,12 @@
|
||||
</component>
|
||||
<component name="PhpEntryPointsManager">
|
||||
<pattern value="\Pages\Controllers\*" />
|
||||
<pattern value="\AcceptanceTester" />
|
||||
<pattern value="\FunctionalTester" />
|
||||
<pattern value="\UnitTester" />
|
||||
<pattern value="\acceptance\*" />
|
||||
<pattern value="\acceptance\*" member="*" />
|
||||
<pattern value="\Helper\*" />
|
||||
<pattern value="\Helper\*" member="*" />
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
25
.idea/php-test-framework.xml
Normal file
25
.idea/php-test-framework.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PhpTestFrameworkSettings">
|
||||
<test_tools>
|
||||
<tool tool_name="Codeception">
|
||||
<settings>
|
||||
<configurations>
|
||||
<local_configuration configuration_file_path="$PROJECT_DIR$/codeception.yml" executable_path="$PROJECT_DIR$/vendor/codeception/codeception/codecept" use_configuration_file="true" />
|
||||
</configurations>
|
||||
</settings>
|
||||
</tool>
|
||||
</test_tools>
|
||||
</component>
|
||||
<component name="PhpTestFrameworkVersionCache">
|
||||
<tools_cache>
|
||||
<tool tool_name="Codeception">
|
||||
<cache>
|
||||
<versions>
|
||||
<info id="Local" version="4.1.7" />
|
||||
</versions>
|
||||
</cache>
|
||||
</tool>
|
||||
</tools_cache>
|
||||
</component>
|
||||
</project>
|
18
.idea/runConfigurations/Test.xml
Normal file
18
.idea/runConfigurations/Test.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Test" type="CodeceptionConfigurationType" factoryName="Codeception">
|
||||
<CommandLine workingDirectory="$PROJECT_DIR$" />
|
||||
<PhpTestRunnerSettings method="" scope="ConfigurationFile" options="--fail-fast" />
|
||||
<method v="2">
|
||||
<option name="GulpBeforeRunTask" enabled="true">
|
||||
<node-interpreter>project</node-interpreter>
|
||||
<node-options />
|
||||
<gulpfile>$PROJECT_DIR$/build/gulpfile.js</gulpfile>
|
||||
<tasks>
|
||||
<task>prepareTests</task>
|
||||
</tasks>
|
||||
<arguments />
|
||||
<envs />
|
||||
</option>
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
18
.idea/runConfigurations/Test__Debug_.xml
Normal file
18
.idea/runConfigurations/Test__Debug_.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Test (Debug)" type="CodeceptionConfigurationType" factoryName="Codeception">
|
||||
<CommandLine workingDirectory="$PROJECT_DIR$" />
|
||||
<PhpTestRunnerSettings method="" scope="ConfigurationFile" options="--debug --fail-fast" />
|
||||
<method v="2">
|
||||
<option name="GulpBeforeRunTask" enabled="true">
|
||||
<node-interpreter>project</node-interpreter>
|
||||
<node-options />
|
||||
<gulpfile>$PROJECT_DIR$/build/gulpfile.js</gulpfile>
|
||||
<tasks>
|
||||
<task>prepareTests</task>
|
||||
</tasks>
|
||||
<arguments />
|
||||
<envs />
|
||||
</option>
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
28
README.md
28
README.md
@ -43,3 +43,31 @@ You should be able to install Lightning Tracker on other server software, such a
|
||||
* If the installation page appears without any styles, you may need to edit your Apache settings (or `.htaccess` if you do not have access to the server configuration) to include a path to the tracker installation folder. For example, if you place the tracker into a folder called `tracker`, you may need to change:
|
||||
* This line: `RewriteCond %{REQUEST_URI} !^/~resources/`
|
||||
* To this: `RewriteCond %{REQUEST_URI} !^/tracker/~resources/`
|
||||
|
||||
### Source Code
|
||||
|
||||
#### Test Server
|
||||
|
||||
The project is setup so that `http://localhost` maps to `/server/www/` in the repository root folder. If you use PhpStorm, it should automatically upload modified files to this folder.
|
||||
|
||||
To enable debug mode, which bypasses manual installation, caching, and required minification of resources, copy all files from `/dev/` to `/server/www/`. You will also need a MySQL server with the following credentials:
|
||||
|
||||
* **Host:** `localhost`
|
||||
* **User:** `lt`
|
||||
* **Password:** `test`
|
||||
* **Database:** `tracker`
|
||||
|
||||
#### Automated Testing
|
||||
|
||||
The project uses the [Codeception](https://codeception.com/) test framework. Before you proceed, make sure you have `php`, `composer`, and `gulp` installed in your PATH.
|
||||
|
||||
1. Run `composer install` in the repository root folder to install dependencies
|
||||
2. Setup a web server as outlined in the **Test Server** section above
|
||||
3. Create a MySQL database named `tracker_test` and grant the `lt` user all privileges:
|
||||
* `GRANT ALL PRIVILEGES ON tracker_test.* to 'lt'@'localhost';`
|
||||
4. Run the `gulp prepareTests` task in the `/build/` folder
|
||||
5. Run the tests by running the following command in the repository root folder:
|
||||
* Windows: `codecept run`
|
||||
* (Otherwise): `php vendor/codeception/codeception/codecept run`
|
||||
|
||||
If you use PhpStorm, steps 4 and 5 are included under the provided `Test` run configuration. You may also use the `Test (Debug)` configuration which runs in debug mode.
|
||||
|
@ -9,6 +9,7 @@ const merge = require("merge-stream");
|
||||
|
||||
const crypto = require("crypto");
|
||||
const fs = require("fs");
|
||||
const fse = require("fs-extra");
|
||||
|
||||
const php = "../src";
|
||||
const res = "../res";
|
||||
@ -90,4 +91,22 @@ function taskHash(){
|
||||
.pipe(dest(out));
|
||||
}
|
||||
|
||||
function taskPrepareTests(cb){
|
||||
const www = "../server/www";
|
||||
const backup = "../server/www-backup";
|
||||
|
||||
if (!fs.existsSync(backup)){
|
||||
fs.renameSync(www, backup);
|
||||
}
|
||||
else{
|
||||
fs.rmdirSync(www, { recursive: true, maxRetries: 10 });
|
||||
}
|
||||
|
||||
fs.mkdirSync(www);
|
||||
fse.copySync(out, www);
|
||||
cb();
|
||||
}
|
||||
|
||||
exports.default = series(taskClean, taskCopy, taskCSS, taskHash);
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
exports.prepareTests = series(taskClean, taskCopy, taskCSS, taskHash, taskPrepareTests);
|
||||
|
34
build/package-lock.json
generated
34
build/package-lock.json
generated
@ -283,6 +283,12 @@
|
||||
"async-done": "^1.2.2"
|
||||
}
|
||||
},
|
||||
"at-least-node": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
|
||||
"integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==",
|
||||
"dev": true
|
||||
},
|
||||
"atob": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
|
||||
@ -1354,6 +1360,18 @@
|
||||
"map-cache": "^0.2.2"
|
||||
}
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "9.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.0.1.tgz",
|
||||
"integrity": "sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"at-least-node": "^1.0.0",
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"fs-mkdirp-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-mkdirp-stream/-/fs-mkdirp-stream-1.0.0.tgz",
|
||||
@ -1985,6 +2003,16 @@
|
||||
"integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=",
|
||||
"dev": true
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.0.1.tgz",
|
||||
"integrity": "sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6",
|
||||
"universalify": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"just-debounce": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/just-debounce/-/just-debounce-1.0.0.tgz",
|
||||
@ -3318,6 +3346,12 @@
|
||||
"through2-filter": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"universalify": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-1.0.0.tgz",
|
||||
"integrity": "sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==",
|
||||
"dev": true
|
||||
},
|
||||
"unset-value": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz",
|
||||
|
@ -10,6 +10,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"del": "5.1.0",
|
||||
"fs-extra": "9.0.1",
|
||||
"glob": "7.1.6",
|
||||
"gulp": "4.0.2",
|
||||
"gulp-autoprefixer": "7.0.1",
|
||||
|
1
codecept.bat
Normal file
1
codecept.bat
Normal file
@ -0,0 +1 @@
|
||||
@call php vendor/codeception/codeception/codecept %*
|
10
codeception.yml
Normal file
10
codeception.yml
Normal file
@ -0,0 +1,10 @@
|
||||
paths:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
envs: tests/_envs
|
||||
actor_suffix: Tester
|
||||
extensions:
|
||||
enabled:
|
||||
- Codeception\Extension\RunFailed
|
15
composer.json
Normal file
15
composer.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"require-dev": {
|
||||
"codeception/codeception": "4.1.7",
|
||||
"codeception/module-phpbrowser": "1.0.1",
|
||||
"codeception/module-asserts": "1.3.0",
|
||||
"codeception/module-db": "1.0.1"
|
||||
},
|
||||
"require": {
|
||||
"ext-intl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*",
|
||||
"ext-pdo": "*",
|
||||
"ext-pdo_mysql": "*"
|
||||
}
|
||||
}
|
4140
composer.lock
generated
Normal file
4140
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
0
tests/_data/.gitkeep
Normal file
0
tests/_data/.gitkeep
Normal file
2
tests/_output/.gitignore
vendored
Normal file
2
tests/_output/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
28
tests/_support/AcceptanceTester.php
Normal file
28
tests/_support/AcceptanceTester.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
use Codeception\Actor;
|
||||
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method void pause()
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class AcceptanceTester extends Actor{
|
||||
use _generated\AcceptanceTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
70
tests/_support/Helper/Acceptance.php
Normal file
70
tests/_support/Helper/Acceptance.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Helper;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
|
||||
use Codeception\Module;
|
||||
use Database\DB;
|
||||
use FilesystemIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
class Acceptance extends Module{
|
||||
public function _beforeSuite($settings = []): void{
|
||||
define('DB_DRIVER', 'mysql');
|
||||
define('DB_NAME', 'tracker_test');
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_USER', 'lt');
|
||||
define('DB_PASSWORD', 'test');
|
||||
|
||||
require __DIR__.'/../../../src/Database/DB.php';
|
||||
$db = DB::get();
|
||||
|
||||
$tables = [
|
||||
'system_roles',
|
||||
'system_role_permissions',
|
||||
'users',
|
||||
'user_logins',
|
||||
'projects',
|
||||
'project_roles',
|
||||
'project_role_permissions',
|
||||
'project_members',
|
||||
'milestones',
|
||||
'issue_weights',
|
||||
'issues',
|
||||
'project_user_settings',
|
||||
];
|
||||
|
||||
foreach(array_reverse($tables) as $file => $table){
|
||||
$db->exec('DROP TABLE IF EXISTS '.$table);
|
||||
}
|
||||
}
|
||||
|
||||
public function _afterSuite(): void{
|
||||
$dir_backup = __DIR__.'/../../../server/www-backup';
|
||||
$dir_www = __DIR__.'/../../../server/www';
|
||||
$dir_tmp = $dir_www.'-tmp';
|
||||
|
||||
if (is_dir($dir_backup)){
|
||||
$delete = new RecursiveDirectoryIterator($dir_www, FilesystemIterator::SKIP_DOTS);
|
||||
|
||||
foreach(new RecursiveIteratorIterator($delete, RecursiveIteratorIterator::CHILD_FIRST) as $path){
|
||||
if ($path->isFile()){
|
||||
unlink($path->getPathname());
|
||||
}
|
||||
else{
|
||||
rmdir($path->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
// replacing the folder immediately breaks on Windows for some reason...
|
||||
rename($dir_www, $dir_tmp);
|
||||
rmdir($dir_tmp);
|
||||
|
||||
rename($dir_backup, $dir_www);
|
||||
}
|
||||
}
|
||||
}
|
13
tests/_support/Helper/Unit.php
Normal file
13
tests/_support/Helper/Unit.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Helper;
|
||||
|
||||
// here you can define custom actions
|
||||
// all public methods declared in helper class will be available in $I
|
||||
|
||||
use Codeception\Module;
|
||||
|
||||
class Unit extends Module{
|
||||
|
||||
}
|
28
tests/_support/UnitTester.php
Normal file
28
tests/_support/UnitTester.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
use Codeception\Actor;
|
||||
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void expect($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method void pause()
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends Actor{
|
||||
use _generated\UnitTesterActions;
|
||||
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
2
tests/_support/_generated/.gitignore
vendored
Normal file
2
tests/_support/_generated/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
13
tests/acceptance.suite.yml
Normal file
13
tests/acceptance.suite.yml
Normal file
@ -0,0 +1,13 @@
|
||||
# Codeception Test Suite Configuration
|
||||
#
|
||||
# Suite for acceptance tests.
|
||||
# Perform tests in browser using the WebDriver or PhpBrowser.
|
||||
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
|
||||
|
||||
actor: AcceptanceTester
|
||||
modules:
|
||||
enabled:
|
||||
- PhpBrowser:
|
||||
url: http://localhost/
|
||||
- \Helper\Acceptance
|
||||
step_decorators: ~
|
10
tests/unit.suite.yml
Normal file
10
tests/unit.suite.yml
Normal file
@ -0,0 +1,10 @@
|
||||
# Codeception Test Suite Configuration
|
||||
#
|
||||
# Suite for unit or integration tests.
|
||||
|
||||
actor: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Asserts
|
||||
- \Helper\Unit
|
||||
step_decorators: ~
|
Loading…
Reference in New Issue
Block a user