initial commit
This commit is contained in:
commit
5ebc506921
975 changed files with 154341 additions and 0 deletions
8
tests/phpstan.config.php
Normal file
8
tests/phpstan.config.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
|
||||
if (!defined('\Garradin\WWW_URL')) {
|
||||
define('Garradin\WWW_URL', 'http://localhost/');
|
||||
define('Garradin\WWW_URI', '/');
|
||||
}
|
||||
30
tests/phpstan.neon
Normal file
30
tests/phpstan.neon
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
parameters:
|
||||
bootstrapFiles:
|
||||
- phpstan.config.php
|
||||
- ../src/include/init.php
|
||||
level: 3
|
||||
scanDirectories:
|
||||
- ../src/include
|
||||
- ../src/www
|
||||
- ../src/scripts
|
||||
excludePaths:
|
||||
- ../src/include/lib/KD2
|
||||
- ../src/include/lib/Parsedown.php
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
ignoreErrors:
|
||||
- '#Access to protected property Paheko\\Entities#'
|
||||
- '#Access to an undefined property Paheko\\Entities\\Users\\User#'
|
||||
- '#Access to an undefined property KD2\\DB\\AbstractEntity#'
|
||||
- '#but returns KD2\\DB\\AbstractEntity#'
|
||||
- '#Call to an undefined method KD2\\DB\\AbstractEntity#'
|
||||
- '#Property .* does not accept KD2\\DB\\AbstractEntity#'
|
||||
- '#PHPDoc#'
|
||||
-
|
||||
message: '#Variable \$(tpl|form|session|user|session|wiki|config|user|current_year) might not be defined#'
|
||||
path: ../src/www/*
|
||||
-
|
||||
message: '#Constant CURRENT_YEAR_ID not found#'
|
||||
path: ../src/www/admin/acc/*
|
||||
|
||||
includes:
|
||||
- phar://phpstan.phar/conf/bleedingEdge.neon
|
||||
36
tests/psalm.xml
Normal file
36
tests/psalm.xml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0"?>
|
||||
<psalm autoloader="../src/include/init.php">
|
||||
<projectFiles>
|
||||
<directory name="../src/"/>
|
||||
<ignoreFiles>
|
||||
<directory name="../src/data"/>
|
||||
<directory name="../src/include/lib/KD2"/>
|
||||
<file name="../src/include/lib/Parsedown.php"/>
|
||||
</ignoreFiles>
|
||||
</projectFiles>
|
||||
<issueHandlers>
|
||||
<MissingPropertyType errorLevel="suppress"/>
|
||||
<PossiblyUndefinedVariable errorLevel="suppress"/>
|
||||
<UndefinedVariable errorLevel="suppress"/>
|
||||
<PossiblyUndefinedGlobalVariable>
|
||||
<errorLevel type="suppress">
|
||||
<referencedVariable name="$plugin"/>
|
||||
<referencedVariable name="$tpl"/>
|
||||
<referencedVariable name="$session"/>
|
||||
<referencedVariable name="$form"/>
|
||||
<referencedVariable name="$config"/>
|
||||
<referencedVariable name="$user"/>
|
||||
</errorLevel>
|
||||
</PossiblyUndefinedGlobalVariable>
|
||||
<UndefinedGlobalVariable>
|
||||
<errorLevel type="suppress">
|
||||
<referencedVariable name="$plugin"/>
|
||||
<referencedVariable name="$tpl"/>
|
||||
<referencedVariable name="$session"/>
|
||||
<referencedVariable name="$form"/>
|
||||
<referencedVariable name="$config"/>
|
||||
<referencedVariable name="$user"/>
|
||||
</errorLevel>
|
||||
</UndefinedGlobalVariable>
|
||||
</issueHandlers>
|
||||
</psalm>
|
||||
33
tests/run.php
Normal file
33
tests/run.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
define('Garradin\WWW_URI', '/');
|
||||
define('Garradin\WWW_URL', 'http://localhost/');
|
||||
|
||||
const INIT = __DIR__ . '/../src/include/init.php';
|
||||
|
||||
if (!empty($_SERVER['argv'][1]))
|
||||
{
|
||||
require $_SERVER['argv'][1];
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Lister et exécuter tous les tests unitaires
|
||||
$dir = new RecursiveDirectoryIterator(__DIR__ . '/unit_tests');
|
||||
$iterator = new RecursiveIteratorIterator($dir);
|
||||
|
||||
$files = new RegexIterator($iterator, '/^.*\.php$/i', RecursiveRegexIterator::GET_MATCH);
|
||||
$list = [];
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$list[] = $file[0];
|
||||
}
|
||||
|
||||
natcasesort($list);
|
||||
|
||||
foreach ($list as $file)
|
||||
{
|
||||
require $file;
|
||||
}
|
||||
}
|
||||
91
tests/unit_tests/01_basic/db.php
Normal file
91
tests/unit_tests/01_basic/db.php
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
|
||||
use KD2\Test;
|
||||
|
||||
const DB_FILE = ':memory:';
|
||||
const INSTALL_PROCESS = true;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
$db = DB::getInstance();
|
||||
|
||||
// test exec
|
||||
Test::assert($db->exec('CREATE TABLE test (a, b);'));
|
||||
|
||||
// test insert
|
||||
Test::assert($db->insert('test', ['a' => 1, 'b' => 2]));
|
||||
Test::assert($db->insert('test', ['a' => 3, 'b' => 4]));
|
||||
|
||||
// test insert object
|
||||
Test::assert($db->insert('test', (object) ['a' => 9, 'b' => 10]));
|
||||
|
||||
// test fetch
|
||||
Test::equals((object)['a' => 1, 'b' => 2], $db->first('SELECT a, b FROM test;'));
|
||||
Test::assert(is_object($db->first('SELECT a, b FROM test;')));
|
||||
Test::equals(1, $db->firstColumn('SELECT a, b FROM test;'));
|
||||
Test::equals(3, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// test update
|
||||
Test::assert($db->update('test', ['a' => 5, 'b' => 6], 'a = :a AND b = :b', ['a' => 3, 'b' => 4]));
|
||||
|
||||
// test update with mixed type bindings
|
||||
try {
|
||||
$db->update('test', ['a' => 5, 'b' => 6], 'a = ? AND b = ?', [3, 4]);
|
||||
$failed = false;
|
||||
}
|
||||
catch (\LogicException $e) {
|
||||
$failed = true;
|
||||
}
|
||||
|
||||
Test::assert($failed === true);
|
||||
|
||||
// test if update worked
|
||||
Test::equals((object)['a' => 5, 'b' => 6], $db->first('SELECT a, b FROM test LIMIT 1, 1;'));
|
||||
|
||||
// test delete
|
||||
Test::assert($db->delete('test', 'a = ? AND b = ?', 5, 6));
|
||||
|
||||
// test if delete worked
|
||||
Test::equals(2, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// test insert again
|
||||
Test::assert(is_bool($db->insert('test', ['a' => 3, 'b' => 4])));
|
||||
|
||||
Test::equals(3, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// Test bindings
|
||||
Test::equals(1, $db->firstColumn('SELECT a, b FROM test WHERE a = :a;', ['a' => 1]));
|
||||
Test::equals((object) ['a' => 1, 'b' => 2], $db->first('SELECT a, b FROM test WHERE a = ?;', 1));
|
||||
|
||||
// test SELECT
|
||||
$expected = [(object)['a' => 1, 'b' => 2], (object)['a' => 9, 'b' => 10]];
|
||||
Test::equals($expected, $db->get('SELECT * FROM test LIMIT 2;'));
|
||||
|
||||
$expected = [1 => 2, 9 => 10];
|
||||
Test::equals($expected, $db->getAssoc('SELECT * FROM test LIMIT 2;'));
|
||||
|
||||
$expected = [1 => (object) ['a' => 1, 'b' => 2], 9 => (object) ['a' => 9, 'b' => 10]];
|
||||
Test::equals(json_encode($expected), json_encode($db->getGrouped('SELECT * FROM test LIMIT 2;')));
|
||||
|
||||
// test transactions
|
||||
Test::assert($db->begin());
|
||||
|
||||
Test::assert($db->insert('test', ['a' => 42, 'b' => 43]));
|
||||
|
||||
Test::assert($db->insert('test', ['a' => 44, 'b' => 45]));
|
||||
|
||||
// test rollback
|
||||
Test::assert($db->rollback());
|
||||
|
||||
Test::equals(3, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
|
||||
// test successful commit
|
||||
Test::assert($db->begin());
|
||||
|
||||
Test::assert($db->insert('test', ['a' => 42, 'b' => 43]));
|
||||
|
||||
Test::assert($db->commit());
|
||||
|
||||
Test::equals(4, $db->firstColumn('SELECT COUNT(*) FROM test;'));
|
||||
15
tests/unit_tests/01_basic/paths.php
Normal file
15
tests/unit_tests/01_basic/paths.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use KD2\Test;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
Test::assert(defined('Garradin\ROOT'));
|
||||
Test::assert(is_readable(ROOT));
|
||||
|
||||
Test::assert(defined('Garradin\PLUGINS_ROOT'));
|
||||
|
||||
Test::assert(defined('Garradin\DATA_ROOT'));
|
||||
|
||||
Test::assert(defined('Garradin\CACHE_ROOT'));
|
||||
9
tests/unit_tests/01_basic/version.php
Normal file
9
tests/unit_tests/01_basic/version.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use KD2\Test;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
Test::assert(function_exists('Garradin\paheko_version'));
|
||||
Test::assert(paheko_version());
|
||||
18
tests/unit_tests/02_accounting/money.php
Normal file
18
tests/unit_tests/02_accounting/money.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Garradin;
|
||||
use KD2\Test;
|
||||
|
||||
require_once INIT;
|
||||
|
||||
Test::strictlyEquals(500, Utils::moneyToInteger('5'));
|
||||
Test::strictlyEquals(442, Utils::moneyToInteger('4,42'));
|
||||
Test::strictlyEquals(442, Utils::moneyToInteger('4.42'));
|
||||
Test::strictlyEquals(4, Utils::moneyToInteger('0,04'));
|
||||
Test::strictlyEquals(30, Utils::moneyToInteger('0,3'));
|
||||
Test::strictlyEquals(202034, Utils::moneyToInteger('2020,34'));
|
||||
|
||||
Test::strictlyEquals('5,50', Utils::money_format(550));
|
||||
Test::strictlyEquals('0,05', Utils::money_format(5));
|
||||
Test::strictlyEquals('0,50', Utils::money_format(50));
|
||||
Test::strictlyEquals('1 000,50', Utils::money_format(100050));
|
||||
Loading…
Add table
Add a link
Reference in a new issue