mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
improve tests
This commit is contained in:
parent
f7c5233d28
commit
58c49080c8
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ class Path
|
|||
$node = $this->grid->getNode($x0, $y0);
|
||||
|
||||
if ($node === null) {
|
||||
break;
|
||||
break; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'];
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -156,7 +156,6 @@ abstract class HeaderAbstract
|
|||
public function setStatusCode(int $status) : void
|
||||
{
|
||||
$this->status = $status;
|
||||
$this->generate($status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ final class File extends FileAbstract implements FileInterface, LocalContainerIn
|
|||
}
|
||||
|
||||
if (!\is_writable(\dirname($path))) {
|
||||
return false;
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
\touch($path);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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'])) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ final class Huffman
|
|||
$binary = '';
|
||||
|
||||
if ($splittedBinaryString === false) {
|
||||
return $binary;
|
||||
return $binary; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
foreach ($splittedBinaryString as $i => $c) {
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ final class MbStringUtils
|
|||
$encodedPos = \strpos($lastChunk, '=');
|
||||
|
||||
if ($encodedPos === false) {
|
||||
break;
|
||||
break; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$hex = \substr($text, $length - $reset + $encodedPos + 1, 2);
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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([], []);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
));
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user