diff --git a/Business/Finance/FinanceFormulas.php b/Business/Finance/FinanceFormulas.php
index b5cb4772f..ef15a95ec 100644
--- a/Business/Finance/FinanceFormulas.php
+++ b/Business/Finance/FinanceFormulas.php
@@ -1061,7 +1061,7 @@ class FinanceFormulas
*
* @return float
*
- * @throws InvalidDimensionException Throws this exception if the length of the array is 0
+ * @throws \UnexpectedValueException Throws this exception if the length of the array is 0
*
* @since 1.0.0
*/
@@ -1070,7 +1070,7 @@ class FinanceFormulas
$count = count($C);
if ($count === 0) {
- throw new InvalidDimensionException($count);
+ throw new \UnexpectedValueException((string) $count);
}
$npv = -$C[0];
diff --git a/Log/FileLogger.php b/Log/FileLogger.php
index 0847b9ce6..1c120ec1c 100644
--- a/Log/FileLogger.php
+++ b/Log/FileLogger.php
@@ -552,7 +552,9 @@ class FileLogger implements LoggerInterface
*/
public function console(string $message, bool $verbose = true, array $context = []) /* : void */
{
- $message = date('[Y-m-d H:i:s] ') . $message . "\r\n";
+ if (empty($context)) {
+ $message = date('[Y-m-d H:i:s] ') . $message . "\r\n";
+ }
if ($verbose) {
echo $message;
diff --git a/Message/Http/Response.php b/Message/Http/Response.php
index b3ef74e43..ff36309ae 100644
--- a/Message/Http/Response.php
+++ b/Message/Http/Response.php
@@ -106,7 +106,7 @@ class Response extends ResponseAbstract implements RenderableInterface
foreach ($types as $type) {
if (stripos($type, MimeType::M_JSON) !== false) {
- return $this->jsonSerialize();
+ return json_encode($this->jsonSerialize());
}
}
diff --git a/Message/ResponseAbstract.php b/Message/ResponseAbstract.php
index 28013940f..d8392eba8 100644
--- a/Message/ResponseAbstract.php
+++ b/Message/ResponseAbstract.php
@@ -27,7 +27,7 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable
/**
* Responses.
*
- * @var string[]
+ * @var array
* @since 1.0.0
*/
protected $response = [];
@@ -49,9 +49,9 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable
*
* @since 1.0.0
*/
- public function &get($id)
+ public function get($id)
{
- return $this->response[$id];
+ return $this->response[$id] ?? null;
}
/**
@@ -77,7 +77,7 @@ abstract class ResponseAbstract implements MessageInterface, \JsonSerializable
*/
public function jsonSerialize()
{
- return json_encode($this->toArray());
+ return $this->toArray();
}
/**
diff --git a/Model/Html/Head.php b/Model/Html/Head.php
index 4c59d7a91..277446537 100644
--- a/Model/Html/Head.php
+++ b/Model/Html/Head.php
@@ -189,8 +189,9 @@ class Head implements RenderableInterface
{
$head = '';
$head .= $this->meta->render();
- $head .= $this->renderStyle();
- $head .= $this->renderScript();
+ $head .= $this->renderAssets();
+ $head .= empty($this->style) ? '' : '';
+ $head .= empty($this->script) ? '' : '';
return $head;
}
diff --git a/Model/Html/Meta.php b/Model/Html/Meta.php
index 1b5283b76..5bf486499 100644
--- a/Model/Html/Meta.php
+++ b/Model/Html/Meta.php
@@ -15,6 +15,7 @@ declare(strict_types=1);
namespace phpOMS\Model\Html;
use phpOMS\Contract\RenderableInterface;
+use phpOMS\Views\ViewAbstract;
/**
* Meta class.
@@ -170,10 +171,10 @@ class Meta implements RenderableInterface
*/
public function render() : string
{
- return (count($this->keywords) > 0 ? '"' : '')
- . (!empty($this->author) ? '' : '')
- . (!empty($this->description) ? '' : '')
- . (!empty($this->charset) ? '' : '')
+ return (count($this->keywords) > 0 ? '"' : '')
+ . (!empty($this->author) ? '' : '')
+ . (!empty($this->description) ? '' : '')
+ . (!empty($this->charset) ? '' : '')
. '';
}
}
diff --git a/Security/PhpCode.php b/Security/PhpCode.php
index bf6550fbe..b0d6a7b2c 100644
--- a/Security/PhpCode.php
+++ b/Security/PhpCode.php
@@ -48,7 +48,7 @@ class PhpCode
*
* @since 1.0.0
*/
- private static function normalizeSource(string $source) : string
+ public static function normalizeSource(string $source) : string
{
return str_replace(["\n", "\r\n", "\r", "\t"], ['', '', '', ' '], $source);
}
@@ -102,8 +102,6 @@ class PhpCode
*/
public static function hasDeprecatedFunction(string $source) : bool
{
- $source = self::normalizeSource($source);
-
foreach (self::$deprecatedFunctions as $function) {
if (preg_match('/' . $function . '\s*\(/', $source) === 1) {
return true;
diff --git a/Utils/ArrayUtils.php b/Utils/ArrayUtils.php
index 2a64a45bf..e6aeb4b29 100644
--- a/Utils/ArrayUtils.php
+++ b/Utils/ArrayUtils.php
@@ -297,6 +297,25 @@ class ArrayUtils
return trim($args[$key + 1], '" ');
}
+ /**
+ * Check if flag is set
+ *
+ * @param string $id Id to find
+ * @param array $args CLI command list
+ *
+ * @return int
+ *
+ * @since 1.0.0
+ */
+ public static function hasArg(string $id, array $args) /* : ?int */
+ {
+ if (($key = array_search($id, $args)) === false) {
+ return null;
+ }
+
+ return $key;
+ }
+
/**
* Flatten array
*
diff --git a/Utils/Git/Repository.php b/Utils/Git/Repository.php
index 97c086f1c..9cc8ca9d1 100644
--- a/Utils/Git/Repository.php
+++ b/Utils/Git/Repository.php
@@ -106,6 +106,18 @@ class Repository
}
}
+ /**
+ * Get repository path.
+ *
+ * @return string
+ *
+ * @since 1.0.0
+ */
+ public function getPath() : string
+ {
+ return $this->path;
+ }
+
/**
* Get active Branch.
*
diff --git a/Validation/Base/DateTime.php b/Validation/Base/DateTime.php
index 67fce81a0..15fdf22d4 100644
--- a/Validation/Base/DateTime.php
+++ b/Validation/Base/DateTime.php
@@ -27,15 +27,6 @@ use phpOMS\Validation\ValidatorAbstract;
abstract class DateTime extends ValidatorAbstract
{
- /**
- * Constructor.
- *
- * @since 1.0.0
- */
- public function __construct()
- {
- }
-
/**
* {@inheritdoc}
*/
diff --git a/Validation/Finance/BIC.php b/Validation/Finance/BIC.php
index 8b3faec57..f73c68654 100644
--- a/Validation/Finance/BIC.php
+++ b/Validation/Finance/BIC.php
@@ -24,18 +24,9 @@ use phpOMS\Validation\ValidatorAbstract;
* @link http://website.orange-management.de
* @since 1.0.0
*/
-abstract class BIC extends ValidatorAbstract
+final class BIC extends ValidatorAbstract
{
- /**
- * Constructor.
- *
- * @since 1.0.0
- */
- public function __construct()
- {
- }
-
/**
* {@inheritdoc}
*/
diff --git a/Validation/Finance/CreditCard.php b/Validation/Finance/CreditCard.php
index 2f755c353..23a6b8537 100644
--- a/Validation/Finance/CreditCard.php
+++ b/Validation/Finance/CreditCard.php
@@ -24,18 +24,9 @@ use phpOMS\Validation\ValidatorAbstract;
* @link http://website.orange-management.de
* @since 1.0.0
*/
-abstract class CreditCard extends ValidatorAbstract
+final class CreditCard extends ValidatorAbstract
{
- /**
- * Constructor.
- *
- * @since 1.0.0
- */
- public function __construct()
- {
- }
-
/**
* {@inheritdoc}
*/
diff --git a/Validation/Finance/Iban.php b/Validation/Finance/Iban.php
index 8ff9aba22..71d6e0e55 100644
--- a/Validation/Finance/Iban.php
+++ b/Validation/Finance/Iban.php
@@ -24,18 +24,8 @@ use phpOMS\Validation\ValidatorAbstract;
* @link http://website.orange-management.de
* @since 1.0.0
*/
-abstract class Iban extends ValidatorAbstract
+final class Iban extends ValidatorAbstract
{
- /**
- * Constructor.
- *
- * @since 1.0.0
- * @codeCoverageIgnore
- */
- private function __construct()
- {
- }
-
/**
* {@inheritdoc}
*/
diff --git a/Validation/Validator.php b/Validation/Validator.php
index b893aa0f7..18dcde896 100644
--- a/Validation/Validator.php
+++ b/Validation/Validator.php
@@ -43,10 +43,16 @@ final class Validator extends ValidatorAbstract
return true;
}
- foreach ($constraints as $callback => $settings) {
- $callback = StringUtils::endsWith($callback, 'Not') ? substr($callback, 0, -3) : $callback;
- $valid = self::$callback($var, ...$settings);
- $valid = (StringUtils::endsWith($callback, 'Not') ? $valid : !$valid);
+ foreach ($constraints as $test => $settings) {
+ $callback = StringUtils::endsWith($test, 'Not') ? substr($test, 0, -3) : $test;
+
+ if (!empty($settings)) {
+ $valid = $callback($var, ...$settings);
+ } else {
+ $valid = $callback($var);
+ }
+
+ $valid = (StringUtils::endsWith($test, 'Not') ? !$valid : $valid);
if (!$valid) {
return false;
@@ -130,7 +136,7 @@ final class Validator extends ValidatorAbstract
*/
public static function matches(string $var, string $pattern) : bool
{
- return (preg_match($pattern, $var) !== false ? true : false);
+ return (preg_match($pattern, $var) === 1 ? true : false);
}
/**
diff --git a/Views/View.php b/Views/View.php
index 5ca9433ed..d7702771c 100644
--- a/Views/View.php
+++ b/Views/View.php
@@ -217,20 +217,6 @@ class View extends ViewAbstract
return htmlspecialchars($this->getText($translation, $module, $theme));
}
- /**
- * Print html output.
- *
- * @param mixed $text Text
- *
- * @return string
- *
- * @since 1.0.0
- */
- public function printHtml($text) : string
- {
- return htmlspecialchars((string) $text);
- }
-
/**
* Get request of view
*
diff --git a/Views/ViewAbstract.php b/Views/ViewAbstract.php
index f909612d8..8cbde67f1 100644
--- a/Views/ViewAbstract.php
+++ b/Views/ViewAbstract.php
@@ -97,6 +97,34 @@ abstract class ViewAbstract implements \Serializable
$this->template = $template;
}
+ /**
+ * Print html output.
+ *
+ * @param mixed $text Text
+ *
+ * @return string
+ *
+ * @since 1.0.0
+ */
+ public function printHtml($text) : string
+ {
+ return htmlspecialchars((string) $text);
+ }
+
+ /**
+ * Print html output.
+ *
+ * @param mixed $text Text
+ *
+ * @return string
+ *
+ * @since 1.0.0
+ */
+ public static function html($text) : string
+ {
+ return htmlspecialchars((string) $text);
+ }
+
/**
* Returns all views
*
diff --git a/tests/Business/Finance/FinanceFormulasTest.php b/tests/Business/Finance/FinanceFormulasTest.php
index 1a3adb35d..a07eb340f 100644
--- a/tests/Business/Finance/FinanceFormulasTest.php
+++ b/tests/Business/Finance/FinanceFormulasTest.php
@@ -183,6 +183,9 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase
self::assertEquals(500 / 1000 - 1, FinanceFormulas::getReturnOnInvestment(500, 1000));
self::assertEquals((500 - 300) / 500, FinanceFormulas::getRetentionRatio(500, 300));
self::assertEquals(500 / 1000 - 1, FinanceFormulas::getRateOfOnflation(500, 1000));
+
+ self::assertEquals(1000 / 500, FinanceFormulas::getPaybackPeriod(1000, 500));
+ self::assertEquals(100 / 0.15, FinanceFormulas::getPresentValueOfPerpetuity(100, 0.15));
}
public function testCompound()
@@ -305,12 +308,13 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase
self::assertEquals(2857.65, FinanceFormulas::getFutureValueContinuousCompounding($pv, $r, $t), '', 0.01);
}
- public function testFutureValueFactor()
+ public function testValueFactor()
{
$r = 0.15;
$n = 7;
self::assertEquals(2.66, FinanceFormulas::getFutureValueFactor($r, $n), '', 0.01);
+ self::assertEquals(0.37594, FinanceFormulas::getPresentValueFactor($r, $n), '', 0.01);
}
public function testGeometricMeanReturn()
@@ -377,6 +381,14 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase
self::assertEquals(172.13, FinanceFormulas::getNetPresentValue($c, $r), '', 0.01);
}
+ /**
+ * @expectedException \UnexpectedValueException
+ */
+ public function testInvalidNetPresentValue()
+ {
+ FinanceFormulas::getNetPresentValue([], 0.1);
+ }
+
public function testRealRateOfReturn()
{
$nominal = 0.15;
@@ -384,4 +396,36 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0.09524, FinanceFormulas::getRealRateOfReturn($nominal, $inflation), '', 0.01);
}
+
+ public function testNetWorkingCapital()
+ {
+ self::assertEquals(1000 - 600, FinanceFormulas::getNetWorkingCapital(1000, 600), '', 0.01);
+ }
+
+ public function testNumberOfPeriodsPVFV()
+ {
+ $fv = 1200;
+ $pv = 1000;
+ $r = 0.03;
+
+ self::assertEquals(6.1681, FinanceFormulas::getNumberOfPeriodsPVFV($fv, $pv, $r), '', 0.01);
+ }
+
+ public function testPresentValue()
+ {
+ $c = 1000;
+ $r = 0.15;
+ $n = 7;
+
+ self::assertEquals(375.94, FinanceFormulas::getPresentValue($c, $r, $n), '', 0.01);
+ }
+
+ public function testPresentValueContinuousCompounding()
+ {
+ $c = 1000;
+ $r = 0.15;
+ $t = 7;
+
+ self::assertEquals(349.94, FinanceFormulas::getPresentValueContinuousCompounding($c, $r, $t), '', 0.01);
+ }
}
diff --git a/tests/Business/Finance/StockBondsTest.php b/tests/Business/Finance/StockBondsTest.php
index 05ea45f1b..57987a0b8 100644
--- a/tests/Business/Finance/StockBondsTest.php
+++ b/tests/Business/Finance/StockBondsTest.php
@@ -66,4 +66,50 @@ class StockBondsTest extends \PHPUnit\Framework\TestCase
self::assertEquals(1.75, StockBonds::getNetAssetValue($assets, $liabilities, $shares), '', 0.01);
}
+
+ public function testPresentValueOfStockConstantGrowth()
+ {
+ $div = 500;
+ $r = 0.15;
+ $g = 0.05;
+
+ self::assertEquals(5000, StockBonds::getPresentValueOfStockConstantGrowth($div, $r, $g), '', 0.01);
+ }
+
+ public function testTotalStockReturn()
+ {
+ $p0 = 1000;
+ $p1 = 1200;
+ $d = 100;
+
+ self::assertEquals(0.3, StockBonds::getTotalStockReturn($p0, $p1, $d), '', 0.01);
+ }
+
+ public function testYieldToMaturity()
+ {
+ $c = 100;
+ $f = 1000;
+ $p = 920;
+ $n = 10;
+
+ self::assertEquals(0.1138, StockBonds::getYieldToMaturity($c, $f, $p, $n), '', 0.01);
+ }
+
+ public function testZeroCouponBondValue()
+ {
+ $f = 100;
+ $r = 0.06;
+ $t = 5;
+
+ self::assertEquals(74.73, StockBonds::getZeroCouponBondValue($f, $r, $t), '', 0.01);
+ }
+
+ public function testZeroCouponBondEffectiveYield()
+ {
+ $f = 100;
+ $pv = 90;
+ $n = 5;
+
+ self::assertEquals(0.01517, StockBonds::getZeroCouponBondEffectiveYield($f, $pv, $n), '', 0.01);
+ }
}
diff --git a/tests/Dispatcher/DispatcherTest.php b/tests/Dispatcher/DispatcherTest.php
index d1e5490bb..c382e685f 100644
--- a/tests/Dispatcher/DispatcherTest.php
+++ b/tests/Dispatcher/DispatcherTest.php
@@ -125,4 +125,12 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase
{
$this->app->dispatcher->dispatch('phpOMS\tests\Dispatcher\TestControllers::testFunctionStatic');
}
+
+ /**
+ * @expectedException \UnexpectedValueException
+ */
+ public function testInvalidControllerString()
+ {
+ $this->app->dispatcher->dispatch('phpOMS\tests\Dispatcher\TestController::testFunctionStatic:failure');
+ }
}
diff --git a/tests/Localization/LocalizationTest.php b/tests/Localization/LocalizationTest.php
index 675182597..66b2252db 100644
--- a/tests/Localization/LocalizationTest.php
+++ b/tests/Localization/LocalizationTest.php
@@ -56,6 +56,12 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase
self::assertEquals('.', $localization->getDecimal());
self::assertEquals(',', $localization->getThousands());
self::assertEquals('Y-m-d H:i:s', $localization->getDatetime());
+
+ self::assertEquals([], $localization->getSpeed());
+ self::assertEquals([], $localization->getWeight());
+ self::assertEquals([], $localization->getLength());
+ self::assertEquals([], $localization->getArea());
+ self::assertEquals([], $localization->getVolume());
}
/**
diff --git a/tests/Log/2017-12-23.log b/tests/Log/2017-12-23.log
deleted file mode 100644
index 182523d57..000000000
--- a/tests/Log/2017-12-23.log
+++ /dev/null
@@ -1,2 +0,0 @@
-2017-12-23 06:28:59; error ; 0.0.0.0 ; 30 ; 7.0.5 ; WINNT ; REQUEST_URI; Unhandled error; C:\Users\coyle\Desktop\Orange-ManagementphpOMS\tests\UnhandledHandlerTest.php; [{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\Log\\FileLogger.php","line":353,"function":"interpolate","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\UnhandledHandler.php","line":82,"function":"error","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"function":"errorHandler","class":"phpOMS\\UnhandledHandler","type":"::"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest.php","line":30,"function":"trigger_error"},{"function":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":1071,"function":"invokeArgs","class":"ReflectionMethod","object":{"name":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest"},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":939,"function":"runTest","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestResult.php","line":698,"function":"runBare","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":894,"function":"run","class":"PHPUnit\\Framework\\TestResult","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/TestRunner.php","line":537,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":195,"function":"doRun","class":"PHPUnit\\TextUI\\TestRunner","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":148,"function":"run","class":"PHPUnit\\TextUI\\Command","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpunit.phar","line":566,"function":"main","class":"PHPUnit\\TextUI\\Command","type":"::"}]
-2017-12-23 06:28:59; error ; 0.0.0.0 ; 0 ; 7.0.5 ; WINNT ; REQUEST_URI; Undefined error; ; [{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\Log\\FileLogger.php","line":353,"function":"interpolate","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\UnhandledHandler.php","line":70,"function":"error","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest.php","line":34,"function":"errorHandler","class":"phpOMS\\UnhandledHandler","type":"::"},{"function":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":1071,"function":"invokeArgs","class":"ReflectionMethod","object":{"name":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest"},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":939,"function":"runTest","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestResult.php","line":698,"function":"runBare","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":894,"function":"run","class":"PHPUnit\\Framework\\TestResult","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/TestRunner.php","line":537,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":195,"function":"doRun","class":"PHPUnit\\TextUI\\TestRunner","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":148,"function":"run","class":"PHPUnit\\TextUI\\Command","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpunit.phar","line":566,"function":"main","class":"PHPUnit\\TextUI\\Command","type":"::"}]
diff --git a/tests/Log/2018-01-05.log b/tests/Log/2018-01-05.log
deleted file mode 100644
index d02e25260..000000000
--- a/tests/Log/2018-01-05.log
+++ /dev/null
@@ -1,2 +0,0 @@
-2018-01-05 09:17:52; error ; 0.0.0.0 ; 29 ; 7.0.5 ; WINNT ; REQUEST_URI; Unhandled error; C:\Users\coyle\Desktop\Orange-ManagementphpOMS\tests\UnhandledHandlerTest.php; [{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\Log\\FileLogger.php","line":351,"function":"interpolate","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\UnhandledHandler.php","line":80,"function":"error","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"function":"errorHandler","class":"phpOMS\\UnhandledHandler","type":"::"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest.php","line":29,"function":"trigger_error"},{"function":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":1071,"function":"invokeArgs","class":"ReflectionMethod","object":{"name":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest"},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":939,"function":"runTest","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestResult.php","line":698,"function":"runBare","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":894,"function":"run","class":"PHPUnit\\Framework\\TestResult","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/TestRunner.php","line":537,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":195,"function":"doRun","class":"PHPUnit\\TextUI\\TestRunner","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":148,"function":"run","class":"PHPUnit\\TextUI\\Command","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpunit.phar","line":566,"function":"main","class":"PHPUnit\\TextUI\\Command","type":"::"}]
-2018-01-05 09:17:52; error ; 0.0.0.0 ; 0 ; 7.0.5 ; WINNT ; REQUEST_URI; Undefined error; ; [{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\Log\\FileLogger.php","line":351,"function":"interpolate","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpOMS\\UnhandledHandler.php","line":68,"function":"error","class":"phpOMS\\Log\\FileLogger","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest.php","line":33,"function":"errorHandler","class":"phpOMS\\UnhandledHandler","type":"::"},{"function":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":1071,"function":"invokeArgs","class":"ReflectionMethod","object":{"name":"testErrorHandling","class":"Tests\\PHPUnit\\phpOMS\\UnhandledHandlerTest"},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":939,"function":"runTest","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestResult.php","line":698,"function":"runBare","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestCase.php","line":894,"function":"run","class":"PHPUnit\\Framework\\TestResult","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestCase","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/Framework\/TestSuite.php","line":744,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/TestRunner.php","line":537,"function":"run","class":"PHPUnit\\Framework\\TestSuite","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":195,"function":"doRun","class":"PHPUnit\\TextUI\\TestRunner","object":{},"type":"->"},{"file":"phar:\/\/C:\/Users\/coyle\/Desktop\/Orange-Management\/phpunit.phar\/phpunit\/TextUI\/Command.php","line":148,"function":"run","class":"PHPUnit\\TextUI\\Command","object":{},"type":"->"},{"file":"C:\\Users\\coyle\\Desktop\\Orange-Management\\phpunit.phar","line":566,"function":"main","class":"PHPUnit\\TextUI\\Command","type":"::"}]
diff --git a/tests/Log/FileLoggerTest.php b/tests/Log/FileLoggerTest.php
index 1f82258dc..7b7f2f184 100644
--- a/tests/Log/FileLoggerTest.php
+++ b/tests/Log/FileLoggerTest.php
@@ -55,7 +55,7 @@ class FileLoggerTest extends \PHPUnit\Framework\TestCase
unlink(__DIR__ . '/test.log');
}
- $log = new FileLogger(__DIR__ . '/test.log');
+ $log = new FileLogger(__DIR__ . '/test.log', true);
$log->emergency(FileLogger::MSG_FULL, [
'message' => 'msg',
@@ -124,6 +124,16 @@ class FileLoggerTest extends \PHPUnit\Framework\TestCase
self::assertEquals([5, 6, 7, 8, 9], array_keys($log->get(5, 1)));
self::assertEquals('alert', $log->getByLine(2)['level']);
+ ob_start();
+ $log->console(FileLogger::MSG_FULL, false, [
+ 'message' => 'msg',
+ 'line' => 11,
+ 'file' => FileLoggerTest::class,
+ ]);
+ $ob = ob_get_clean();
+ self::assertEquals(2, $log->countLogs()['info'] ?? 0);
+ self::assertTrue(stripos($ob, 'msg;') !== false);
+
ob_start();
$log->console('test', true);
$ob = ob_get_clean();
@@ -134,6 +144,8 @@ class FileLoggerTest extends \PHPUnit\Framework\TestCase
if (file_exists(__DIR__ . '/' . date('Y-m-d') . '.log')) {
unlink(__DIR__ . '/' . date('Y-m-d') . '.log');
}
+
+ ob_clean();
}
/**
diff --git a/tests/Math/Functions/FunctionsTest.php b/tests/Math/Functions/FunctionsTest.php
index c5d5a625e..f88839b89 100644
--- a/tests/Math/Functions/FunctionsTest.php
+++ b/tests/Math/Functions/FunctionsTest.php
@@ -41,6 +41,7 @@ class FunctionsTest extends \PHPUnit\Framework\TestCase
{
self::assertEquals(4, Functions::invMod(3, -11));
self::assertEquals(12, Functions::invMod(10, 17));
+ self::assertEquals(5, Functions::invMod(-10, 17));
}
public function testAbs()
diff --git a/tests/Math/Geometry/Shape/D2/PolygonTest.php b/tests/Math/Geometry/Shape/D2/PolygonTest.php
index 9236b7f6c..da353025c 100644
--- a/tests/Math/Geometry/Shape/D2/PolygonTest.php
+++ b/tests/Math/Geometry/Shape/D2/PolygonTest.php
@@ -19,16 +19,23 @@ class PolygonTest extends \PHPUnit\Framework\TestCase
{
public function testPoint()
{
- $polygon = new Polygon([
+ $polyArray = [
['x' => 1, 'y' => 1],
['x' => 1, 'y' => 2],
['x' => 2, 'y' => 2],
['x' => 2, 'y' => 1],
- ]);
+ ];
+
+ $polygon = new Polygon($polyArray);
self::assertEquals(-1, $polygon->pointInPolygon(['x' => 1.5, 'y' => 1.5]));
self::assertEquals(1, $polygon->pointInPolygon(['x' => 4.9, 'y' => 1.2]));
self::assertEquals(-1, $polygon->pointInPolygon(['x' => 1.8, 'y' => 1.1]));
+
+ self::assertEquals(-1, Polygon::isPointInPolygon(['x' => 1.5, 'y' => 1.5], $polyArray));
+ self::assertEquals(1, Polygon::isPointInPolygon(['x' => 4.9, 'y' => 1.2], $polyArray));
+ self::assertEquals(0, Polygon::isPointInPolygon(['x' => 1, 'y' => 2], $polyArray));
+ self::assertEquals(-1, Polygon::isPointInPolygon(['x' => 1.8, 'y' => 1.1], $polyArray));
}
public function testAngle()
diff --git a/tests/Message/HeaderAbstractTest.php b/tests/Message/HeaderAbstractTest.php
new file mode 100644
index 000000000..fd1209b18
--- /dev/null
+++ b/tests/Message/HeaderAbstractTest.php
@@ -0,0 +1,59 @@
+header = new class extends HeaderAbstract
+ {
+ public function generate(int $statusCode) /* : void */
+ {
+ }
+
+ public function getProtocolVersion() : string
+ {
+ return '1';
+ }
+
+ public function set(string $key, string $value, bool $overwrite = false) /* : void */
+ {
+
+ }
+
+ public function get(string $key) : array
+ {
+ return [];
+ }
+
+ public function has(string $key) : bool
+ {
+ return true;
+ }
+ };
+ }
+
+ public function testSetGet()
+ {
+ $this->header->setStatusCode(2);
+ self::assertEquals(2, $this->header->getStatusCode());
+ }
+}
diff --git a/tests/Message/Http/HeaderTest.php b/tests/Message/Http/HeaderTest.php
index 831bf763e..339b9250c 100644
--- a/tests/Message/Http/HeaderTest.php
+++ b/tests/Message/Http/HeaderTest.php
@@ -16,6 +16,8 @@ namespace phpOMS\tests\Message\Http;
use phpOMS\Message\Http\Header;
use phpOMS\Localization\Localization;
use phpOMS\Message\Http\RequestStatusCode;
+use phpOMS\DataStorage\LockException;
+use phpOMS\Utils\TestUtils;
class HeaderTest extends \PHPUnit\Framework\TestCase
{
@@ -65,6 +67,38 @@ class HeaderTest extends \PHPUnit\Framework\TestCase
self::AssertEquals(2, $header->getAccount(2));
}
+ /**
+ * @expectedException phpOMS\DataStorage\LockException
+ */
+ public function testLockedHeaderSet()
+ {
+ try {
+ $header = new Header();
+ Header::lock();
+ self::assertTrue(Header::isLocked());
+
+ $header->set('key', 'value');
+ } finally {
+ TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false);
+ }
+ }
+
+ /**
+ * @expectedException phpOMS\DataStorage\LockException
+ */
+ public function testLockedHeaderRemove()
+ {
+ try {
+ $header = new Header();
+ Header::lock();
+ self::assertTrue(Header::isLocked());
+
+ $header->remove('key');
+ } finally {
+ TestUtils::setMember('phpOMS\Message\Http\Header', 'isLocked', false);
+ }
+ }
+
public function testGeneration()
{
$header = new Header();
diff --git a/tests/Message/Http/RequestTest.php b/tests/Message/Http/RequestTest.php
index 9f791346d..6f15f67af 100644
--- a/tests/Message/Http/RequestTest.php
+++ b/tests/Message/Http/RequestTest.php
@@ -45,6 +45,8 @@ class RequestTest extends \PHPUnit\Framework\TestCase
self::assertInstanceOf('\phpOMS\Message\Http\Header', $request->getHeader());
self::assertInstanceOf('\phpOMS\Message\Http\Request', Request::createFromSuperglobals());
self::assertEquals('http://', $request->__toString());
+ self::assertFalse($request->hasData('key'));
+ self::assertEquals(null, $request->getData('key'));
}
public function testSetGet()
@@ -84,6 +86,7 @@ class RequestTest extends \PHPUnit\Framework\TestCase
self::assertTrue($request->setData('key', 'value'));
self::assertFalse($request->setData('key', 'value2', false));
self::assertEquals('value', $request->getData('key'));
+ self::assertTrue($request->hasData('key'));
self::assertEquals(['key' => 'value'], $request->getData());
$request->setRequestSource(RequestSource::SOCKET);
@@ -112,4 +115,14 @@ class RequestTest extends \PHPUnit\Framework\TestCase
$request = new Request(new Http('http://www.google.com/test/path'));
$request->isHttps(-1);
}
+
+ /**
+ * @expectedException \Exception
+ */
+ public function testInvalidRouteVerb()
+ {
+ $request = new Request(new Http('http://www.google.com/test/path'));
+ $request->setMethod('failure');
+ $request->getRouteVerb();
+ }
}
diff --git a/tests/Message/ResponseAbstractTest.php b/tests/Message/ResponseAbstractTest.php
new file mode 100644
index 000000000..0d6fb6bfc
--- /dev/null
+++ b/tests/Message/ResponseAbstractTest.php
@@ -0,0 +1,53 @@
+response = new class extends ResponseAbstract
+ {
+ public function toArray() : array
+ {
+ return [1];
+ }
+
+ public function getBody() : string
+ {
+ return '';
+ }
+ };
+ }
+
+ public function testDefault()
+ {
+ self::assertEquals(null, $this->response->get('asdf'));
+ self::assertEquals('', $this->response->getBody());
+ }
+
+ public function testSetGet()
+ {
+ self::assertEquals([1], $this->response->jsonSerialize());
+
+ $this->response->set('asdf', false);
+ self::assertEquals(false, $this->response->get('asdf'));
+ }
+}
diff --git a/tests/Model/Html/HeadTest.php b/tests/Model/Html/HeadTest.php
index 82935e075..70c8cc551 100644
--- a/tests/Model/Html/HeadTest.php
+++ b/tests/Model/Html/HeadTest.php
@@ -14,6 +14,7 @@
namespace phpOMS\tests\Model\Html;
use phpOMS\Model\Html\Head;
+use phpOMS\Asset\AssetType;
class HeadTest extends \PHPUnit\Framework\TestCase
{
@@ -31,4 +32,36 @@ class HeadTest extends \PHPUnit\Framework\TestCase
self::assertEquals('', $head->renderAssetsLate());
self::assertEquals('', $head->render());
}
+
+ public function testSetGet()
+ {
+ $head = new Head();
+
+ $head->setTitle('my title');
+ self::assertEquals('my title', $head->getTitle());
+
+ $head->addAsset(AssetType::CSS, '/path/styles.css');
+ $head->addAsset(AssetType::JS, '/path/logic.js');
+ $head->addAsset(AssetType::JSLATE, '/path/late.js');
+
+ $head->setStyle('base', '#test .class { color: #000; }');
+ self::assertEquals(['base' => '#test .class { color: #000; }'], $head->getStyleAll());
+
+ $head->setScript('key', 'console.log("msg");');
+ self::assertEquals(['key' => 'console.log("msg");'], $head->getScriptAll());
+
+ $head->setLanguage('en');
+ self::assertEquals('en', $head->getLanguage());
+
+ self::assertEquals(
+ ''
+ . ''
+ . ''
+ . ''
+ . '',
+ $head->render()
+ );
+
+ self::assertEquals('', $head->renderAssetsLate());
+ }
}
diff --git a/tests/Model/Html/MetaTest.php b/tests/Model/Html/MetaTest.php
index c52baaf96..525515b79 100644
--- a/tests/Model/Html/MetaTest.php
+++ b/tests/Model/Html/MetaTest.php
@@ -26,4 +26,21 @@ class MetaTest extends \PHPUnit\Framework\TestCase
self::assertEquals([], $meta->getKeywords());
self::assertEquals('', $meta->render());
}
+
+ public function testGetSet()
+ {
+ $meta = new Meta();
+
+ $meta->addKeyword('orange');
+ self::assertEquals(['orange'], $meta->getKeywords());
+
+ $meta->setAuthor('oms');
+ self::assertEquals('oms', $meta->getAuthor());
+
+ $meta->setCharset('utf-8');
+ self::assertEquals('utf-8', $meta->getCharset());
+
+ $meta->setDescription('some description');
+ self::assertEquals('some description', $meta->getDescription());
+ }
}
diff --git a/tests/Module/InfoManagerTest.php b/tests/Module/InfoManagerTest.php
index 53d5e3c49..f496905cb 100644
--- a/tests/Module/InfoManagerTest.php
+++ b/tests/Module/InfoManagerTest.php
@@ -21,10 +21,10 @@ class InfoManagerTest extends \PHPUnit\Framework\TestCase
{
public function testInfoManager()
{
- $info = new InfoManager(__Dir__ . '/info-test.json');
+ $info = new InfoManager(__DIR__ . '/info-test.json');
$info->load();
- $jarray = json_decode(file_get_contents(__Dir__ . '/info-test.json'), true);
+ $jarray = json_decode(file_get_contents(__DIR__ . '/info-test.json'), true);
self::assertEquals($jarray, $info->get());
self::assertEquals($jarray['name']['internal'], $info->getInternalName());
@@ -35,12 +35,13 @@ class InfoManagerTest extends \PHPUnit\Framework\TestCase
self::assertEquals($jarray['directory'], $info->getDirectory());
self::assertEquals($jarray['version'], $info->getVersion());
self::assertEquals($jarray['load'], $info->getLoad());
+ self::assertEquals(__DIR__ . '/info-test.json', $info->getPath());
$info->set('/name/internal', 'ABC');
self::assertEquals('ABC', $info->getInternalName());
$info->update();
- $info2 = new InfoManager(__Dir__ . '/info-test.json');
+ $info2 = new InfoManager(__DIR__ . '/info-test.json');
$info2->load();
self::assertEquals($info->getInternalName(), $info2->getInternalName());
@@ -53,7 +54,7 @@ class InfoManagerTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidPathLoad()
{
- $info = new InfoManager(__Dir__ . '/invalid.json');
+ $info = new InfoManager(__DIR__ . '/invalid.json');
$info->load();
}
@@ -62,7 +63,7 @@ class InfoManagerTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidPathUpdate()
{
- $info = new InfoManager(__Dir__ . '/invalid.json');
+ $info = new InfoManager(__DIR__ . '/invalid.json');
$info->update();
}
@@ -71,7 +72,7 @@ class InfoManagerTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidDataSet()
{
- $info = new InfoManager(__Dir__ . '/info-test.json');
+ $info = new InfoManager(__DIR__ . '/info-test.json');
$info->load();
$testObj = new class {
diff --git a/tests/Router/RouterTest.php b/tests/Router/RouterTest.php
index 6e6ab5a80..514fc9d5e 100644
--- a/tests/Router/RouterTest.php
+++ b/tests/Router/RouterTest.php
@@ -75,4 +75,13 @@ class RouterTest extends \PHPUnit\Framework\TestCase
$router->route('http://test.com/backends/admin/settings/general/something?test', RouteVerb::GET)
);
}
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testInvalidRequestType()
+ {
+ $router = new Router();
+ $router->route([]);
+ }
}
diff --git a/tests/Security/PhpCodeTest.php b/tests/Security/PhpCodeTest.php
new file mode 100644
index 000000000..218705cd9
--- /dev/null
+++ b/tests/Security/PhpCodeTest.php
@@ -0,0 +1,65 @@
+getRepository());
self::assertInstanceOf('\DateTime', $commit->getDate());
}
+
+ public function testGetSet()
+ {
+ $commit = new Commit();
+
+ self::assertTrue($commit->addFile('/some/file/path'));
+ self::assertFalse($commit->addFile('/some/file/path'));
+ self::assertTrue($commit->addFile('/some/file/path2'));
+ self::assertEquals([
+ '/some/file/path' => [],
+ '/some/file/path2' => []
+ ], $commit->getFiles());
+
+ self::assertFalse($commit->removeFile('/some/file/path3'));
+ self::assertTrue($commit->removeFile('/some/file/path'));
+ self::assertEquals([
+ '/some/file/path2' => []
+ ], $commit->getFiles());
+
+ $commit->setMessage('My Message');
+ self::assertEquals('My Message', $commit->getMessage());
+
+ $commit->setAuthor(new Author('Orange'));
+ self::assertEquals('Orange', $commit->getAuthor()->getName());
+
+ $commit->setBranch(new Branch('develop'));
+ self::assertEquals('develop', $commit->getBranch()->getName());
+
+ $commit->setTag(new Tag('1.0.0'));
+ self::assertEquals('1.0.0', $commit->getTag()->getName());
+
+ $commit->setDate($date = new \DateTime('now'));
+ self::assertEquals($date->format('Y-m-d'), $commit->getDate()->format('Y-m-d'));
+
+ $commit->setRepository(new Repository(realpath(__DIR__ . '/../../../')));
+ self::assertEquals(realpath(__DIR__ . '/../../../'), $commit->getRepository()->getPath());
+ }
}
diff --git a/tests/Utils/Git/RepositoryTest.php b/tests/Utils/Git/RepositoryTest.php
index fc46249dd..f4aaf26b9 100644
--- a/tests/Utils/Git/RepositoryTest.php
+++ b/tests/Utils/Git/RepositoryTest.php
@@ -22,5 +22,6 @@ class RepositoryTest extends \PHPUnit\Framework\TestCase
$repo = new Repository(realpath(__DIR__ . '/../../../'));
self::assertTrue('phpOMS' === $repo->getName() || 'build' === $repo->getName());
self::assertEquals(str_replace('\\', '/', realpath(__DIR__ . '/../../../.git')), str_replace('\\', '/', $repo->getDirectoryPath()));
+ self::assertEquals(realpath(__DIR__ . '/../../../'), $repo->getPath());
}
}
diff --git a/tests/Validation/ValidatorTest.php b/tests/Validation/ValidatorTest.php
index 2ebbe2c6a..8f46b3485 100644
--- a/tests/Validation/ValidatorTest.php
+++ b/tests/Validation/ValidatorTest.php
@@ -39,5 +39,15 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
Validator::resetError();
self::assertEquals('', Validator::getMessage());
self::assertEquals(0, Validator::getErrorCode());
+
+ self::assertTrue(Validator::isValid('testVar'));
+ self::assertTrue(Validator::isValid('value', ['\is_string' => []]));
+ self::assertFalse(Validator::isValid('value', ['\is_stringNot' => []]));
+ self::assertTrue(Validator::isValid('value', ['phpOMS\Validation\Validator::hasLength' => [4]]));
+
+ self::assertTrue(Validator::matches('ThisTestVar', '/.*/'));
+ self::assertFalse(Validator::matches('ThisTestVar', '/.*\d+/'));
+ self::assertTrue(Validator::matches('ThisTestVar', '/TestVar/'));
+ self::assertFalse(Validator::matches('ThisTestVar', '/ThisTest$/'));
}
}
diff --git a/tests/Views/ViewTest.php b/tests/Views/ViewTest.php
index e3fde04bc..a3c360d40 100644
--- a/tests/Views/ViewTest.php
+++ b/tests/Views/ViewTest.php
@@ -22,6 +22,7 @@ use phpOMS\Message\Http\Request;
use phpOMS\Message\Http\Response;
use phpOMS\Uri\Http;
use phpOMS\Views\View;
+use phpOMS\Views\ViewAbstract;
use phpOMS\Localization\L11nManager;
class ViewTest extends \PHPUnit\Framework\TestCase
@@ -60,7 +61,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
public function testGetText()
{
- $view = new View($this->app, $request = new Request(new Http('')), $response = new Response(new Localization()));
+ $view = new View($this->app, $request = new Request(new Http('')), $response = new Response());
$view->setTemplate('/Modules/Admin/Theme/Backend/accounts-list');
$expected = [
@@ -80,7 +81,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
public function testGetSet()
{
- $view = new View($this->app, $request = new Request(new Http('')), $response = new Response(new Localization()));
+ $view = new View($this->app, $request = new Request(new Http('')), $response = new Response());
$view->setData('key', 'value');
self::assertEquals('value', $view->getData('key'));
@@ -96,6 +97,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
self::assertEquals($response, $view->getResponse());
self::assertEquals('<a href="test">Test</a>', $view->printHtml('Test'));
+ self::assertEquals('<a href="test">Test</a>', ViewAbstract::html('Test'));
$tView = new View($this->app, $request, $response);
self::assertTrue($view->addView('test', $tView));
@@ -108,7 +110,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
public function testRender()
{
- $view = new View($this->app, new Request(), new Response(new Localization()));
+ $view = new View($this->app, new Request(), new Response());
$view->setTemplate('/phpOMS/tests/Views/testTemplate');
self::assertEquals('Test', $view->render());
@@ -123,7 +125,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
*/
public function testRenderException()
{
- $view = new View($this->app, new Request(new Http('')), new Response(new Localization()));
+ $view = new View($this->app, new Request(new Http('')), new Response());
$view->setTemplate('something.txt');
$view->render();
@@ -134,7 +136,7 @@ class ViewTest extends \PHPUnit\Framework\TestCase
*/
public function testSerializeException()
{
- $view = new View($this->app, new Request(new Http('')), new Response(new Localization()));
+ $view = new View($this->app, new Request(new Http('')), new Response());
$view->setTemplate('something.txt');
$view->serialize();