mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
test fixes
This commit is contained in:
parent
7fece66ef6
commit
d706b8b320
|
|
@ -39,15 +39,6 @@ final class DatabasePool implements DataStoragePoolInterface
|
|||
*/
|
||||
private array $pool = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Add database.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -125,9 +125,9 @@ class HttpSession implements SessionInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($key, $value, bool $overwrite = true) : bool
|
||||
public function set($key, $value, bool $overwrite = false) : bool
|
||||
{
|
||||
if ($overwrite || !isset($this->sessionData[$key])) {
|
||||
if (!$this->isLocked && ($overwrite || !isset($this->sessionData[$key]))) {
|
||||
$this->sessionData[$key] = $value;
|
||||
|
||||
return true;
|
||||
|
|
@ -180,7 +180,7 @@ class HttpSession implements SessionInterface
|
|||
*/
|
||||
public function remove($key) : bool
|
||||
{
|
||||
if (isset($this->sessionData[$key])) {
|
||||
if (!$this->isLocked && isset($this->sessionData[$key])) {
|
||||
unset($this->sessionData[$key]);
|
||||
|
||||
return true;
|
||||
|
|
@ -215,9 +215,12 @@ class HttpSession implements SessionInterface
|
|||
*/
|
||||
private function destroy() : void
|
||||
{
|
||||
\session_destroy();
|
||||
$this->sessionData = [];
|
||||
\session_start();
|
||||
|
||||
if (\session_status() !== \PHP_SESSION_NONE) {
|
||||
\session_destroy();
|
||||
$this->sessionData = [];
|
||||
\session_start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ interface SessionInterface
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function set($key, $value, bool $overwrite = true) : bool;
|
||||
public function set($key, $value, bool $overwrite = false) : bool;
|
||||
|
||||
/**
|
||||
* Remove value from session by key.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"thousand": ".",
|
||||
"decimal": ",",
|
||||
"angle": "Degree",
|
||||
"angle": "deg",
|
||||
"temperature": "celsius",
|
||||
"weight": {
|
||||
"very_light": "mg",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"thousand": ",",
|
||||
"decimal": ".",
|
||||
"angle": "Degree",
|
||||
"angle": "deg",
|
||||
"temperature": "celsius",
|
||||
"weight": {
|
||||
"very_light": "mg",
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"thousand": ",",
|
||||
"decimal": ".",
|
||||
"angle": "Degree",
|
||||
"angle": "deg",
|
||||
"temperature": "celsius",
|
||||
"weight": {
|
||||
"very_light": "mg",
|
||||
|
|
|
|||
|
|
@ -448,10 +448,16 @@ class Localization
|
|||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InvalidEnumValue This exception is thrown if the angle is invalid
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setAngle(string $angle) : void
|
||||
{
|
||||
if (!AngleType::isValidValue($angle)) {
|
||||
throw new InvalidEnumValue($angle);
|
||||
}
|
||||
|
||||
$this->angle = $angle;
|
||||
}
|
||||
|
||||
|
|
@ -478,6 +484,10 @@ class Localization
|
|||
*/
|
||||
public function setTemperature(string $temperature) : void
|
||||
{
|
||||
if (!TemperatureType::isValidValue($temperature)) {
|
||||
throw new InvalidEnumValue($temperature);
|
||||
}
|
||||
|
||||
$this->temperature = $temperature;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -467,7 +467,7 @@ final class FileLogger implements LoggerInterface
|
|||
/**
|
||||
* Get logging messages from file.
|
||||
*
|
||||
* @param int $limit Amout of perpetrators
|
||||
* @param int $limit Amout of logs
|
||||
* @param int $offset Offset
|
||||
*
|
||||
* @return array
|
||||
|
|
@ -493,25 +493,27 @@ final class FileLogger implements LoggerInterface
|
|||
|
||||
$line = \fgetcsv($this->fp, 0, ';');
|
||||
while ($line !== false && $line !== null) {
|
||||
if ($limit < 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
++$id;
|
||||
|
||||
if ($offset > 0) {
|
||||
$line = \fgetcsv($this->fp, 0, ';');
|
||||
|
||||
--$offset;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($limit <= 0) {
|
||||
\reset($logs);
|
||||
unset($logs[\key($logs)]);
|
||||
}
|
||||
|
||||
foreach ($line as &$value) {
|
||||
$value = \trim($value);
|
||||
}
|
||||
|
||||
$logs[$id] = $line;
|
||||
|
||||
--$limit;
|
||||
\ksort($logs);
|
||||
|
||||
$line = \fgetcsv($this->fp, 0, ';');
|
||||
}
|
||||
|
||||
|
|
@ -554,16 +556,10 @@ final class FileLogger implements LoggerInterface
|
|||
continue;
|
||||
}
|
||||
|
||||
$log['datetime'] = \trim($line[0] ?? '');
|
||||
$log['level'] = \trim($line[1] ?? '');
|
||||
$log['ip'] = \trim($line[2] ?? '');
|
||||
$log['line'] = \trim($line[3] ?? '');
|
||||
$log['version'] = \trim($line[4] ?? '');
|
||||
$log['os'] = \trim($line[5] ?? '');
|
||||
$log['path'] = \trim($line[6] ?? '');
|
||||
$log['message'] = \trim($line[7] ?? '');
|
||||
$log['file'] = \trim($line[8] ?? '');
|
||||
$log['backtrace'] = \trim($line[9] ?? '');
|
||||
foreach ($line as $value) {
|
||||
$log[] = \trim($value);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,8 +135,6 @@ final class CubicSplineInterpolation implements InterpolationInterface
|
|||
$this->solveA->setV($n - 1, 0.0);
|
||||
$this->solveC->setV($n - 1, 3.0 * $this->solveA->getV($n - 2) * $h ** 2 + 2.0 * $this->solveB->get($n - 2) * $h + $this->solveC->getV($n - 2));
|
||||
|
||||
$a = 2;
|
||||
|
||||
/**
|
||||
* @todo: consider linear extrapolation at start and end point
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\Utils\Excel
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Utils\Excel;
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
require_once \realpath(__DIR__ . '/../../../Resources/phpexcel/Classes/PHPExcel.php');
|
||||
|
||||
/**
|
||||
* Excel class.
|
||||
*
|
||||
* @package phpOMS\Utils\Excel
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
* @noinspection PhpUndefinedClassInspection
|
||||
*/
|
||||
class Excel extends \PHPExcel
|
||||
{
|
||||
}
|
||||
|
|
@ -40,7 +40,6 @@ class AStarNodeTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
self::assertFalse($this->node->isClosed());
|
||||
self::assertFalse($this->node->isOpened());
|
||||
self::assertFalse($this->node->isTested());
|
||||
self::assertEquals(0.0, $this->node->getG());
|
||||
self::assertEquals(null, $this->node->getH());
|
||||
self::assertEquals(0.0, $this->node->getF());
|
||||
|
|
@ -66,16 +65,6 @@ class AStarNodeTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertTrue($this->node->isOpened());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The node can be set tested and checked
|
||||
* @covers phpOMS\Algorithm\PathFinding\AStarNode
|
||||
*/
|
||||
public function testTestedInputOutput() : void
|
||||
{
|
||||
$this->node->setTested(true);
|
||||
self::assertTrue($this->node->isTested());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The g value cen be set and returned
|
||||
* @covers phpOMS\Algorithm\PathFinding\AStarNode
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testInvalidDeleteUnexpired() : void
|
||||
{
|
||||
$this->cache->set('key4', 'testVal4', 1);
|
||||
$this->cache->set('key4', 'testVal4', 60);
|
||||
self::assertFalse($this->cache->delete('key4', 0));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,54 +17,99 @@ namespace phpOMS\tests\DataStorage\Cookie;
|
|||
use phpOMS\DataStorage\Cookie\CookieJar;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Cookie\CookieJar: CookieJar to handle http cookies
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CookieJarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected CookieJar $jar;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->jar = new CookieJar();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The cookie jar has the expected default values and functionality after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$jar = new CookieJar();
|
||||
|
||||
self::assertFalse(CookieJar::isLocked());
|
||||
self::assertNull($jar->get('asd'));
|
||||
self::assertFalse($jar->delete('abc'));
|
||||
self::assertNull($this->jar->get('asd'));
|
||||
self::assertFalse($this->jar->delete('abc'));
|
||||
}
|
||||
|
||||
public function testCookie() : void
|
||||
/**
|
||||
* @testdox Cookie values can be set and returned
|
||||
*/
|
||||
public function testCookieInputOutput() : void
|
||||
{
|
||||
$jar = new CookieJar();
|
||||
self::assertTrue($this->jar->set('test', 'value'));
|
||||
self::assertEquals('value', $this->jar->get('test')['value']);
|
||||
|
||||
self::assertTrue($jar->set('test', 'value'));
|
||||
self::assertFalse($jar->set('test', 'value', 86400, '/', null, false, true, false));
|
||||
self::assertTrue($jar->set('test2', 'value2', 86400, '/', null, false, true, false));
|
||||
self::assertTrue($jar->set('test3', 'value3', 86400, '/', null, false, true, false));
|
||||
|
||||
// header already set
|
||||
//self::assertTrue($jar->delete('test2'));
|
||||
//self::assertFalse($jar->delete('test2'));
|
||||
|
||||
self::assertTrue($jar->remove('test2'));
|
||||
self::assertFalse($jar->remove('test2'));
|
||||
self::assertTrue($this->jar->set('test2', 'value2', 86400, '/', null, false, true, false));
|
||||
self::assertEquals('value2', $this->jar->get('test2')['value']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Cookie values cannot be overwritten
|
||||
*/
|
||||
public function testInvalidOverwrite() : void
|
||||
{
|
||||
self::assertTrue($this->jar->set('test', 'value'));
|
||||
self::assertFalse($this->jar->set('test', 'value', 86400, '/', null, false, true, false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Cookie values can be forced to overwrite
|
||||
*/
|
||||
public function testOverwrite() : void
|
||||
{
|
||||
self::assertTrue($this->jar->set('test', 'value'));
|
||||
self::assertTrue($this->jar->set('test', 'value2', 86400, '/', null, false, true, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Cookie values can be removed
|
||||
*/
|
||||
public function testRemove() : void
|
||||
{
|
||||
self::assertTrue($this->jar->set('test', 'value'));
|
||||
self::assertTrue($this->jar->remove('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox None-existing cookie values cannot be removed
|
||||
*/
|
||||
public function testInvalidRemove() : void
|
||||
{
|
||||
self::assertTrue($this->jar->set('test', 'value'));
|
||||
self::assertTrue($this->jar->remove('test'));
|
||||
self::assertFalse($this->jar->remove('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Values cannot be removed from a locked cookie and throws a LockException
|
||||
*/
|
||||
public function testDeleteLocked() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\LockException::class);
|
||||
|
||||
$jar = new CookieJar();
|
||||
self::assertTrue($jar->set('test', 'value'));
|
||||
self::assertTrue($this->jar->set('test', 'value'));
|
||||
|
||||
CookieJar::lock();
|
||||
$jar->delete('test');
|
||||
$this->jar->delete('test');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A locked coockie cannot be saved and throws a LockException
|
||||
*/
|
||||
public function testSaveLocked() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\LockException::class);
|
||||
|
||||
CookieJar::lock();
|
||||
|
||||
$jar = new CookieJar();
|
||||
$jar->save();
|
||||
$this->jar->save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,16 @@ use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
|||
use phpOMS\DataStorage\Database\Connection\SqlServerConnection;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Connection\ConnectionFactory: Database connection factory
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The mysql connection can be successfully created
|
||||
* @covers phpOMS\DataStorage\Database\Connection\ConnectionFactory
|
||||
*/
|
||||
public function testCreateMysql() : void
|
||||
{
|
||||
if (!\extension_loaded('pdo_mysql')) {
|
||||
|
|
@ -41,6 +47,10 @@ class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The postgresql connection can be successfully created
|
||||
* @covers phpOMS\DataStorage\Database\Connection\ConnectionFactory
|
||||
*/
|
||||
public function testCreatePostgres() : void
|
||||
{
|
||||
if (!\extension_loaded('pdo_pgsql')) {
|
||||
|
|
@ -57,6 +67,10 @@ class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The sqlserver connection can be successfully created
|
||||
* @covers phpOMS\DataStorage\Database\Connection\ConnectionFactory
|
||||
*/
|
||||
public function testCreateSqlsrv() : void
|
||||
{
|
||||
if (!\extension_loaded('pdo_sqlsrv')) {
|
||||
|
|
@ -73,6 +87,10 @@ class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The sqlite connection can be successfully created
|
||||
* @covers phpOMS\DataStorage\Database\Connection\ConnectionFactory
|
||||
*/
|
||||
public function testCreateSqlite() : void
|
||||
{
|
||||
if (!\extension_loaded('pdo_sqlite')) {
|
||||
|
|
@ -89,6 +107,10 @@ class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid database type throws a InvalidArgumentException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\ConnectionFactory
|
||||
*/
|
||||
public function testInvalidDatabaseType() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ use phpOMS\DataStorage\Database\Connection\MysqlConnection;
|
|||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Connection\MysqlConnectionTest: Mysql connection
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -31,6 +33,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Valid mysql connection data result in a valid database connection
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testConnect() : void
|
||||
{
|
||||
$mysql = new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin']);
|
||||
|
|
@ -42,6 +48,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar', $mysql->getGrammar());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database type throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidDatabaseType() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -52,6 +62,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$mysql = new MysqlConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database host throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidHost() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -62,6 +76,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$mysql = new MysqlConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database port throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidPort() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -72,6 +90,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$mysql = new MysqlConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidDatabase() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -82,6 +104,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$mysql = new MysqlConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database login throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidLogin() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -92,6 +118,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$mysql = new MysqlConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database password throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidPassword() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -102,6 +132,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$mysql = new MysqlConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid database type throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidDatabaseTypeName() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -112,6 +146,10 @@ class MysqlConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$mysql = new MysqlConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid database throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\MysqlConnection
|
||||
*/
|
||||
public function testInvalidDatabaseName() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ use phpOMS\DataStorage\Database\Connection\PostgresConnection;
|
|||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Connection\PostgresConnection: Postgresql connection
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -30,6 +32,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Valid postgresql connection data result in a valid database connection
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testConnect() : void
|
||||
{
|
||||
$psql = new PostgresConnection($GLOBALS['CONFIG']['db']['core']['postgresql']['admin']);
|
||||
|
|
@ -40,6 +46,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\PostgresGrammar', $psql->getGrammar());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database type throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testInvalidDatabaseType() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -49,6 +59,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$psql = new PostgresConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database host throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testInvalidHost() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -58,6 +72,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$psql = new PostgresConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database port throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testInvalidPort() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -67,6 +85,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$psql = new PostgresConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testInvalidDatabase() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -76,6 +98,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$psql = new PostgresConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database login throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testInvalidLogin() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -85,6 +111,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$psql = new PostgresConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database password throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testInvalidPassword() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -94,6 +124,10 @@ class PostgresConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$psql = new PostgresConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid database type throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\PostgresConnection
|
||||
*/
|
||||
public function testInvalidDatabaseTypeName() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ use phpOMS\DataStorage\Database\Connection\SQLiteConnection;
|
|||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Connection\SQLiteConnectionTest: SQLite connection
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SQLiteConnectionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -30,6 +32,10 @@ class SQLiteConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Valid sqlite connection data result in a valid database connection
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SQLiteConnection
|
||||
*/
|
||||
public function testConnect() : void
|
||||
{
|
||||
$sqlite = new SQLiteConnection($GLOBALS['CONFIG']['db']['core']['sqlite']['admin']);
|
||||
|
|
@ -38,6 +44,10 @@ class SQLiteConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\SQLiteGrammar', $sqlite->getGrammar());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database type throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SQLiteConnection
|
||||
*/
|
||||
public function testInvalidDatabaseType() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -47,6 +57,10 @@ class SQLiteConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$sqlite = new SQLiteConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SQLiteConnection
|
||||
*/
|
||||
public function testInvalidDatabase() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ use phpOMS\DataStorage\Database\Connection\SqlServerConnection;
|
|||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Connection\SqlServerConnectionTest: Sqlserver connection
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -31,6 +33,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Valid sqlserver connection data result in a valid database connection
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testConnect() : void
|
||||
{
|
||||
$ssql = new SqlServerConnection($GLOBALS['CONFIG']['db']['core']['mssql']['admin']);
|
||||
|
|
@ -41,6 +47,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\SqlServerGrammar', $ssql->getGrammar());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database type throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidDatabaseType() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -50,6 +60,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$ssql = new SqlServerConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database host throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidHost() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -59,6 +73,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$ssql = new SqlServerConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database port throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidPort() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -68,6 +86,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$ssql = new SqlServerConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidDatabase() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -77,6 +99,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$ssql = new SqlServerConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database login throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidLogin() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -86,6 +112,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$ssql = new SqlServerConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A missing database password throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidPassword() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -95,6 +125,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$ssql = new SqlServerConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid database type throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidDatabaseTypeName() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
@ -104,6 +138,10 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
|||
$ssql = new SqlServerConnection($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid database throws a InvalidConnectionConfigException
|
||||
* @covers phpOMS\DataStorage\Database\Connection\SqlServerConnection
|
||||
*/
|
||||
public function testInvalidDatabaseName() : void
|
||||
{
|
||||
self::expectException(\phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException::class);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ use phpOMS\tests\DataStorage\Database\TestModel\BaseModelMapper;
|
|||
use phpOMS\tests\DataStorage\Database\TestModel\ManyToManyDirectModelMapper;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\DataMapperAbstract: Datamapper for database models
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -148,6 +150,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper has the expected default values after initialization
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testDefault() : void
|
||||
|
|
@ -158,6 +161,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper sucessfully creates a database entry of a model
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testCreate() : void
|
||||
|
|
@ -167,6 +171,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper sucessfully creates a database entry of array data
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testCreateArray() : void
|
||||
|
|
@ -176,6 +181,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper sucessfully returns a database entry as model
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testRead() : void
|
||||
|
|
@ -211,6 +217,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper sucessfully returns a database entry as array
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testReadArray() : void
|
||||
|
|
@ -241,6 +248,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper sucessfully updates a database entry from a model
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testUpdate() : void
|
||||
|
|
@ -271,6 +279,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper sucessfully updates a database entry from an array
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testUpdateArray() : void
|
||||
|
|
@ -301,6 +310,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @testdox The datamapper sucessfully deletes a database entry from a model
|
||||
* @covers phpOMS\DataStorage\Database\DataMapperAbstract
|
||||
*/
|
||||
public function testDelete() : void
|
||||
|
|
|
|||
|
|
@ -19,37 +19,86 @@ use phpOMS\DataStorage\Database\DatabasePool;
|
|||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\DatabasePool: Pool for database connections
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DatabasePoolTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testBasicConnection() : void
|
||||
{
|
||||
$dbPool = new DatabasePool();
|
||||
/** @var array $CONFIG */
|
||||
$dbPool->create('core', $GLOBALS['CONFIG']['db']['core']['masters']['admin']);
|
||||
protected DatabasePool $dbPool;
|
||||
|
||||
self::assertEquals($dbPool->get()->getStatus(), DatabaseStatus::OK);
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->dbPool = new DatabasePool();
|
||||
}
|
||||
|
||||
public function testGetSet() : void
|
||||
/**
|
||||
* @testdox The pool has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\NullConnection', $this->dbPool->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A database connection can be created by the pool
|
||||
*/
|
||||
public function testCreateConnection() : void
|
||||
{
|
||||
$dbPool = new DatabasePool();
|
||||
/** @var array $CONFIG */
|
||||
self::assertTrue($this->dbPool->create('core', $GLOBALS['CONFIG']['db']['core']['masters']['admin']));
|
||||
self::assertEquals($this->dbPool->get()->getStatus(), DatabaseStatus::OK);
|
||||
}
|
||||
|
||||
self::assertTrue($dbPool->create('core', $GLOBALS['CONFIG']['db']['core']['masters']['admin']));
|
||||
self::assertFalse($dbPool->create('core', $GLOBALS['CONFIG']['db']['core']['masters']['admin']));
|
||||
/**
|
||||
* @testdox Database connections cannot be overwritten
|
||||
*/
|
||||
public function testInvalidOverwrite() : void
|
||||
{
|
||||
/** @var array $CONFIG */
|
||||
self::assertTrue($this->dbPool->create('core', $GLOBALS['CONFIG']['db']['core']['masters']['admin']));
|
||||
self::assertFalse($this->dbPool->create('core', $GLOBALS['CONFIG']['db']['core']['masters']['admin']));
|
||||
self::assertFalse($this->dbPool->add('core', new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])));
|
||||
}
|
||||
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\ConnectionAbstract', $dbPool->get());
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\NullConnection', $dbPool->get('doesNotExist'));
|
||||
self::assertEquals($dbPool->get('core'), $dbPool->get());
|
||||
/**
|
||||
* @testdox Existing database connections can be added to the pool
|
||||
*/
|
||||
public function testAddConnections() : void
|
||||
{
|
||||
/** @var array $CONFIG */
|
||||
self::assertTrue($this->dbPool->add('core', new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])));
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\ConnectionAbstract', $this->dbPool->get());
|
||||
}
|
||||
|
||||
self::assertFalse($dbPool->remove('cores'));
|
||||
self::assertTrue($dbPool->remove('core'));
|
||||
/**
|
||||
* @testdox Database connections can be removed from the pool
|
||||
*/
|
||||
public function testRemoveConnections() : void
|
||||
{
|
||||
/** @var array $CONFIG */
|
||||
self::assertTrue($this->dbPool->add('core', new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])));
|
||||
self::assertTrue($this->dbPool->remove('core'));
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\NullConnection', $this->dbPool->get());
|
||||
}
|
||||
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Connection\NullConnection', $dbPool->get());
|
||||
/**
|
||||
* @testdox Invalid database connections cannot be removed
|
||||
*/
|
||||
public function testInvalidRemove() : void
|
||||
{
|
||||
/** @var array $CONFIG */
|
||||
self::assertTrue($this->dbPool->add('core', new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])));
|
||||
self::assertFalse($this->dbPool->remove('cores'));
|
||||
}
|
||||
|
||||
self::assertTrue($dbPool->add('core', new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])));
|
||||
self::assertFalse($dbPool->add('core', new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])));
|
||||
/**
|
||||
* @testdox The first connection added to the pool is the default connection
|
||||
*/
|
||||
public function testDefaultConnection() : void
|
||||
{
|
||||
/** @var array $CONFIG */
|
||||
self::assertTrue($this->dbPool->add('abc', new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin'])));
|
||||
self::assertEquals($this->dbPool->get('abc'), $this->dbPool->get());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ use phpOMS\DataStorage\Database\Connection\MysqlConnection;
|
|||
use phpOMS\DataStorage\Database\Query\Builder;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Query\BuilderTest: Query builder for sql queries
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BuilderTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -29,6 +31,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$this->con = new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql selects form a valid query
|
||||
*/
|
||||
public function testMysqlSelect() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -84,6 +89,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($query->toSql(), $query->__toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql orders form a valid query
|
||||
*/
|
||||
public function testMysqlOrder() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -111,6 +119,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->orderBy(['a.test', 'a.test2'], 'ASC')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql offsets and limits form a valid query
|
||||
*/
|
||||
public function testMysqlOffsetLimit() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -122,6 +133,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', 1)->offset(3)->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql groupings form a valid query
|
||||
*/
|
||||
public function testMysqlGroup() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -140,6 +154,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', ':test')->groupBy('a', 'b')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql wheres form a valid query
|
||||
*/
|
||||
public function testMysqlWheres() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -199,6 +216,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->select('a.test')->from('a')->where('a.test', '=', ':testWhere')->whereIn('a.test2', ['a', ':bValue', 'c'], 'or')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql joins form a valid query
|
||||
*/
|
||||
public function testMysqlJoins() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -258,6 +278,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->select('a.test')->from('a')->fullOuterJoin('b')->on('a.id', '=', 'b.id')->where('a.test', '=', 1)->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql inserts form a valid query
|
||||
*/
|
||||
public function testMysqlInsert() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -282,6 +305,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->insert('test', 'test2')->into('a')->values(':test', ':test2')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql deletes form a valid query
|
||||
*/
|
||||
public function testMysqlDelete() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -293,6 +319,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->delete()->from('a')->where('a.test', '=', ':testVal')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql updates form a valid query
|
||||
*/
|
||||
public function testMysqlUpdate() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -308,12 +337,18 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->update('a')->set(['a.test' => 1])->set(['a.test2' => ':test2'])->where('a.test', '=', ':test3')->toSql());
|
||||
}
|
||||
|
||||
public function testRaw() : void
|
||||
/**
|
||||
* @testdox Raw queries get output as defined
|
||||
*/
|
||||
public function testRawInputOutput() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
self::assertEquals('SELECT test.val FROM test;', $query->raw('SELECT test.val FROM test;')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Read only queries don't allow drops
|
||||
*/
|
||||
public function testReadOnlyRaw() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
|
@ -322,6 +357,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->raw('DROP DATABASE oms;');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Read only queries don't allow inserts
|
||||
*/
|
||||
public function testReadOnlyInsert() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
|
@ -330,6 +368,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->insert('test');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Read only queries don't allow updates
|
||||
*/
|
||||
public function testReadOnlyUpdate() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
|
@ -338,6 +379,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Read only queries don't allow deletes
|
||||
*/
|
||||
public function testReadOnlyDelete() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
|
@ -346,6 +390,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid select types throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidSelectParameter() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
|
@ -354,6 +401,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->select(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid from types throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidFromParameter() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
|
@ -362,6 +412,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->from(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid group types throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidGroupByParameter() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
|
@ -370,6 +423,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->groupBy(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid where operators throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidWhereOperator() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
|
@ -378,6 +434,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->where('a', 'invalid', 'b');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid join types throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidJoinTable() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
|
@ -386,6 +445,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->join(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid join operators throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidJoinOperator() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
|
@ -394,7 +456,10 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->join('b')->on('a', 'invalid', 'b');
|
||||
}
|
||||
|
||||
public function testInvalidOrOrderType() : void
|
||||
/**
|
||||
* @testdox Invalid order types throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidOrderType() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
||||
|
|
@ -402,7 +467,10 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$query->orderBy('a', 1);
|
||||
}
|
||||
|
||||
public function testInvalidOrColumnType() : void
|
||||
/**
|
||||
* @testdox Invalid order column types throw a InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidOrderColumnType() : void
|
||||
{
|
||||
self::expectException(\InvalidArgumentException::class);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,16 +17,29 @@ namespace phpOMS\tests\DataStorage\Database\Query\Grammar;
|
|||
use phpOMS\DataStorage\Database\Query\Grammar\Grammar;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Query\GrammarTest: Basic sql query grammar
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class GrammarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @testdox The grammar has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$grammar = new Grammar();
|
||||
self::assertEquals('Y-m-d H:i:s', $grammar->getDateFormat());
|
||||
self::assertEquals('', $grammar->getTablePrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The grammar can define a default table prefix and return this value
|
||||
*/
|
||||
public function testPrefixInputOutput() : void
|
||||
{
|
||||
$grammar = new Grammar();
|
||||
$grammar->setTablePrefix('oms_');
|
||||
self::assertEquals('oms_', $grammar->getTablePrefix());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,16 @@ use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
|
|||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Query\MysqlGrammarTest: Mysql sql query grammar
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class MysqlGrammarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @testdox The grammar has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\Grammar', new MysqlGrammar());
|
||||
|
|
|
|||
|
|
@ -18,10 +18,15 @@ use phpOMS\DataStorage\Database\Query\Grammar\SQLiteGrammar;
|
|||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Query\SQLiteGrammarTest: SQLite sql query grammar
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SQLiteGrammarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The grammar has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\Grammar', new SqliteGrammar());
|
||||
|
|
|
|||
|
|
@ -18,17 +18,22 @@ use phpOMS\DataStorage\Database\Connection\MysqlConnection;
|
|||
use phpOMS\DataStorage\Database\Schema\Builder;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Schema\BuilderTest: Query builder for sql schemas
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class BuilderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $con = null;
|
||||
protected MysqlConnection $con;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->con = new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql drops form a valid query
|
||||
*/
|
||||
public function testMysqlDrop() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -36,6 +41,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->dropDatabase('test')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql show tables form a valid query
|
||||
*/
|
||||
public function testMysqlShowTables() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -43,6 +51,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->selectTables()->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql show fields form a valid query
|
||||
*/
|
||||
public function testMysqlShowFields() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
@ -50,6 +61,9 @@ class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals($sql, $query->selectFields('test')->toSql());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Mysql create tables form a valid query
|
||||
*/
|
||||
public function testMysqlCreateTable() : void
|
||||
{
|
||||
$query = new Builder($this->con);
|
||||
|
|
|
|||
|
|
@ -17,16 +17,28 @@ namespace phpOMS\tests\DataStorage\Database\Schema\Grammar;
|
|||
use phpOMS\DataStorage\Database\Schema\Grammar\Grammar;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Schema\GrammarTest: Basic sql query grammar
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class GrammarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The grammar has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$grammar = new Grammar();
|
||||
self::assertEquals('Y-m-d H:i:s', $grammar->getDateFormat());
|
||||
self::assertEquals('', $grammar->getTablePrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The grammar can define a default table prefix and return this value
|
||||
*/
|
||||
public function testPrefixInputOutput() : void
|
||||
{
|
||||
$grammar = new Grammar();
|
||||
$grammar->setTablePrefix('oms_');
|
||||
self::assertEquals('oms_', $grammar->getTablePrefix());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,24 +21,34 @@ use phpOMS\Utils\ArrayUtils;
|
|||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Schema\Grammar\MysqlGrammarTest: Mysql sql schema grammar
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class MysqlGrammarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $con = null;
|
||||
protected MysqlConnection $con;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->con = new MysqlConnection($GLOBALS['CONFIG']['db']['core']['masters']['admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The grammar has the expected default values after initialization
|
||||
* @covers phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar<extended>
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Schema\Grammar\Grammar', new MysqlGrammar());
|
||||
self::assertEquals('`', TestUtils::getMember(new MysqlGrammar(), 'systemIdentifier'));
|
||||
}
|
||||
|
||||
public function testSchemaCreateReadDelete() : void
|
||||
/**
|
||||
* @testdox The the grammar correctly creates and returns a database table
|
||||
* @covers phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar<extended>
|
||||
*/
|
||||
public function testSchemaInputOutput() : void
|
||||
{
|
||||
$definitions = \json_decode(\file_get_contents(__DIR__ . '/testSchema.json'), true);
|
||||
foreach ($definitions as $definition) {
|
||||
|
|
@ -59,6 +69,16 @@ class MysqlGrammarTest extends \PHPUnit\Framework\TestCase
|
|||
'Couldn\'t find "' . $key . '" in array'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The grammar correctly deletes a table
|
||||
* @covers phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar<extended>
|
||||
*/
|
||||
public function testDelete() : void
|
||||
{
|
||||
$table = new SchemaBuilder($this->con);
|
||||
$tables = $table->prefix($this->con->prefix)->selectTables()->execute()->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
$delete = new SchemaBuilder($this->con);
|
||||
$delete->prefix($this->con->prefix)->dropTable('test')->execute();
|
||||
|
|
|
|||
|
|
@ -17,10 +17,15 @@ use phpOMS\DataStorage\Database\Schema\Grammar\SQLiteGrammar;
|
|||
use phpOMS\Utils\TestUtils;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Database\Schema\Grammar\SQLiteGrammarTest: SQLite sql schema grammar
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class SQLiteGrammarTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The grammar has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Schema\Grammar\Grammar', new SQLiteGrammar());
|
||||
|
|
|
|||
|
|
@ -17,10 +17,15 @@ namespace phpOMS\tests\DataStorage\Session;
|
|||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\DataStorage\Session\HttpSessionTest: Session data handler for http sessions
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class HttpSessionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The session has the expected default values after initialization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$session = new HttpSession();
|
||||
|
|
@ -28,25 +33,101 @@ class HttpSessionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertFalse($session->isLocked());
|
||||
}
|
||||
|
||||
public function testGetSet() : void
|
||||
/**
|
||||
* @testdox Session data can be set and returned
|
||||
*/
|
||||
public function testInputOutput() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
self::assertTrue($session->set('test', 'value'));
|
||||
self::assertEquals('value', $session->get('test'));
|
||||
}
|
||||
|
||||
self::assertFalse($session->set('test', 'value2', false));
|
||||
/**
|
||||
* @testdox Session data cannot be overwritten
|
||||
*/
|
||||
public function testInvalidOverwrite() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
$session->set('test', 'value');
|
||||
self::assertFalse($session->set('test', 'value2'));
|
||||
self::assertEquals('value', $session->get('test'));
|
||||
}
|
||||
|
||||
self::assertTrue($session->set('test', 'value3'));
|
||||
self::assertEquals('value3', $session->get('test'));
|
||||
/**
|
||||
* @testdox Session data can be forced to overwrite
|
||||
*/
|
||||
public function testOverwrite() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
$session->set('test', 'value');
|
||||
self::assertTrue($session->set('test', 'value2', true));
|
||||
self::assertEquals('value2', $session->get('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Session data can be removed
|
||||
*/
|
||||
public function testRemove() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
$session->set('test', 'value');
|
||||
self::assertTrue($session->remove('test'));
|
||||
self::assertFalse($session->remove('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox None-existing session data cannot be removed
|
||||
*/
|
||||
public function testInvalidRemove() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
$session->set('test', 'value');
|
||||
$session->remove('test');
|
||||
|
||||
self::assertFalse($session->remove('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A session id can be set and returned
|
||||
*/
|
||||
public function testSessionIdInputOutput() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
$session->setSID('abc');
|
||||
self::assertEquals('abc', $session->getSID());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A session can be locked
|
||||
*/
|
||||
public function testLockInputOutput() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
|
||||
$session->lock();
|
||||
self::assertTrue($session->isLocked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A locked session cannot add or change data
|
||||
*/
|
||||
public function testLockInvalidSet() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
|
||||
$session->lock();
|
||||
self::assertFalse($session->set('test', 'value'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A locked session cannot remove data
|
||||
*/
|
||||
public function testLockInvalidRemove() : void
|
||||
{
|
||||
$session = new HttpSession(1, false, 1);
|
||||
|
||||
self::assertTrue($session->set('test', 'value'));
|
||||
$session->lock();
|
||||
self::assertFalse($session->remove('test'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ use phpOMS\Uri\Http;
|
|||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Dispatcher\DispatcherTest: Dispatcher for executing request endpoints
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DispatcherTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -38,11 +40,19 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
$this->app->dispatcher = new Dispatcher($this->app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The dispatcher has the expected member variables
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testAttributes() : void
|
||||
{
|
||||
self::assertObjectHasAttribute('controllers', $this->app->dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The disptacher can dispatch a function/closure
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testClosure() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
|
|
@ -66,6 +76,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The disptacher can dispatch a method as string representation of a controller
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testPathMethod() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
|
|
@ -81,6 +95,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The disptacher can dispatch a method as array representation of a controller
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testPathMethodInArray() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
|
|
@ -104,6 +122,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The disptacher can dispatch a static method as string representation
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testPathStatic() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
|
|
@ -119,6 +141,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The disptacher can dispatch multiple destinations after another
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testArray() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
|
|
@ -138,6 +164,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid destination type throws UnexpectedValueException
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testInvalidDestination() : void
|
||||
{
|
||||
self::expectException(\UnexpectedValueException::class);
|
||||
|
|
@ -145,6 +175,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
$this->app->dispatcher->dispatch(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid controller path thorws a PathException
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testInvalidControllerPath() : void
|
||||
{
|
||||
self::expectException(\phpOMS\System\File\PathException::class);
|
||||
|
|
@ -152,6 +186,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
$this->app->dispatcher->dispatch('phpOMS\tests\Dispatcher\TestControllers::testFunctionStatic');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid function path thorws a Exception
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testInvalidControllerFunction() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
|
@ -159,6 +197,10 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
|
|||
$this->app->dispatcher->dispatch('phpOMS\tests\Dispatcher\TestController::testFunctionStaticINVALID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A malformed dispatch path thorws UnexpectedValueException
|
||||
* @covers phpOMS\Dispatcher\Dispatcher
|
||||
*/
|
||||
public function testInvalidControllerString() : void
|
||||
{
|
||||
self::expectException(\UnexpectedValueException::class);
|
||||
|
|
|
|||
|
|
@ -19,96 +19,188 @@ require_once __DIR__ . '/../Autoloader.php';
|
|||
use phpOMS\Event\EventManager;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Event\EventManager: Event manager for managing and executing events
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class EventManagerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected EventManager $event;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->event = new EventManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The event manager has the expected member variables
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testAttributes() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
|
||||
self::assertObjectHasAttribute('groups', $event);
|
||||
self::assertObjectHasAttribute('callbacks', $event);
|
||||
self::assertObjectHasAttribute('groups', $this->event);
|
||||
self::assertObjectHasAttribute('callbacks', $this->event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The event manager has the expected default values after initialization
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
|
||||
self::assertEquals(0, $event->count());
|
||||
self::assertFalse($event->trigger('invalid'));
|
||||
self::assertEquals(0, $this->event->count());
|
||||
}
|
||||
|
||||
public function testBase() : void
|
||||
/**
|
||||
* @testdox New events can be added
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testAdd() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
|
||||
self::assertTrue($event->attach('group', function() { return true; }, false, false));
|
||||
self::assertTrue($event->attach('group', function() { return true; }, false, false));
|
||||
self::assertEquals(1, $event->count());
|
||||
self::assertTrue($this->event->attach('group', function() { return true; }, false, false));
|
||||
self::assertEquals(1, $this->event->count());
|
||||
}
|
||||
|
||||
public function testDefaultDispatchOfPath() : void
|
||||
/**
|
||||
* @testdox Multiple callbacks can be added to an event
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testAddMultiple() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
|
||||
self::assertTrue($event->attach('group', 'path_to_execute', false, true));
|
||||
$event->addGroup('group', 'id1');
|
||||
$event->addGroup('group', 'id2');
|
||||
|
||||
$event->trigger('group', 'id1');
|
||||
self::assertTrue($event->trigger('group', 'id2'));
|
||||
self::assertTrue($this->event->attach('group', function() { return true; }, false, false));
|
||||
self::assertTrue($this->event->attach('group', function() { return true; }, false, false));
|
||||
self::assertEquals(1, $this->event->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An event gets executed if all conditions and sub conditions are met
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testDispatchAfterAllConditions() : void
|
||||
{
|
||||
$this->event->attach('group', 'path_to_execute', false, true);
|
||||
$this->event->addGroup('group', 'id1');
|
||||
$this->event->addGroup('group', 'id2');
|
||||
|
||||
$this->event->trigger('group', 'id1');
|
||||
self::assertTrue($this->event->trigger('group', 'id2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An event doesn't get executed if not all conditions and sub conditions are met
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testDispatchAfterSomeConditionsInvalid() : void
|
||||
{
|
||||
$this->event->attach('group', 'path_to_execute', false, true);
|
||||
$this->event->addGroup('group', 'id1');
|
||||
$this->event->addGroup('group', 'id2');
|
||||
|
||||
self::assertFalse($this->event->trigger('group', 'id1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox None-existing events cannot be executed/triggered
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testInvalidEventTrigger() : void
|
||||
{
|
||||
self::assertFalse($this->event->trigger('invalid'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An event can be defined to reset after all conditions and subconditions are met. Then all conditions and sub conditions must be met again before it gets triggered again.
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testReset() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
self::assertTrue($this->event->attach('group', function() { return true; }, false, true));
|
||||
$this->event->addGroup('group', 'id1');
|
||||
$this->event->addGroup('group', 'id2');
|
||||
|
||||
self::assertTrue($event->attach('group', function() { return true; }, false, true));
|
||||
$event->addGroup('group', 'id1');
|
||||
$event->addGroup('group', 'id2');
|
||||
|
||||
self::assertFalse($event->trigger('group', 'id1'));
|
||||
self::assertTrue($event->trigger('group', 'id2'));
|
||||
self::assertFalse($event->trigger('group', 'id2'));
|
||||
self::assertEquals(1, $event->count());
|
||||
self::assertFalse($this->event->trigger('group', 'id1'));
|
||||
self::assertTrue($this->event->trigger('group', 'id2'));
|
||||
self::assertFalse($this->event->trigger('group', 'id2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An event can be defined to not reset after all conditions and subconditions are met. Then an event can be triggered any time.
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testNoeReset() : void
|
||||
{
|
||||
self::assertTrue($this->event->attach('group', function() { return true; }, false, false));
|
||||
$this->event->addGroup('group', 'id1');
|
||||
$this->event->addGroup('group', 'id2');
|
||||
|
||||
self::assertFalse($this->event->trigger('group', 'id1'));
|
||||
self::assertTrue($this->event->trigger('group', 'id2'));
|
||||
self::assertTrue($this->event->trigger('group', 'id2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An event can be manually removed/detatched
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testDetach() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
$this->event->attach('group', function() { return true; }, false, true);
|
||||
$this->event->addGroup('group', 'id1');
|
||||
$this->event->addGroup('group', 'id2');
|
||||
|
||||
self::assertTrue($event->attach('group', function() { return true; }, false, true));
|
||||
$event->addGroup('group', 'id1');
|
||||
$event->addGroup('group', 'id2');
|
||||
|
||||
self::assertEquals(1, $event->count());
|
||||
self::assertTrue($event->detach('group'));
|
||||
self::assertEquals(0, $event->count());
|
||||
self::assertFalse($event->trigger('group'));
|
||||
|
||||
self::assertFalse($event->detach('group'));
|
||||
self::assertEquals(1, $this->event->count());
|
||||
self::assertTrue($this->event->detach('group'));
|
||||
self::assertEquals(0, $this->event->count());
|
||||
self::assertFalse($this->event->trigger('group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox None-existing events cannot be manually removed/detatched
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testInvalidDetach() : void
|
||||
{
|
||||
$this->event->attach('group', function() { return true; }, false, true);
|
||||
$this->event->addGroup('group', 'id1');
|
||||
$this->event->addGroup('group', 'id2');
|
||||
|
||||
$this->event->detach('group');
|
||||
self::assertFalse($this->event->detach('group'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An event can be defined to automatically remove itself after all conditions and subconditions are met and it is executed
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testRemove() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
self::assertTrue($this->event->attach('group1', function() { return true; }, true, false));
|
||||
self::assertTrue($this->event->attach('group2', function() { return true; }, true, false));
|
||||
|
||||
self::assertTrue($event->attach('group1', function() { return true; }, true, false));
|
||||
self::assertTrue($event->attach('group2', function() { return true; }, true, false));
|
||||
self::assertEquals(2, $event->count());
|
||||
$event->trigger('group1');
|
||||
self::assertEquals(1, $event->count());
|
||||
self::assertEquals(2, $this->event->count());
|
||||
$this->event->trigger('group1');
|
||||
self::assertEquals(1, $this->event->count());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Events can be imported from a file
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testImportEvents() : void
|
||||
{
|
||||
$event = new EventManager();
|
||||
self::assertFalse($event->importFromFile(__DIR__ . '/invalid.php'));
|
||||
self::assertTrue($event->importFromFile(__DIR__ . '/events.php'));
|
||||
self::assertTrue($this->event->importFromFile(__DIR__ . '/events.php'));
|
||||
|
||||
self::assertEquals(2, $event->count());
|
||||
self::assertTrue($event->trigger('SomeName1', '', [1, 2, 3]));
|
||||
self::assertTrue($event->trigger('SomeName2', '', 4));
|
||||
self::assertEquals(2, $this->event->count());
|
||||
self::assertTrue($this->event->trigger('SomeName1', '', [1, 2, 3]));
|
||||
self::assertTrue($this->event->trigger('SomeName2', '', 4));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid event files cannot be imported and return a failure
|
||||
* @covers phpOMS\Event\EventManager
|
||||
*/
|
||||
public function testInvalidImportEvents() : void
|
||||
{
|
||||
self::assertFalse($this->event->importFromFile(__DIR__ . '/invalid.php'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ use phpOMS\Localization\ISO4217SymbolEnum;
|
|||
*/
|
||||
class ISO4217SymbolEnumTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testEnum() : void
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testEnums() : void
|
||||
{
|
||||
$enum = ISO4217SymbolEnum::getConstants();
|
||||
self::assertCount(109, $enum);
|
||||
|
|
|
|||
|
|
@ -19,26 +19,45 @@ use phpOMS\Localization\L11nManager;
|
|||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Localization\L11nManagerTest: Localization manager for view templates
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class L11nManagerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected L11nManager $l11nManager;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->l11nManager = new L11nManager('Api');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The localization manager has the expected member variables
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
*/
|
||||
public function testAttributes() : void
|
||||
{
|
||||
$l11nManager = new L11nManager('Api');
|
||||
self::assertObjectHasAttribute('language', $l11nManager);
|
||||
self::assertObjectHasAttribute('language', $this->l11nManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The localization manager has the expected default values after initialization
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$l11nManager = new L11nManager('Api');
|
||||
self::assertFalse($l11nManager->isLanguageLoaded('en'));
|
||||
self::assertEquals([], $l11nManager->getModuleLanguage('en'));
|
||||
self::assertEquals([], $l11nManager->getModuleLanguage('en', 'Admin'));
|
||||
self::assertEquals('ERROR', $l11nManager->getHtml('en', 'Admin', 'Backend', 'Test2'));
|
||||
self::assertEquals('ERROR', $l11nManager->getText('en', 'Admin', 'Backend', 'Test2'));
|
||||
self::assertFalse($this->l11nManager->isLanguageLoaded('en'));
|
||||
self::assertEquals([], $this->l11nManager->getModuleLanguage('en'));
|
||||
self::assertEquals([], $this->l11nManager->getModuleLanguage('en', 'Admin'));
|
||||
self::assertEquals('ERROR', $this->l11nManager->getHtml('en', 'Admin', 'Backend', 'Test2'));
|
||||
self::assertEquals('ERROR', $this->l11nManager->getText('en', 'Admin', 'Backend', 'Test2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Loading language for an invalid module throws Exception
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
*/
|
||||
public function testInvalidModule() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
|
@ -51,11 +70,14 @@ class L11nManagerTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$localization = new L11nManager('Api');
|
||||
$localization->loadLanguage('en', 'doesNotExist', $expected);
|
||||
$this->l11nManager->loadLanguage('en', 'doesNotExist', $expected);
|
||||
}
|
||||
|
||||
public function testGetSet() : void
|
||||
/**
|
||||
* @testdox Language data can be loaded and output as plain text or html
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
*/
|
||||
public function testLanguageInputOutput() : void
|
||||
{
|
||||
$expected = [
|
||||
'en' => [
|
||||
|
|
@ -73,22 +95,25 @@ class L11nManagerTest extends \PHPUnit\Framework\TestCase
|
|||
],
|
||||
];
|
||||
|
||||
$l11nManager = new L11nManager('Api');
|
||||
$l11nManager->loadLanguage('en', 'Admin', $expected['en']);
|
||||
$l11nManager->loadLanguage('en', 'Admin', $expected2['en']);
|
||||
self::assertTrue($l11nManager->isLanguageLoaded('en'));
|
||||
$this->l11nManager->loadLanguage('en', 'Admin', $expected['en']);
|
||||
$this->l11nManager->loadLanguage('en', 'Admin', $expected2['en']);
|
||||
self::assertTrue($this->l11nManager->isLanguageLoaded('en'));
|
||||
|
||||
self::assertEquals('Test strin&g2', $l11nManager->getText('en', 'Admin', 'RandomThemeDoesNotMatterAlreadyLoaded', 'Test2'));
|
||||
self::assertEquals('Test strin&g2', $l11nManager->getHtml('en', 'Admin', 'RandomThemeDoesNotMatterAlreadyLoaded', 'Test2'));
|
||||
self::assertEquals('Test strin&g2', $this->l11nManager->getText('en', 'Admin', 'RandomThemeDoesNotMatterAlreadyLoaded', 'Test2'));
|
||||
self::assertEquals('Test strin&g2', $this->l11nManager->getHtml('en', 'Admin', 'RandomThemeDoesNotMatterAlreadyLoaded', 'Test2'));
|
||||
}
|
||||
|
||||
public function testGetSetFromFile() : void
|
||||
/**
|
||||
* @testdox Language data can be loaded from a file
|
||||
* @covers phpOMS\Localization\L11nManager
|
||||
*/
|
||||
public function testLanguageFile() : void
|
||||
{
|
||||
$l11nManager2 = new L11nManager('Api');
|
||||
$l11nManager2->loadLanguageFromFile('en', 'Test', __DIR__ . '/langTestFile.php');
|
||||
self::assertEquals('value', $l11nManager2->getHtml('en', 'Test', 'RandomThemeDoesNotMatterAlreadyLoaded', 'key'));
|
||||
$this->l11nManager2 = new L11nManager('Api');
|
||||
$this->l11nManager2->loadLanguageFromFile('en', 'Test', __DIR__ . '/langTestFile.php');
|
||||
self::assertEquals('value', $this->l11nManager2->getHtml('en', 'Test', 'RandomThemeDoesNotMatterAlreadyLoaded', 'key'));
|
||||
|
||||
self::assertEquals(['Test' => ['key' => 'value']], $l11nManager2->getModuleLanguage('en'));
|
||||
self::assertEquals(['key' => 'value'], $l11nManager2->getModuleLanguage('en', 'Test'));
|
||||
self::assertEquals(['Test' => ['key' => 'value']], $this->l11nManager2->getModuleLanguage('en'));
|
||||
self::assertEquals(['key' => 'value'], $this->l11nManager2->getModuleLanguage('en', 'Test'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use phpOMS\Localization\ISO3166TwoEnum;
|
|||
use phpOMS\Localization\ISO4217CharEnum;
|
||||
use phpOMS\Localization\ISO4217Enum;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Localization\L11nManager;
|
||||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Localization\TimeZoneEnumArray;
|
||||
use phpOMS\Utils\Converter\AngleType;
|
||||
|
|
@ -27,140 +26,299 @@ use phpOMS\Utils\Converter\TemperatureType;
|
|||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Localization\LocalizationTest: Localization for information such as language, currency, location, language specific formatting etc.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LocalizationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $l11nManager = null;
|
||||
protected Localization $localization;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->l11nManager = new L11nManager('Api');
|
||||
$this->localization = new Localization();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The localization has the expected member variables
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testAttributes() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
self::assertObjectHasAttribute('country', $localization);
|
||||
self::assertObjectHasAttribute('timezone', $localization);
|
||||
self::assertObjectHasAttribute('language', $localization);
|
||||
self::assertObjectHasAttribute('currency', $localization);
|
||||
self::assertObjectHasAttribute('decimal', $localization);
|
||||
self::assertObjectHasAttribute('thousands', $localization);
|
||||
self::assertObjectHasAttribute('datetime', $localization);
|
||||
self::assertObjectHasAttribute('country', $this->localization);
|
||||
self::assertObjectHasAttribute('timezone', $this->localization);
|
||||
self::assertObjectHasAttribute('language', $this->localization);
|
||||
self::assertObjectHasAttribute('currency', $this->localization);
|
||||
self::assertObjectHasAttribute('decimal', $this->localization);
|
||||
self::assertObjectHasAttribute('thousands', $this->localization);
|
||||
self::assertObjectHasAttribute('datetime', $this->localization);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The localization has the expected default values after initialization
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
self::assertTrue(ISO3166TwoEnum::isValidValue($localization->getCountry()));
|
||||
self::assertTrue(TimeZoneEnumArray::isValidValue($localization->getTimezone()));
|
||||
self::assertTrue(ISO639x1Enum::isValidValue($localization->getLanguage()));
|
||||
self::assertTrue(ISO4217Enum::isValidValue($localization->getCurrency()));
|
||||
self::assertEquals('.', $localization->getDecimal());
|
||||
self::assertEquals(',', $localization->getThousands());
|
||||
self::assertEquals([], $localization->getDatetime());
|
||||
self::assertTrue(ISO3166TwoEnum::isValidValue($this->localization->getCountry()));
|
||||
self::assertTrue(TimeZoneEnumArray::isValidValue($this->localization->getTimezone()));
|
||||
self::assertTrue(ISO639x1Enum::isValidValue($this->localization->getLanguage()));
|
||||
self::assertTrue(ISO4217Enum::isValidValue($this->localization->getCurrency()));
|
||||
self::assertEquals('.', $this->localization->getDecimal());
|
||||
self::assertEquals(',', $this->localization->getThousands());
|
||||
self::assertEquals([], $this->localization->getDatetime());
|
||||
|
||||
self::assertEquals([], $localization->getSpeed());
|
||||
self::assertEquals([], $localization->getWeight());
|
||||
self::assertEquals([], $localization->getLength());
|
||||
self::assertEquals([], $localization->getArea());
|
||||
self::assertEquals([], $localization->getVolume());
|
||||
self::assertEquals([], $this->localization->getSpeed());
|
||||
self::assertEquals([], $this->localization->getWeight());
|
||||
self::assertEquals([], $this->localization->getLength());
|
||||
self::assertEquals([], $this->localization->getArea());
|
||||
self::assertEquals([], $this->localization->getVolume());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Setting a invalid language code throws InvalidEnumValue
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidLanguage() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$localization = new Localization();
|
||||
$localization->setLanguage('abc');
|
||||
$this->localization->setLanguage('abc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Setting a invalid country code throws InvalidEnumValue
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidCountry() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$localization = new Localization();
|
||||
$localization->setCountry('abc');
|
||||
$this->localization->setCountry('abc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Setting a invalid timezone code throws InvalidEnumValue
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidTimezone() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$localization = new Localization();
|
||||
$localization->setTimezone('abc');
|
||||
$this->localization->setTimezone('abc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Setting a invalid currency code throws InvalidEnumValue
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidCurrency() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$localization = new Localization();
|
||||
$localization->setCurrency('abc');
|
||||
$this->localization->setCurrency('abc');
|
||||
}
|
||||
|
||||
public function testGetSet() : void
|
||||
/**
|
||||
* @testdox Setting a invalid angle throws InvalidEnumValue
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidAngle() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$localization->setCountry(ISO3166TwoEnum::_USA);
|
||||
self::assertEquals(ISO3166TwoEnum::_USA, $localization->getCountry());
|
||||
|
||||
$localization->setTimezone(TimeZoneEnumArray::get(315));
|
||||
self::assertEquals(TimeZoneEnumArray::get(315), $localization->getTimezone());
|
||||
|
||||
$localization->setLanguage(ISO639x1Enum::_DE);
|
||||
self::assertEquals(ISO639x1Enum::_DE, $localization->getLanguage());
|
||||
|
||||
$localization->setCurrency(ISO4217CharEnum::_EUR);
|
||||
self::assertEquals(ISO4217CharEnum::_EUR, $localization->getCurrency());
|
||||
|
||||
$localization->setDatetime(['Y-m-d H:i:s']);
|
||||
self::assertEquals(['Y-m-d H:i:s'], $localization->getDatetime());
|
||||
|
||||
$localization->setDecimal(',');
|
||||
self::assertEquals(',', $localization->getDecimal());
|
||||
|
||||
$localization->setThousands('.');
|
||||
self::assertEquals('.', $localization->getThousands());
|
||||
|
||||
$localization->setAngle(AngleType::CENTRAD);
|
||||
self::assertEquals(AngleType::CENTRAD, $localization->getAngle());
|
||||
|
||||
$localization->setTemperature(TemperatureType::FAHRENHEIT);
|
||||
self::assertEquals(TemperatureType::FAHRENHEIT, $localization->getTemperature());
|
||||
|
||||
$localization->setWeight([1]);
|
||||
$localization->setLength([1]);
|
||||
$localization->setArea([1]);
|
||||
$localization->setVolume([1]);
|
||||
$localization->setSpeed([1]);
|
||||
self::assertEquals([1], $localization->getWeight());
|
||||
self::assertEquals([1], $localization->getLength());
|
||||
self::assertEquals([1], $localization->getArea());
|
||||
self::assertEquals([1], $localization->getVolume());
|
||||
self::assertEquals([1], $localization->getSpeed());
|
||||
$this->localization->setAngle('abc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Setting a invalid temperature throws InvalidEnumValue
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidTemperature() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$this->localization->setTemperature('abc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The country can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testCountryInputOutput() : void
|
||||
{
|
||||
$this->localization->setCountry(ISO3166TwoEnum::_USA);
|
||||
self::assertEquals(ISO3166TwoEnum::_USA, $this->localization->getCountry());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The timezone can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testTimezoneInputOutput() : void
|
||||
{
|
||||
$this->localization->setTimezone(TimeZoneEnumArray::get(315));
|
||||
self::assertEquals(TimeZoneEnumArray::get(315), $this->localization->getTimezone());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The language can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testLanguageInputOutput() : void
|
||||
{
|
||||
$this->localization->setLanguage(ISO639x1Enum::_DE);
|
||||
self::assertEquals(ISO639x1Enum::_DE, $this->localization->getLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The currency can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testCurrencyInputOutput() : void
|
||||
{
|
||||
$this->localization->setCurrency(ISO4217CharEnum::_EUR);
|
||||
self::assertEquals(ISO4217CharEnum::_EUR, $this->localization->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The datetime can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testDatetimeInputOutput() : void
|
||||
{
|
||||
$this->localization->setDatetime(['Y-m-d H:i:s']);
|
||||
self::assertEquals(['Y-m-d H:i:s'], $this->localization->getDatetime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The decimal can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testDecimalInputOutput() : void
|
||||
{
|
||||
$this->localization->setDecimal(',');
|
||||
self::assertEquals(',', $this->localization->getDecimal());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The thousands can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testThousandsInputOutput() : void
|
||||
{
|
||||
$this->localization->setThousands('.');
|
||||
self::assertEquals('.', $this->localization->getThousands());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The angle can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testAngleInputOutput() : void
|
||||
{
|
||||
$this->localization->setAngle(AngleType::CENTRAD);
|
||||
self::assertEquals(AngleType::CENTRAD, $this->localization->getAngle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The temperature can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testTemperatureInputOutput() : void
|
||||
{
|
||||
$this->localization->setTemperature(TemperatureType::FAHRENHEIT);
|
||||
self::assertEquals(TemperatureType::FAHRENHEIT, $this->localization->getTemperature());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The weight can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testWeightInputOutput() : void
|
||||
{
|
||||
$this->localization->setWeight([1]);
|
||||
self::assertEquals([1], $this->localization->getWeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The length can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testLengthInputOutput() : void
|
||||
{
|
||||
$this->localization->setLength([1]);
|
||||
self::assertEquals([1], $this->localization->getLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The area can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testAreaInputOutput() : void
|
||||
{
|
||||
$this->localization->setArea([1]);
|
||||
self::assertEquals([1], $this->localization->getArea());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The volume can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testVolumeInputOutput() : void
|
||||
{
|
||||
$this->localization->setVolume([1]);
|
||||
self::assertEquals([1], $this->localization->getVolume());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The speed can be set and returned
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testSpeedInputOutput() : void
|
||||
{
|
||||
$this->localization->setSpeed([1]);
|
||||
self::assertEquals([1], $this->localization->getSpeed());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Localization data can be loaded from a locale file
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testLocalizationLoading() : void
|
||||
{
|
||||
$localization = new Localization();
|
||||
$localization->loadFromLanguage(ISO639x1Enum::_EN);
|
||||
self::assertEquals(ISO4217CharEnum::_USD, $localization->getCurrency());
|
||||
|
||||
$localization->loadFromLanguage(ISO639x1Enum::_AA);
|
||||
self::assertEquals(ISO4217CharEnum::_USD, $localization->getCurrency());
|
||||
|
||||
$localization->loadFromLanguage(ISO639x1Enum::_AA, 'ABC');
|
||||
self::assertEquals(ISO4217CharEnum::_USD, $localization->getCurrency());
|
||||
$this->localization->loadFromLanguage(ISO639x1Enum::_EN);
|
||||
self::assertEquals(ISO4217CharEnum::_USD, $this->localization->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox If no locale file for a specified country exists or a wild card country is used the first match of a locale file based on the defined language is loaded
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidCountryLocalizationLoading() : void
|
||||
{
|
||||
$this->localization->loadFromLanguage(ISO639x1Enum::_EN, 'ABC');
|
||||
self::assertEquals(ISO4217CharEnum::_USD, $this->localization->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox By default the english locale file will be loaded if no other locale file can be found
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testMissingLocalizationLoading() : void
|
||||
{
|
||||
$this->localization->loadFromLanguage(ISO639x1Enum::_AA);
|
||||
self::assertEquals(ISO4217CharEnum::_USD, $this->localization->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Loading localization data from a file with invalid language throws InvalidEnumValue
|
||||
* @covers phpOMS\Localization\Localization
|
||||
*/
|
||||
public function testInvalidLocalizationLoading() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$localization = new Localization();
|
||||
$localization->loadFromLanguage('INVALID');
|
||||
$this->localization->loadFromLanguage('INVALID');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,15 +20,25 @@ use phpOMS\Log\LogLevel;
|
|||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Log\FileLoggerTest: File logger for saving log information in a local file
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class FileLoggerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected FileLogger $log;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log')) {
|
||||
\unlink(__DIR__ . '/' . \date('Y-m-d') . '.log');
|
||||
}
|
||||
|
||||
if (\file_exists(__DIR__ . '/test.log')) {
|
||||
\unlink(__DIR__ . '/test.log');
|
||||
}
|
||||
|
||||
$this->log = new FileLogger(__DIR__ . '/test.log', false);
|
||||
}
|
||||
|
||||
protected function tearDown() : void
|
||||
|
|
@ -36,150 +46,317 @@ class FileLoggerTest extends \PHPUnit\Framework\TestCase
|
|||
if (\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log')) {
|
||||
\unlink(__DIR__ . '/' . \date('Y-m-d') . '.log');
|
||||
}
|
||||
}
|
||||
|
||||
public function testAttributes() : void
|
||||
{
|
||||
$log = new FileLogger(__DIR__);
|
||||
self::assertObjectHasAttribute('fp', $log);
|
||||
self::assertObjectHasAttribute('path', $log);
|
||||
}
|
||||
|
||||
public function testDefault() : void
|
||||
{
|
||||
$log = new FileLogger(__DIR__);
|
||||
self::assertEquals([], $log->countLogs());
|
||||
self::assertEquals([], $log->getHighestPerpetrator());
|
||||
self::assertEquals([], $log->get());
|
||||
self::assertEquals([], $log->getByLine());
|
||||
}
|
||||
|
||||
public function testGetSet() : void
|
||||
{
|
||||
if (\file_exists(__DIR__ . '/test.log')) {
|
||||
\unlink(__DIR__ . '/test.log');
|
||||
}
|
||||
|
||||
$log = new FileLogger(__DIR__ . '/test.log', false);
|
||||
|
||||
$log->emergency(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->alert(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->critical(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->error(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->warning(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->notice(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->info(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->debug(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$log->log(LogLevel::DEBUG, FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
self::assertEquals(1, $log->countLogs()['emergency'] ?? 0);
|
||||
self::assertEquals(1, $log->countLogs()['alert'] ?? 0);
|
||||
self::assertEquals(1, $log->countLogs()['critical'] ?? 0);
|
||||
self::assertEquals(1, $log->countLogs()['error'] ?? 0);
|
||||
self::assertEquals(1, $log->countLogs()['warning'] ?? 0);
|
||||
self::assertEquals(1, $log->countLogs()['notice'] ?? 0);
|
||||
self::assertEquals(1, $log->countLogs()['info'] ?? 0);
|
||||
self::assertEquals(2, $log->countLogs()['debug'] ?? 0);
|
||||
|
||||
self::assertEquals(['0.0.0.0' => 9], $log->getHighestPerpetrator());
|
||||
self::assertEquals([6, 7, 8, 9, 10], \array_keys($log->get(5, 1)));
|
||||
self::assertEquals('alert', $log->getByLine(2)['level']);
|
||||
|
||||
\ob_start();
|
||||
$log->console(FileLogger::MSG_FULL, true, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
$ob = \ob_get_clean();
|
||||
|
||||
// test without output
|
||||
$log->console(FileLogger::MSG_FULL, false, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
self::assertTrue(\stripos($ob, 'msg;') !== false);
|
||||
self::assertEquals(2, $log->countLogs()['info'] ?? 0);
|
||||
|
||||
\ob_start();
|
||||
$log->console('test', true);
|
||||
$ob = \ob_get_clean();
|
||||
self::assertEquals(\date('[Y-m-d H:i:s] ') . "test\r\n", $ob);
|
||||
|
||||
\unlink(__DIR__ . '/test.log');
|
||||
|
||||
\ob_clean();
|
||||
}
|
||||
|
||||
public function testVerbose() : void
|
||||
/**
|
||||
* @testdox The logger has the expected member variables
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testAttributes() : void
|
||||
{
|
||||
$log = new FileLogger(__DIR__, true);
|
||||
self::assertObjectHasAttribute('fp', $this->log);
|
||||
self::assertObjectHasAttribute('path', $this->log);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The logger has the expected default values after initialization
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals([], $this->log->countLogs());
|
||||
self::assertEquals([], $this->log->getHighestPerpetrator());
|
||||
self::assertEquals([], $this->log->get());
|
||||
self::assertEquals([], $this->log->getByLine());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A log file for the output can be specified for the file logger
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testNamedLogFile() : void
|
||||
{
|
||||
if (\file_exists(__DIR__ . '/named.log')) {
|
||||
\unlink(__DIR__ . '/named.log');
|
||||
}
|
||||
|
||||
$log = new FileLogger(__DIR__ . '/named.log', false);
|
||||
|
||||
$log->info('something');
|
||||
self::assertTrue(\file_exists(__DIR__ . '/named.log'));
|
||||
|
||||
if (\file_exists(__DIR__ . '/named.log')) {
|
||||
\unlink(__DIR__ . '/named.log');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox If no log file name is specified a log file per date is created
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testUnnamedLogFile() : void
|
||||
{
|
||||
$log = new FileLogger(__DIR__, false);
|
||||
|
||||
$log->info('something');
|
||||
self::assertTrue(\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox If no logs are performed no log file will be created
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testNoFileIfNoLog() : void
|
||||
{
|
||||
$log = new FileLogger(__DIR__, false);
|
||||
|
||||
self::assertFalse(\file_exists(__DIR__ . '/' . \date('Y-m-d') . '.log'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Logs with different levels get correctly stored in the log file
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testLogInputOutput() : void
|
||||
{
|
||||
$this->log->emergency(FileLogger::MSG_FULL, [
|
||||
'message' => 'emergency1',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->alert(FileLogger::MSG_FULL, [
|
||||
'message' => 'alert2',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->critical(FileLogger::MSG_FULL, [
|
||||
'message' => 'critical3',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->error(FileLogger::MSG_FULL, [
|
||||
'message' => 'error4',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->warning(FileLogger::MSG_FULL, [
|
||||
'message' => 'warning5',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->notice(FileLogger::MSG_FULL, [
|
||||
'message' => 'notice6',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->info(FileLogger::MSG_FULL, [
|
||||
'message' => 'info7',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->debug(FileLogger::MSG_FULL, [
|
||||
'message' => 'debug8',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->log(LogLevel::DEBUG, FileLogger::MSG_FULL, [
|
||||
'message' => 'log9',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->console(FileLogger::MSG_FULL, false, [
|
||||
'message' => 'console10',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$logContent = \file_get_contents(__DIR__ . '/test.log');
|
||||
|
||||
self::assertTrue(\stripos($logContent, 'emergency1') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'alert2') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'critical3') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'error4') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'warning5') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'notice6') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'info7') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'debug8') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'log9') !== false);
|
||||
self::assertTrue(\stripos($logContent, 'console10') !== false);
|
||||
|
||||
self::assertEquals(1, $this->log->countLogs()['emergency'] ?? 0);
|
||||
self::assertEquals(1, $this->log->countLogs()['alert'] ?? 0);
|
||||
self::assertEquals(1, $this->log->countLogs()['critical'] ?? 0);
|
||||
self::assertEquals(1, $this->log->countLogs()['error'] ?? 0);
|
||||
self::assertEquals(1, $this->log->countLogs()['warning'] ?? 0);
|
||||
self::assertEquals(1, $this->log->countLogs()['notice'] ?? 0);
|
||||
self::assertEquals(2, $this->log->countLogs()['info'] ?? 0);
|
||||
self::assertEquals(2, $this->log->countLogs()['debug'] ?? 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Log files can be analyzed for the highest perpetrator (IP address)
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testPerpetrator() : void
|
||||
{
|
||||
$this->log->emergency(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
self::assertEquals(['0.0.0.0' => 1], $this->log->getHighestPerpetrator());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Logs can be read from the log file
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testReadLogs() : void
|
||||
{
|
||||
$this->log->emergency(FileLogger::MSG_FULL, [
|
||||
'message' => 'emergency1',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->info(FileLogger::MSG_FULL, [
|
||||
'message' => 'info2',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->error(FileLogger::MSG_FULL, [
|
||||
'message' => 'error3',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$this->log->warning(FileLogger::MSG_FULL, [
|
||||
'message' => 'warning4',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$logs = $this->log->get(2, 1);
|
||||
|
||||
self::assertEquals(2, \count($logs));
|
||||
self::assertEquals('info2', $logs[2][7]);
|
||||
self::assertEquals('error3', $logs[3][7]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Invalid log reads return empty log data
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testInvalidReadLogs() : void
|
||||
{
|
||||
$this->log->emergency(FileLogger::MSG_FULL, [
|
||||
'message' => 'emergency1',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
$logs = $this->log->get(2, 1);
|
||||
|
||||
self::assertEquals([], $logs);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A line can be read from a log file
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testReadLine() : void
|
||||
{
|
||||
$this->log->alert(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
self::assertEquals('alert', $this->log->getByLine(1)[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox None-existing lines return on read empty log data
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testInvalidReadLine() : void
|
||||
{
|
||||
$this->log->emergency(FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
|
||||
self::assertEquals([], $this->log->getByLine(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A verbose file logger automatically outputs log data
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testVerboseLogger() : void
|
||||
{
|
||||
$this->log = new FileLogger(__DIR__, true);
|
||||
|
||||
\ob_start();
|
||||
$log->info('my log message');
|
||||
$this->log->info('my log message');
|
||||
$ob = \ob_get_clean();
|
||||
\ob_clean();
|
||||
|
||||
self::assertEquals('my log message' . "\n", $ob);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A verbose console log outputs log data
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testVerboseLog() : void
|
||||
{
|
||||
$this->log = new FileLogger(__DIR__, false);
|
||||
|
||||
\ob_start();
|
||||
$this->log->console('my log message', true);
|
||||
$ob = \ob_get_clean();
|
||||
\ob_clean();
|
||||
|
||||
self::assertTrue(\stripos($ob, 'my log message') !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A invalid log type throws a InvalidEnumValue
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testLogException() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
|
||||
|
||||
$log = new FileLogger(__DIR__ . '/test.log');
|
||||
$log->log('testException', FileLogger::MSG_FULL, [
|
||||
$this->log = new FileLogger(__DIR__ . '/test.log');
|
||||
$this->log->log('testException', FileLogger::MSG_FULL, [
|
||||
'message' => 'msg',
|
||||
'line' => 11,
|
||||
'file' => self::class,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The logger can perform timings for internal duration logging
|
||||
* @covers phpOMS\Log\FileLogger
|
||||
*/
|
||||
public function testTiming() : void
|
||||
{
|
||||
self::assertTrue(FileLogger::startTimeLog('test'));
|
||||
|
|
|
|||
|
|
@ -19,12 +19,18 @@ namespace phpOMS\tests\Math\Numerics;
|
|||
use phpOMS\Math\Numerics\Integration;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Numerics\IntegrationTest: Numeric integration
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* Commented out assertions which take a loong time with xdebug. without xdebug these are fine!
|
||||
* Commented out assertions which take a long time with xdebug. without xdebug these are fine!
|
||||
*/
|
||||
class IntegrationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox Integration by summing up rectangle areas from the left side
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
*/
|
||||
public function testLRect(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.235322, Integration::intLeftRect(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
|
|
@ -33,6 +39,10 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
//self::assertEqualsWithDelta(17999991.001392, Integration::intLeftRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Integration by summing up rectangle areas from the right side
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
*/
|
||||
public function testRRect(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.245025, Integration::intRightRect(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
|
|
@ -41,6 +51,10 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
//self::assertEqualsWithDelta(17999997.001390, Integration::intRightRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Integration by summing up rectangle areas from the middle
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
*/
|
||||
public function testMRect(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.240137, Integration::intMiddleRect(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
|
|
@ -49,6 +63,10 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
//self::assertEqualsWithDelta(17999994.001391, Integration::intMiddleRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Integration by summing up trapezoid areas
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
*/
|
||||
public function testTrapeze(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.250025, Integration::intTrapezium(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
|
|
@ -57,6 +75,10 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
//self::assertEqualsWithDelta(18000000.0, Integration::intTrapezium(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Integration by using the simpson formula
|
||||
* @covers phpOMS\tests\Math\Numerics\IntegrationTest
|
||||
*/
|
||||
public function testSimpson(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.25, Integration::intSimpson(0.0, 1.0, 100.0, function ($x) { return $x ** 3; }), 0.001);
|
||||
|
|
|
|||
|
|
@ -18,10 +18,16 @@ use phpOMS\Math\Numerics\Interpolation\CubicSplineInterpolation;
|
|||
use phpOMS\Math\Numerics\Interpolation\DerivativeType;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Numerics\Interpolation\CubicSplineInterpolationTest: Cubic spline interpolation
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CubicSplineInterpolationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The spline interpolation using the first derivative is correct
|
||||
* @covers phpOMS\tests\Math\Numerics\Interpolation\CubicSplineInterpolation
|
||||
*/
|
||||
public function testInterpolationFirstDerivative() : void
|
||||
{
|
||||
$interpolation = new CubicSplineInterpolation([
|
||||
|
|
@ -38,6 +44,10 @@ class CubicSplineInterpolationTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta(0.947888, $interpolation->interpolate(1.5), 0.1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The spline interpolation using the second derivative is correct
|
||||
* @covers phpOMS\tests\Math\Numerics\Interpolation\CubicSplineInterpolation
|
||||
*/
|
||||
public function testInterpolationSecondDerivative() : void
|
||||
{
|
||||
$interpolation = new CubicSplineInterpolation([
|
||||
|
|
|
|||
|
|
@ -17,10 +17,16 @@ namespace phpOMS\tests\Math\Numerics\Interpolation;
|
|||
use phpOMS\Math\Numerics\Interpolation\LagrangeInterpolation;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Numerics\Interpolation\LagrangeInterpolationTest: Lagrange interpolation
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LagrangeInterpolationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The lagrange interpolation is correct
|
||||
* @covers phpOMS\tests\Math\Numerics\Interpolation\LagrangeInterpolation
|
||||
*/
|
||||
public function testInterpolation() : void
|
||||
{
|
||||
$interpolation = new LagrangeInterpolation([
|
||||
|
|
|
|||
|
|
@ -17,10 +17,16 @@ namespace phpOMS\tests\Math\Numerics\Interpolation;
|
|||
use phpOMS\Math\Numerics\Interpolation\LinearInterpolation;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Numerics\Interpolation\LinearInterpolationTest: Linear interpolation
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LinearInterpolationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The linear interpolation is correct
|
||||
* @covers phpOMS\tests\Math\Numerics\LinearInterpolation
|
||||
*/
|
||||
public function testInterpolation() : void
|
||||
{
|
||||
$interpolation = new LinearInterpolation([
|
||||
|
|
|
|||
|
|
@ -17,14 +17,28 @@ namespace phpOMS\tests\Math\Parser;
|
|||
use phpOMS\Math\Parser\Evaluator;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Parser\EvaluatorTest: Evaluator for simple math formulas
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class EvaluatorTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox Basic formulas using +, -, *, /, () and ^ can be avluated
|
||||
* @covers phpOMS\Math\Parser\Evaluator
|
||||
*/
|
||||
public function testBasicEvaluation() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(4.5, Evaluator::evaluate('3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3 + 1.5'), 2);
|
||||
self::assertEqualsWithDelta(4.5, Evaluator::evaluate('3+4*2/(1-5)^2^3+1.5'), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Badly formed formulas return null as result
|
||||
* @covers phpOMS\Math\Parser\Evaluator
|
||||
*/
|
||||
public function testInvalidEvaluation() : void
|
||||
{
|
||||
self::assertNull(Evaluator::evaluate('invalid'));
|
||||
self::assertNull(Evaluator::evaluate('3+4*2/(1-5^2^3+1.5'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,15 +17,23 @@ namespace phpOMS\tests\Math\Statistic;
|
|||
use phpOMS\Math\Statistic\Average;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\AverageTest: Averages
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class AverageTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The average change of a dataset is correctly calculated
|
||||
*/
|
||||
public function testAverage() : void
|
||||
{
|
||||
self::assertEquals(-3 / 2, Average::averageDatasetChange([6, 7, 6, 3, 0]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The average mean of angles is calculated correctly
|
||||
*/
|
||||
public function testAngleMean() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(-90, Average::angleMean([90.0, 180.0, 270.0, 360.0]), 0.01);
|
||||
|
|
@ -35,11 +43,17 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta(9.999999999999977, Average::angleMean2([370.0]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The arithmetic mean is correctly calculated
|
||||
*/
|
||||
public function testArithmeticMean() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(4, Average::arithmeticMean([1, 2, 3, 4, 5, 6, 7]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The weighted mean is correctly calculated
|
||||
*/
|
||||
public function testWeightedAverage() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(69 / 20, Average::weightedAverage(
|
||||
|
|
@ -48,16 +62,25 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The geometric mean is correctly calculated
|
||||
*/
|
||||
public function testGeometricMean() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(3.3800151591413, Average::geometricMean([1, 2, 3, 4, 5, 6, 7]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The harmonic mean is correctly calculated
|
||||
*/
|
||||
public function testHarmonicMean() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(2.6997245179063, Average::harmonicMean([1, 2, 3, 4, 5, 6, 7]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The moving average is correctly calculated
|
||||
*/
|
||||
public function testMovingAverage() : void
|
||||
{
|
||||
$data = [
|
||||
|
|
@ -70,6 +93,9 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta($average, Average::totalMovingAverage($data, 10), 0.1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Different weight and dataset dimensions throw a InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidWeightedAverageDimension() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||
|
|
@ -77,6 +103,9 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
Average::weightedAverage([1, 2, 3, 4, 5, 6, 7], [0.1, 0.2, 0.3, 0.1, 0.2, 0.05]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An empty dataset for the arithmetic mean throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidArithmeticMeanZeroDevision() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
@ -84,6 +113,9 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
Average::arithmeticMean([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An empty dataset for the moving average throws a Exception
|
||||
*/
|
||||
public function testInvalidMovingAverageZeroDevision() : void
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
|
@ -91,6 +123,9 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
Average::movingAverage([], 4, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An empty dataset for the harmonic mean throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidHarmonicMeanZeroDevision() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
@ -98,6 +133,9 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
Average::harmonicMean([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An empty dataset for the geometric mean throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidGeometricMean() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
@ -105,6 +143,9 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
Average::geometricMean([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A dataset with a 0 element throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidHarmonicMean() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
@ -112,12 +153,18 @@ class AverageTest extends \PHPUnit\Framework\TestCase
|
|||
Average::harmonicMean([1, 2, 3, 0, 5, 6, 7]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The mode is correctly calculated
|
||||
*/
|
||||
public function testMode() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(2, Average::mode([1, 2, 2, 3, 4, 4, 2]), 0.01);
|
||||
}
|
||||
|
||||
public function testMedia() : void
|
||||
/**
|
||||
* @testdox The median is correctly calculated
|
||||
*/
|
||||
public function testMedian() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(4, Average::median([1, 2, 3, 4, 5, 6, 7]), 0.01);
|
||||
self::assertEqualsWithDelta(3.5, Average::median([1, 2, 3, 4, 5, 6]), 0.01);
|
||||
|
|
|
|||
|
|
@ -17,10 +17,15 @@ namespace phpOMS\tests\Math\Statistic;
|
|||
use phpOMS\Math\Statistic\Correlation;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\CorrelationTest: Correlations
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class CorrelationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The correlation coefficient (Bravis Person) is calculated correctly
|
||||
*/
|
||||
public function testBravisPersonCorrelationCoefficient() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(
|
||||
|
|
@ -32,6 +37,9 @@ class CorrelationTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The autocorrelation coefficient is calculated correctly
|
||||
*/
|
||||
public function testAutocorrelationCoefficient() : void
|
||||
{
|
||||
$data = [
|
||||
|
|
@ -45,7 +53,10 @@ class CorrelationTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta(0.098, Correlation::autocorrelationCoefficient($data, 2), 0.01);
|
||||
}
|
||||
|
||||
public function testPortmanteauTest() : void
|
||||
/**
|
||||
* @testdox The portmanteau test (Box Pierce) is correct
|
||||
*/
|
||||
public function testPortmanteauTestBoxPierce() : void
|
||||
{
|
||||
$data = [
|
||||
1, 20, 31, 8, 40, 41, 46, 89, 72, 45, 81, 93,
|
||||
|
|
@ -60,6 +71,25 @@ class CorrelationTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
self::assertEqualsWithDelta(16.46, Correlation::boxPierceTest($correlations, 24, 48), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The portmanteau test (Ljung Box) is correct
|
||||
*/
|
||||
public function testPortmanteauTestLjungBox() : void
|
||||
{
|
||||
$data = [
|
||||
1, 20, 31, 8, 40, 41, 46, 89, 72, 45, 81, 93,
|
||||
41, 63, 17, 96, 68, 27, 41, 17, 26, 75, 63, 93,
|
||||
18, 93, 80, 36, 4, 23, 81, 47, 61, 27, 13, 25,
|
||||
51, 20, 65, 45, 87, 68, 36, 31, 79, 7, 95, 37,
|
||||
];
|
||||
|
||||
$correlations = [];
|
||||
for ($i = 0; $i < 24; ++$i) {
|
||||
$correlations[] = Correlation::autocorrelationCoefficient($data, $i + 1);
|
||||
}
|
||||
|
||||
self::assertEqualsWithDelta(24.92, Correlation::ljungBoxTest($correlations, 24, 48), 0.01);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ use phpOMS\Math\Statistic\Forecast\Error;
|
|||
use phpOMS\Math\Stochastic\Distribution\TDistribution;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\Forecast\Regression\LevelLevelRegressionTest: Level level regression
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LevelLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -34,21 +36,33 @@ class LevelLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
$this->reg = LevelLevelRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The regression parameters are calcualated correctly
|
||||
*/
|
||||
public function testRegression() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(['b0' => 3, 'b1' => 4], $this->reg, 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The slope is calculated correctly
|
||||
*/
|
||||
public function testSlope() : void
|
||||
{
|
||||
self::assertEquals(4, LevelLevelRegression::getSlope($this->reg['b1'], 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The elasticity is calculated correctly
|
||||
*/
|
||||
public function testElasticity() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.7273, LevelLevelRegression::getElasticity($this->reg['b1'], 11, 2), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The standard error of the population is calculated correctly
|
||||
*/
|
||||
public function testStandardErrorOfRegressionPopulation() : void
|
||||
{
|
||||
$x = [1, 2, 3, 4, 5];
|
||||
|
|
@ -64,6 +78,9 @@ class LevelLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta(0.747, LevelLevelRegression::getStandardErrorOfRegressionPopulation($errors), 0.001);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The standard error of the sample is calculated correctly
|
||||
*/
|
||||
public function testStandardErrorOfRegressionSample() : void
|
||||
{
|
||||
$x = [1, 2, 3, 4, 5];
|
||||
|
|
@ -79,6 +96,9 @@ class LevelLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta(0.964, LevelLevelRegression::getStandardErrorOfRegressionSample($errors), 0.001);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The prediction interval is calculated correctly
|
||||
*/
|
||||
public function testPredictionInterval() : void
|
||||
{
|
||||
$x = [1, 2, 3, 4, 5];
|
||||
|
|
@ -99,6 +119,9 @@ class LevelLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Different dimension sizes for x and y coordinates throw a InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ namespace phpOMS\tests\Math\Statistic\Forecast\Regression;
|
|||
use phpOMS\Math\Statistic\Forecast\Regression\LevelLogRegression;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\Forecast\Regression\LevelLogRegressionTest: Level log regression
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LevelLogRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -32,23 +34,35 @@ class LevelLogRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
$this->reg = LevelLogRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The regression parameters are calcualated correctly
|
||||
*/
|
||||
public function testRegression() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(['b0' => 1, 'b1' => 1], $this->reg, 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The slope is calculated correctly
|
||||
*/
|
||||
public function testSlope() : void
|
||||
{
|
||||
$x = 2;
|
||||
self::assertEqualsWithDelta($this->reg['b1'] / $x, LevelLogRegression::getSlope($this->reg['b1'], 0, $x), 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The elasticity is calculated correctly
|
||||
*/
|
||||
public function testElasticity() : void
|
||||
{
|
||||
$y = 3;
|
||||
self::assertEqualsWithDelta($this->reg['b1'] / $y, LevelLogRegression::getElasticity($this->reg['b1'], $y, 0), 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Different dimension sizes for x and y coordinates throw a InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ namespace phpOMS\tests\Math\Statistic\Forecast\Regression;
|
|||
use phpOMS\Math\Statistic\Forecast\Regression\LogLevelRegression;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\Forecast\Regression\LogLevelRegressionTest: Log level regression
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LogLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -32,23 +34,35 @@ class LogLevelRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
$this->reg = LogLevelRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The regression parameters are calcualated correctly
|
||||
*/
|
||||
public function testRegression() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(['b0' => -1, 'b1' => 2], $this->reg, 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The slope is calculated correctly
|
||||
*/
|
||||
public function testSlope() : void
|
||||
{
|
||||
$y = 3;
|
||||
self::assertEqualsWithDelta($this->reg['b1'] * $y, LogLevelRegression::getSlope($this->reg['b1'], $y, 0), 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The elasticity is calculated correctly
|
||||
*/
|
||||
public function testElasticity() : void
|
||||
{
|
||||
$x = 2;
|
||||
self::assertEqualsWithDelta($this->reg['b1'] * $x, LogLevelRegression::getElasticity($this->reg['b1'], 0, $x), 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Different dimension sizes for x and y coordinates throw a InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ namespace phpOMS\tests\Math\Statistic\Forecast\Regression;
|
|||
use phpOMS\Math\Statistic\Forecast\Regression\LogLogRegression;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\Forecast\Regression\LogLogRegressionTest: Log log regression
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class LogLogRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -32,11 +34,17 @@ class LogLogRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
$this->reg = LogLogRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The regression parameters are calcualated correctly
|
||||
*/
|
||||
public function testRegression() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(['b0' => 2, 'b1' => 3], $this->reg, 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The slope is calculated correctly
|
||||
*/
|
||||
public function testSlope() : void
|
||||
{
|
||||
$y = 3;
|
||||
|
|
@ -44,11 +52,17 @@ class LogLogRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta($this->reg['b1'] * $y / $x, LogLogRegression::getSlope($this->reg['b1'], $y, $x), 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The elasticity is calculated correctly
|
||||
*/
|
||||
public function testElasticity() : void
|
||||
{
|
||||
self::assertEqualsWithDelta($this->reg['b1'], LogLogRegression::getElasticity($this->reg['b1'], 0, 0), 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Different dimension sizes for x and y coordinates throw a InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ namespace phpOMS\tests\Math\Statistic\Forecast\Regression;
|
|||
use phpOMS\Math\Statistic\Forecast\Regression\PolynomialRegression;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\Forecast\Regression\PolynomialRegressionTest: Polynomial regression
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PolynomialRegressionTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -32,11 +34,17 @@ class PolynomialRegressionTest extends \PHPUnit\Framework\TestCase
|
|||
$this->reg = PolynomialRegression::getRegression($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The regression parameters are calcualated correctly
|
||||
*/
|
||||
public function testRegression() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(['a' => 1, 'b' => 2, 'c' => 3], $this->reg, 0.2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Different dimension sizes for x and y coordinates throw a InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidDimension() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||
|
|
|
|||
|
|
@ -17,20 +17,31 @@ namespace phpOMS\tests\Math\Statistic;
|
|||
use phpOMS\Math\Statistic\MeasureOfDispersion;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Statistic\MeasureOfDispersionTest: Measure of dispersion
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @testdox The range of a dataset is correctly calculated
|
||||
*/
|
||||
public function testRange() : void
|
||||
{
|
||||
self::assertEquals((float) (9 - 1), MeasureOfDispersion::range([4, 5, 9, 1, 3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The standard deviation is correctly calculated
|
||||
*/
|
||||
public function testStandardDeviation() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(2.160246, MeasureOfDispersion::standardDeviation([1, 2, 3, 4, 5, 6, 7]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The empirical covariance is correctly calculated
|
||||
*/
|
||||
public function testEmpiricalCovariance() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(
|
||||
|
|
@ -42,12 +53,25 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testVariance() : void
|
||||
/**
|
||||
* @testdox The sample variance is correctly calculated
|
||||
*/
|
||||
public function testVarianceSample() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(6219.9, MeasureOfDispersion::sampleVariance([3, 21, 98, 203, 17, 9]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The population/empirical variance is correctly calculated
|
||||
*/
|
||||
public function testVariancePopulation() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(5183.25, MeasureOfDispersion::empiricalVariance([3, 21, 98, 203, 17, 9]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The mean deviations are correctly calculated
|
||||
*/
|
||||
public function testDeviation() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.0, MeasureOfDispersion::meanDeviation([3, 4, 5, 9, 7, 8, 9]), 0.01);
|
||||
|
|
@ -55,6 +79,9 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta((12.96 + 2.56 + 0.36 + 5.76 + 11.56) / 5, MeasureOfDispersion::squaredMeanDeviation([1, 3, 4, 7, 8]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The mean deviations for every dataset element is correctly calculated
|
||||
*/
|
||||
public function testDeviationArray() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(
|
||||
|
|
@ -76,17 +103,26 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The empirical variation coefficient is correctly calculated
|
||||
*/
|
||||
public function testEmpiricalVariationCoefficient() : void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.5400, MeasureOfDispersion::empiricalVariationCoefficient([1, 2, 3, 4, 5, 6, 7]), 0.01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The interquartile range is correctly calculated
|
||||
*/
|
||||
public function testIQR() : void
|
||||
{
|
||||
$x = [7, 7, 31, 31, 47, 75, 87, 115, 116, 119, 119, 155, 177];
|
||||
self::assertEquals(88, MeasureOfDispersion::getIQR($x));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The empirical varation coefficient with a mean of 0 throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidEmpiricalVariationCoefficient() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
@ -94,6 +130,9 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
|||
MeasureOfDispersion::empiricalVariationCoefficient([1, 2, 3, 4, 5, 6, 7], 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An empty dataset in the empirical covariance throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidEmpiricalCovariance() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
@ -101,6 +140,9 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
|||
MeasureOfDispersion::empiricalCovariance([], []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Different dataset saces in the empirical covariance throw a InvalidDimensionException
|
||||
*/
|
||||
public function testInvalidEmpiricalCovarianceDimension() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Matrix\Exception\InvalidDimensionException::class);
|
||||
|
|
@ -108,6 +150,9 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
|||
MeasureOfDispersion::empiricalCovariance([1, 2, 3, 4], [1, 2, 3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An empty dataset in the sample variance throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidSampleVariance() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
@ -115,6 +160,9 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase
|
|||
MeasureOfDispersion::sampleVariance([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox An empty dataset in the empirical/population variance throws a ZeroDevisionException
|
||||
*/
|
||||
public function testInvalidEmpiricalVariance() : void
|
||||
{
|
||||
self::expectException(\phpOMS\Math\Exception\ZeroDevisionException::class);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ namespace phpOMS\tests\Math\Stochastic;
|
|||
use phpOMS\Math\Stochastic\NaiveBayesClassifier;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Math\Stochastic\NaiveBayesClassifierTest: Naive bayes classifier for numeric values and strings/attributes
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class NaiveBayesClassifierTest extends \PHPUnit\Framework\TestCase
|
||||
|
|
@ -55,6 +57,9 @@ class NaiveBayesClassifierTest extends \PHPUnit\Framework\TestCase
|
|||
['height' => 5.75, 'weight' => 150, 'foot' => 9],
|
||||
];
|
||||
|
||||
/**
|
||||
* @testdox The classification of strings/attributes is correct
|
||||
*/
|
||||
public function testTextClassifier() : void
|
||||
{
|
||||
$filter = new NaiveBayesClassifier();
|
||||
|
|
@ -68,6 +73,9 @@ class NaiveBayesClassifierTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The classification of nimeric values is correct
|
||||
*/
|
||||
public function testNumericClassifier() : void
|
||||
{
|
||||
$filter = new NaiveBayesClassifier();
|
||||
|
|
|
|||
|
|
@ -17,26 +17,43 @@ namespace phpOMS\tests\Message\Http;
|
|||
use phpOMS\Localization\Localization;
|
||||
use phpOMS\Message\Http\Header;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\System\MimeType;
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Message\HeaderTest: Header for http requests/responses
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class HeaderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testDefaults() : void
|
||||
protected Header $header;
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$header = new Header();
|
||||
self::assertFalse($header->isLocked());
|
||||
self::assertEquals(0, $header->getStatusCode());
|
||||
self::assertEquals('HTTP/1.1', $header->getProtocolVersion());
|
||||
self::assertEmpty(Header::getAllHeaders());
|
||||
self::assertEquals('', $header->getReasonPhrase());
|
||||
self::assertEquals([], $header->get('key'));
|
||||
self::assertFalse($header->has('key'));
|
||||
self::assertInstanceOf(Localization::class, $header->getL11n());
|
||||
self::assertEquals(0, $header->getAccount());
|
||||
$this->header = new Header();
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The header has the expected default values after initialization
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testDefaults() : void
|
||||
{
|
||||
self::assertFalse($this->header->isLocked());
|
||||
self::assertEquals(0, $this->header->getStatusCode());
|
||||
self::assertEquals('HTTP/1.1', $this->header->getProtocolVersion());
|
||||
self::assertEmpty(Header::getAllHeaders());
|
||||
self::assertEquals('', $this->header->getReasonPhrase());
|
||||
self::assertEquals([], $this->header->get('key'));
|
||||
self::assertFalse($this->header->has('key'));
|
||||
self::assertInstanceOf(Localization::class, $this->header->getL11n());
|
||||
self::assertEquals(0, $this->header->getAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Security policy headers get correctly identified
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testSecurityHeader() : void
|
||||
{
|
||||
self::assertTrue(Header::isSecurityHeader('content-security-policy'));
|
||||
|
|
@ -46,73 +63,141 @@ class HeaderTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertFalse(Header::isSecurityHeader('x-frame-optionss'));
|
||||
}
|
||||
|
||||
public function testGetSet() : void
|
||||
/**
|
||||
* @testdox Header data can be set, checked for existence and returned
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testDataInputOutput() : void
|
||||
{
|
||||
$header = new Header();
|
||||
|
||||
self::assertTrue($header->set('key', 'header'));
|
||||
self::assertEquals(['header'], $header->get('key'));
|
||||
self::assertTrue($header->has('key'));
|
||||
|
||||
self::assertFalse($header->set('key', 'header2'));
|
||||
self::assertEquals(['header'], $header->get('key'));
|
||||
|
||||
self::assertTrue($header->set('key', 'header3', true));
|
||||
self::assertEquals(['header3'], $header->get('key'));
|
||||
|
||||
self::assertTrue($header->remove('key'));
|
||||
self::assertFalse($header->has('key'));
|
||||
self::assertFalse($header->remove('key'));
|
||||
|
||||
$header->setAccount(2);
|
||||
self::AssertEquals(2, $header->getAccount(2));
|
||||
|
||||
$header->setDownloadable('testname', 'mp3');
|
||||
self::assertTrue($this->header->set('key', 'header'));
|
||||
self::assertEquals(['header'], $this->header->get('key'));
|
||||
self::assertTrue($this->header->has('key'));
|
||||
}
|
||||
|
||||
public function testLockedHeaderSet() : void
|
||||
/**
|
||||
* @testdox Header data can be forced to get overwritten
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testOverwrite() : void
|
||||
{
|
||||
$header = new Header();
|
||||
$header->lock();
|
||||
self::assertTrue($header->isLocked());
|
||||
self::assertFalse($header->set('key', 'value'));
|
||||
self::assertTrue($this->header->set('key', 'header'));
|
||||
self::assertTrue($this->header->set('key', 'header3', true));
|
||||
self::assertEquals(['header3'], $this->header->get('key'));
|
||||
}
|
||||
|
||||
public function testLockedHeaderRemove() : void
|
||||
/**
|
||||
* @testdox By default header data doesn't get overwritten
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testInvalidOverwrite() : void
|
||||
{
|
||||
$header = new Header();
|
||||
$header->lock();
|
||||
self::assertTrue($header->isLocked());
|
||||
self::assertFalse($header->remove('key'));
|
||||
self::assertTrue($this->header->set('key', 'header'));
|
||||
self::assertFalse($this->header->set('key', 'header2'));
|
||||
self::assertEquals(['header'], $this->header->get('key'));
|
||||
}
|
||||
|
||||
public function testGeneration() : void
|
||||
/**
|
||||
* @testdox Header data can be removed
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testRemove() : void
|
||||
{
|
||||
$header = new Header();
|
||||
self::assertTrue($this->header->set('key', 'header'));
|
||||
self::assertTrue($this->header->remove('key'));
|
||||
self::assertFalse($this->header->has('key'));
|
||||
}
|
||||
|
||||
$header->generate(RequestStatusCode::R_403);
|
||||
/**
|
||||
* @testdox None-existing header data cannot be removed
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testInvalidRemove() : void
|
||||
{
|
||||
self::assertFalse($this->header->remove('key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Account data can be set and returned
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testAccountInputOutput() : void
|
||||
{
|
||||
$this->header->setAccount(2);
|
||||
self::assertEquals(2, $this->header->getAccount(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox Data can be defined as downloadable
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testDownloadable() : void
|
||||
{
|
||||
$this->header->setDownloadable('testname', 'mp3');
|
||||
self::assertEquals(MimeType::M_BIN, $this->header->get('Content-Type')[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A header can be locked
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testLockInputOutput() : void
|
||||
{
|
||||
$this->header->lock();
|
||||
self::assertTrue($this->header->isLocked());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A locked header cannot add new data
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testLockInvalidSet() : void
|
||||
{
|
||||
$this->header->lock();
|
||||
self::assertFalse($this->header->set('key', 'value'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox A locked header cannot remove data
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testLockInvalidRemove() : void
|
||||
{
|
||||
$this->header->lock();
|
||||
self::assertFalse($this->header->remove('key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The header can generate default http headers based on status codes
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testHeaderGeneration() : void
|
||||
{
|
||||
$this->header->generate(RequestStatusCode::R_403);
|
||||
self::assertEquals(403, \http_response_code());
|
||||
|
||||
$header->generate(RequestStatusCode::R_404);
|
||||
$this->header->generate(RequestStatusCode::R_404);
|
||||
self::assertEquals(404, \http_response_code());
|
||||
|
||||
$header->generate(RequestStatusCode::R_406);
|
||||
$this->header->generate(RequestStatusCode::R_406);
|
||||
self::assertEquals(406, \http_response_code());
|
||||
|
||||
$header->generate(RequestStatusCode::R_407);
|
||||
$this->header->generate(RequestStatusCode::R_407);
|
||||
self::assertEquals(407, \http_response_code());
|
||||
|
||||
$header->generate(RequestStatusCode::R_503);
|
||||
$this->header->generate(RequestStatusCode::R_503);
|
||||
self::assertEquals(503, \http_response_code());
|
||||
|
||||
$header->generate(RequestStatusCode::R_500);
|
||||
$this->header->generate(RequestStatusCode::R_500);
|
||||
self::assertEquals(500, \http_response_code());
|
||||
}
|
||||
|
||||
public function testOverwriteSecurityHeader() : void
|
||||
/**
|
||||
* @testdox Security header data cannot be changed once defined
|
||||
* @covers phpOMS\Message\Http\Header
|
||||
*/
|
||||
public function testInvalidOverwriteSecurityHeader() : void
|
||||
{
|
||||
$header = new Header();
|
||||
self::assertTrue($header->set('content-security-policy', 'header'));
|
||||
self::assertFalse($header->set('content-security-policy', 'header', true));
|
||||
self::assertTrue($this->header->set('content-security-policy', 'header'));
|
||||
self::assertFalse($this->header->set('content-security-policy', 'header', true));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ use phpOMS\Router\RouteVerb;
|
|||
*/
|
||||
class RouteVerbTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testEnum() : void
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testEnums() : void
|
||||
{
|
||||
self::assertTrue(\defined('phpOMS\Router\RouteVerb::GET'));
|
||||
self::assertTrue(\defined('phpOMS\Router\RouteVerb::PUT'));
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ use phpOMS\System\MimeType;
|
|||
*/
|
||||
class MimeTypeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testEnum() : void
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testEnums() : void
|
||||
{
|
||||
$enums = MimeType::getConstants();
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,10 @@ use phpOMS\Uri\UriScheme;
|
|||
*/
|
||||
class UriSchemeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testEnum() : void
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testEnums() : void
|
||||
{
|
||||
self::assertTrue(\defined('phpOMS\Uri\UriScheme::HTTP'));
|
||||
self::assertTrue(\defined('phpOMS\Uri\UriScheme::FILE'));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user