diff --git a/Algorithm/PathFinding/JumpPointSearch.php b/Algorithm/PathFinding/JumpPointSearch.php index f8ce3f9d8..239c50e19 100644 --- a/Algorithm/PathFinding/JumpPointSearch.php +++ b/Algorithm/PathFinding/JumpPointSearch.php @@ -537,7 +537,7 @@ final class JumpPointSearch implements PathFinderInterface return $node; } } else { - throw new \Exception('invalid movement'); + throw new \Exception('invalid movement'); // @codeCoverageIgnore } return self::jumpStraight($grid->getNode($x + $dx, $y + $dy), $node, $endNode, $grid); diff --git a/Algorithm/PathFinding/Path.php b/Algorithm/PathFinding/Path.php index c3ced26b7..732f9666b 100644 --- a/Algorithm/PathFinding/Path.php +++ b/Algorithm/PathFinding/Path.php @@ -209,7 +209,7 @@ class Path $node = $this->grid->getNode($x0, $y0); if ($node === null) { - break; + break; // @codeCoverageIgnore } } diff --git a/Autoloader.php b/Autoloader.php index 4b4da968c..f98f5275a 100644 --- a/Autoloader.php +++ b/Autoloader.php @@ -127,8 +127,9 @@ final class Autoloader */ public static function invalidate(string $class) : bool { - if (!\extension_loaded('opcache') + if (!\extension_loaded('zend opcache') || !\opcache_is_script_cached($class) + || \opcache_get_status() === false ) { return false; } diff --git a/Dispatcher/Dispatcher.php b/Dispatcher/Dispatcher.php index f28a78223..f98e011cf 100644 --- a/Dispatcher/Dispatcher.php +++ b/Dispatcher/Dispatcher.php @@ -68,8 +68,11 @@ final class Dispatcher implements DispatcherInterface if (\is_array($controller)) { if (isset($controller['dest'])) { - if (!empty($data) && !empty($controller['data'])) { - $data = \array_merge($data, $controller['data']); + if (!empty($controller['data'])) { + $data = \array_merge( + empty($data) ? [] : $data, + \is_array($controller['data']) ? $controller['data'] : [$controller['data']] + ); } $controller = $controller['dest']; diff --git a/Math/Matrix/CholeskyDecomposition.php b/Math/Matrix/CholeskyDecomposition.php index f6f5c2919..deb25f092 100644 --- a/Math/Matrix/CholeskyDecomposition.php +++ b/Math/Matrix/CholeskyDecomposition.php @@ -7,6 +7,7 @@ * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @version 1.0.0 * @link https://orange-management.org */ @@ -23,6 +24,7 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; * * @package phpOMS\Math\Matrix * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @link https://orange-management.org * @since 1.0.0 */ diff --git a/Math/Matrix/EigenvalueDecomposition.php b/Math/Matrix/EigenvalueDecomposition.php index 95d02f53e..32124a6c1 100644 --- a/Math/Matrix/EigenvalueDecomposition.php +++ b/Math/Matrix/EigenvalueDecomposition.php @@ -7,6 +7,7 @@ * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @version 1.0.0 * @link https://orange-management.org */ @@ -24,6 +25,7 @@ use phpOMS\Math\Geometry\Shape\D2\Triangle; * * @package phpOMS\Math\Matrix * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @link https://orange-management.org * @since 1.0.0 */ diff --git a/Math/Matrix/LUDecomposition.php b/Math/Matrix/LUDecomposition.php index 4c9b06530..4944a57f0 100644 --- a/Math/Matrix/LUDecomposition.php +++ b/Math/Matrix/LUDecomposition.php @@ -7,6 +7,7 @@ * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @version 1.0.0 * @link https://orange-management.org */ @@ -23,6 +24,7 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; * * @package phpOMS\Math\Matrix * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @link https://orange-management.org * @since 1.0.0 */ diff --git a/Math/Matrix/QRDecomposition.php b/Math/Matrix/QRDecomposition.php index dd0add4d5..8f7e592fc 100644 --- a/Math/Matrix/QRDecomposition.php +++ b/Math/Matrix/QRDecomposition.php @@ -7,6 +7,7 @@ * @package phpOMS\Math\Matrix * @copyright Dennis Eichhorn * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @version 1.0.0 * @link https://orange-management.org */ @@ -24,6 +25,7 @@ use phpOMS\Math\Matrix\Exception\InvalidDimensionException; * * @package phpOMS\Math\Matrix * @license OMS License 1.0 + * @license JAMA - https://math.nist.gov/javanumerics/jama/ * @link https://orange-management.org * @since 1.0.0 */ diff --git a/Math/Parser/Evaluator.php b/Math/Parser/Evaluator.php index 4544ad6f1..f8cf2ef3a 100644 --- a/Math/Parser/Evaluator.php +++ b/Math/Parser/Evaluator.php @@ -109,7 +109,7 @@ final class Evaluator $equation = \preg_split('/([\+\-\*\/\^\(\)])/', $equation, -1, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); if ($equation === false) { - return []; + return []; // @codeCoverageIgnore } $equation = \array_filter($equation, function($n) { diff --git a/Message/HeaderAbstract.php b/Message/HeaderAbstract.php index 6457343cb..551ccbcb5 100644 --- a/Message/HeaderAbstract.php +++ b/Message/HeaderAbstract.php @@ -156,7 +156,6 @@ abstract class HeaderAbstract public function setStatusCode(int $status) : void { $this->status = $status; - $this->generate($status); } /** diff --git a/Stdlib/Queue/PriorityQueue.php b/Stdlib/Queue/PriorityQueue.php index 2153ec1c9..c1088d35e 100644 --- a/Stdlib/Queue/PriorityQueue.php +++ b/Stdlib/Queue/PriorityQueue.php @@ -122,7 +122,7 @@ class PriorityQueue implements \Countable, \Serializable case PriorityMode::LOWEST: return $this->getInsertLowest($priority); default: - throw new InvalidEnumValue($this->type); + throw new InvalidEnumValue($this->type); // @codeCoverageIgnore } } diff --git a/System/File/Local/File.php b/System/File/Local/File.php index 17465bd5d..e6e4e1959 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -444,7 +444,7 @@ final class File extends FileAbstract implements FileInterface, LocalContainerIn } if (!\is_writable(\dirname($path))) { - return false; + return false; // @codeCoverageIgnore } \touch($path); diff --git a/System/SystemUtils.php b/System/SystemUtils.php index 366cdf90f..dcb310888 100644 --- a/System/SystemUtils.php +++ b/System/SystemUtils.php @@ -54,7 +54,7 @@ final class SystemUtils $fh = \fopen('/proc/meminfo', 'r'); if ($fh === false) { - return $mem; + return $mem; // @codeCoverageIgnore } while ($line = \fgets($fh)) { @@ -86,7 +86,7 @@ final class SystemUtils $free = \shell_exec('free'); if ($free === null) { - return $memUsage; + return $memUsage; // @codeCoverageIgnore } $free = \trim($free); diff --git a/Uri/HttpUri.php b/Uri/HttpUri.php index 7f23e1300..21d28b1f6 100644 --- a/Uri/HttpUri.php +++ b/Uri/HttpUri.php @@ -214,6 +214,7 @@ final class HttpUri implements UriInterface * @return string Returns the current uri * * @since 1.0.0 + * @codeCoverageIgnore */ public static function getCurrent() : string { @@ -230,6 +231,7 @@ final class HttpUri implements UriInterface * @return HttpUri Returns the current uri * * @since 1.0.0 + * @codeCoverageIgnore */ public static function fromCurrent() : self { diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index ff27ce57e..0169470ca 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -201,9 +201,8 @@ final class UriFactory /** @var array $urlStructure */ $urlStructure = \parse_url($url); - if ($urlStructure === false) { - return $url; + return $url; // @codeCoverageIgnore } if (isset($urlStructure['query'])) { diff --git a/Utils/Barcode/C128Abstract.php b/Utils/Barcode/C128Abstract.php index 4ae70e499..5d42f695b 100644 --- a/Utils/Barcode/C128Abstract.php +++ b/Utils/Barcode/C128Abstract.php @@ -327,7 +327,7 @@ abstract class C128Abstract $image = \imagecreate($dimensions['width'], $dimensions['height']); if ($image === false) { - throw new \Exception(); + throw new \Exception(); // @codeCoverageIgnore } $black = \imagecolorallocate($image, 0, 0, 0); diff --git a/Utils/Encoding/Huffman/Huffman.php b/Utils/Encoding/Huffman/Huffman.php index 22a996b6d..5af4a5b1b 100644 --- a/Utils/Encoding/Huffman/Huffman.php +++ b/Utils/Encoding/Huffman/Huffman.php @@ -86,7 +86,7 @@ final class Huffman $binary = ''; if ($splittedBinaryString === false) { - return $binary; + return $binary; // @codeCoverageIgnore } foreach ($splittedBinaryString as $i => $c) { diff --git a/Utils/IO/Zip/Gz.php b/Utils/IO/Zip/Gz.php index 8a6462363..113ca159b 100644 --- a/Utils/IO/Zip/Gz.php +++ b/Utils/IO/Zip/Gz.php @@ -32,14 +32,14 @@ class Gz implements ArchiveInterface public static function pack($source, string $destination, bool $overwrite = false) : bool { $destination = \str_replace('\\', '/', $destination); - if (!$overwrite && \file_exists($destination)) { + if (!$overwrite && \file_exists($destination) || !\file_exists($source)) { return false; } $gz = \gzopen($destination, 'w'); $src = \fopen($source, 'r'); if ($gz === false || $src === false) { - return false; + return false; // @codeCoverageIgnore } while (!\feof($src)) { @@ -65,7 +65,7 @@ class Gz implements ArchiveInterface $gz = \gzopen($source, 'r'); $dest = \fopen($destination, 'w'); if ($gz === false || $dest === false) { - return false; + return false; // @codeCoverageIgnore } while (!\gzeof($gz)) { diff --git a/Utils/IO/Zip/TarGz.php b/Utils/IO/Zip/TarGz.php index cfaf3ab43..fe0da5e4e 100644 --- a/Utils/IO/Zip/TarGz.php +++ b/Utils/IO/Zip/TarGz.php @@ -33,7 +33,8 @@ class TarGz implements ArchiveInterface */ public static function pack($source, string $destination, bool $overwrite = false) : bool { - if (!$overwrite && \file_exists($destination)) { + $destination = \str_replace('\\', '/', $destination); + if (!$overwrite && \file_exists($destination) || !\file_exists($source)) { return false; } @@ -52,7 +53,8 @@ class TarGz implements ArchiveInterface */ public static function unpack(string $source, string $destination) : bool { - if (!\file_exists($source)) { + $destination = \str_replace('\\', '/', $destination); + if (\file_exists($destination) || !\file_exists($source)) { return false; } diff --git a/Utils/MbStringUtils.php b/Utils/MbStringUtils.php index 008d3ffe6..f3d3b09ad 100644 --- a/Utils/MbStringUtils.php +++ b/Utils/MbStringUtils.php @@ -299,7 +299,7 @@ final class MbStringUtils $encodedPos = \strpos($lastChunk, '='); if ($encodedPos === false) { - break; + break; // @codeCoverageIgnore } $hex = \substr($text, $length - $reset + $encodedPos + 1, 2); diff --git a/Utils/StringCompare.php b/Utils/StringCompare.php index a6a437ae5..f17ee1b9b 100644 --- a/Utils/StringCompare.php +++ b/Utils/StringCompare.php @@ -105,7 +105,7 @@ final class StringCompare $total = 0; if ($words1 === false || $words2 === false) { - return \PHP_INT_MAX; + return \PHP_INT_MAX; // @codeCoverageIgnore } foreach ($words1 as $word1) { diff --git a/Views/View.php b/Views/View.php index 3e961124d..2f572aaa3 100644 --- a/Views/View.php +++ b/Views/View.php @@ -246,7 +246,7 @@ class View extends ViewAbstract $this->module = \substr($this->template, $start, $end - $start); if ($this->module === false) { - $this->module = '0'; + $this->module = '0'; // @codeCoverageIgnore } } @@ -274,7 +274,7 @@ class View extends ViewAbstract $this->theme = \substr($this->template, $start, $end - $start); if ($this->theme === false) { - $this->theme = '0'; + $this->theme = '0'; // @codeCoverageIgnore } } diff --git a/tests/AutoloaderTest.php b/tests/AutoloaderTest.php index 47f56355e..22aa82015 100644 --- a/tests/AutoloaderTest.php +++ b/tests/AutoloaderTest.php @@ -54,14 +54,20 @@ class AutoloaderTest extends \PHPUnit\Framework\TestCase public function testOpcodeCacheInvalidation() : void { - if (!\extension_loaded('opcache')) { + if (!\extension_loaded('zend opcache') + || \ini_get('opcache.enable') !== '1' + || \ini_get('opcache.enable_cli') !== '1' + || \ini_get('opcache.file_cache_only') !== '0' + || \opcache_get_status() === false + ) { $this->markTestSkipped( 'The opcache extension is not available.' ); } + self::assertFalse(\opcache_is_script_cached(__DIR__ . '/TestLoad3.php')); Autoloader::defaultAutoloader('\phpOMS\tests\TestLoad3'); - Autoloader::invalidate(__DIR__ . '/TestLoad3.php'); + self::assertTrue(Autoloader::invalidate(__DIR__ . '/TestLoad3.php')); self::assertTrue(\opcache_is_script_cached(__DIR__ . '/TestLoad3.php')); } diff --git a/tests/Dispatcher/DispatcherTest.php b/tests/Dispatcher/DispatcherTest.php index c7642bb5d..dbbfca987 100644 --- a/tests/Dispatcher/DispatcherTest.php +++ b/tests/Dispatcher/DispatcherTest.php @@ -161,7 +161,7 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase !empty( $this->app->dispatcher->dispatch( [ - function($req, $resp, $data = null) { return true; }, + function($app, $req, $resp, $data = null) { return true; }, 'phpOMS\tests\Dispatcher\TestController:testFunction', 'phpOMS\tests\Dispatcher\TestController::testFunctionStatic', ], @@ -172,6 +172,22 @@ class DispatcherTest extends \PHPUnit\Framework\TestCase ); } + public function testArrayWithData() : void + { + $localization = new Localization(); + + self::assertEquals([2], + $this->app->dispatcher->dispatch( + [ + 'dest' => function($app, $req, $resp, $data = null) { return $data; }, + 'data' => 2 + ], + new HttpRequest(new HttpUri(''), $localization), + new HttpResponse($localization) + ) + ); + } + /** * @testdox A invalid destination type throws UnexpectedValueException * @covers phpOMS\Dispatcher\Dispatcher diff --git a/tests/Math/Matrix/EigenvalueDecompositionTest.php b/tests/Math/Matrix/EigenvalueDecompositionTest.php index 8681e5324..b7c92567c 100644 --- a/tests/Math/Matrix/EigenvalueDecompositionTest.php +++ b/tests/Math/Matrix/EigenvalueDecompositionTest.php @@ -254,4 +254,44 @@ class EigenvalueDecompositionTest extends \PHPUnit\Framework\TestCase self::assertEqualsWithDelta([1, 1], $eig->getRealEigenvalues()->toArray(), 0.1); self::assertEqualsWithDelta([2, -2], $eig->getImagEigenvalues()->toArray(), 0.1); } + + public function testComplexDivision() : void + { + $A = new Matrix(); + $A->setMatrix([ + [-2, -4, 2], + [3, 1, -4], + [4, 5, 5], + ]); + + $eig = new EigenvalueDecomposition($A); + self::assertEqualsWithDelta([ + [-0.3569, 4.49865, 0.0], + [-4.49865, -0.3569, 0], + [0.0, 0.0, 4.7139], + ], $eig->getD()->toArray(), 0.1); + + self::assertEqualsWithDelta([-0.35695, -0.35695, 4.7139], $eig->getRealEigenvalues()->toArray(), 0.1); + self::assertEqualsWithDelta([4.49865, -4.49865, 0.0], $eig->getImagEigenvalues()->toArray(), 0.1); + } + + public function testComplexDivision2() : void + { + $A = new Matrix(); + $A->setMatrix([ + [-2, 3, 2], + [-4, 1, -4], + [4, 5, 5], + ]); + + $eig = new EigenvalueDecomposition($A); + self::assertEqualsWithDelta([ + [-2.5510, 0.0, 0.0], + [0.0, 3.27552, 4.79404], + [0.0, -4.7940, 3.27552], + ], $eig->getD()->toArray(), 0.1); + + self::assertEqualsWithDelta([-2.5510, 3.27552, 3.27552], $eig->getRealEigenvalues()->toArray(), 0.1); + self::assertEqualsWithDelta([0.0, 4.7940, -4.7940], $eig->getImagEigenvalues()->toArray(), 0.1); + } } diff --git a/tests/Math/Statistic/MeasureOfDispersionTest.php b/tests/Math/Statistic/MeasureOfDispersionTest.php index 30eb25369..311a95d96 100644 --- a/tests/Math/Statistic/MeasureOfDispersionTest.php +++ b/tests/Math/Statistic/MeasureOfDispersionTest.php @@ -198,4 +198,11 @@ class MeasureOfDispersionTest extends \PHPUnit\Framework\TestCase MeasureOfDispersion::empiricalVariance([]); } + + public function testInvalidSampleCovarianceDimension() : void + { + $this->expectException(\phpOMS\Math\Exception\ZeroDivisionException::class); + + MeasureOfDispersion::sampleCovariance([], []); + } } diff --git a/tests/Utils/Git/TagTest.php b/tests/Utils/Git/TagTest.php index cb942aeab..0fd42e98e 100644 --- a/tests/Utils/Git/TagTest.php +++ b/tests/Utils/Git/TagTest.php @@ -25,7 +25,7 @@ class TagTest extends \PHPUnit\Framework\TestCase { /** * @testdox The tag has the expected default values after initialization - * @covers phpOMS\Utils\Git\Repository + * @covers phpOMS\Utils\Git\Tag * @group framework */ public function testDefault() : void @@ -37,7 +37,7 @@ class TagTest extends \PHPUnit\Framework\TestCase /** * @testdox The tag name can be set during initialization and returned - * @covers phpOMS\Utils\Git\Repository + * @covers phpOMS\Utils\Git\Tag * @group framework */ public function testConstructorInputOutput() : void @@ -48,7 +48,7 @@ class TagTest extends \PHPUnit\Framework\TestCase /** * @testdox The message can be set and returned - * @covers phpOMS\Utils\Git\Repository + * @covers phpOMS\Utils\Git\Tag * @group framework */ public function testMessageInputOutput() : void diff --git a/tests/Utils/IO/Zip/TarTest.php b/tests/Utils/IO/Zip/TarTest.php index 786a3c6b5..d54b81eb2 100644 --- a/tests/Utils/IO/Zip/TarTest.php +++ b/tests/Utils/IO/Zip/TarTest.php @@ -44,6 +44,7 @@ class TarTest extends \PHPUnit\Framework\TestCase __DIR__ . '/test a.txt' => 'test a.txt', __DIR__ . '/test b.md' => 'test b.md', __DIR__ . '/test' => 'test', + __DIR__ . '/invalid.txt', ], __DIR__ . '/test.tar' )); diff --git a/tests/Utils/IO/Zip/ZipTest.php b/tests/Utils/IO/Zip/ZipTest.php index 937d9b6d9..1657c9c90 100644 --- a/tests/Utils/IO/Zip/ZipTest.php +++ b/tests/Utils/IO/Zip/ZipTest.php @@ -45,6 +45,7 @@ class ZipTest extends \PHPUnit\Framework\TestCase __DIR__ . '/test b.md' => 'test b.md', __DIR__ . '/invalid.so' => 'invalid.so', __DIR__ . '/test' => 'test', + __DIR__ . '/invalid.txt', ], __DIR__ . '/test.zip' ));