fix tests

This commit is contained in:
Dennis Eichhorn 2020-11-28 19:26:40 +01:00
parent 1ed4f3f5e2
commit 6443ab6c14
11 changed files with 35 additions and 39 deletions

View File

@ -761,12 +761,13 @@ class DataMapperAbstract implements DataMapperInterface
$values = $property->getValue($obj);
/** @var self $mapper */
$mapper = static::$hasMany[$propertyName]['mapper'];
$mapper = static::$hasMany[$propertyName]['mapper'];
$internalName = isset($mapper::$columns[static::$hasMany[$propertyName]['self']]) ? $mapper::$columns[static::$hasMany[$propertyName]['self']]['internal'] : 'ERROR';
if (\is_object($values)) {
// conditionals
$relReflectionClass = new \ReflectionClass($values);
$relProperty = $relReflectionClass->getProperty($mapper::$columns[static::$hasMany[$propertyName]['self']]['internal']);
$relProperty = $relReflectionClass->getProperty($internalName);
if (!($isPublicRel = $relProperty->isPublic())) {
$relProperty->setAccessible(true);
@ -779,10 +780,17 @@ class DataMapperAbstract implements DataMapperInterface
}
$mapper::create($values);
continue;
}
if (!\is_array($values)) {
if (!$isPublic) {
$property->setAccessible(false);
}
continue;
} elseif (!\is_array($values)) {
if (!$isPublic) {
$property->setAccessible(false);
}
// conditionals
continue;
}
@ -814,13 +822,20 @@ class DataMapperAbstract implements DataMapperInterface
// Setting relation value (id) for relation (since the relation is not stored in an extra relation table)
if (!isset(static::$hasMany[$propertyName]['external'])) {
$relProperty = $relReflectionClass->getProperty($mapper::$columns[static::$hasMany[$propertyName]['self']]['internal']);
$relProperty = $relReflectionClass->getProperty($internalName);
if (!$isPublic) {
$relProperty->setAccessible(true);
}
$relProperty->setValue($value, $objId);
// todo maybe consider to just set the column type to object, and then check for that (might be faster)
if (isset($mapper::$belongsTo[$internalName])
|| isset($mapper::$ownsOne[$internalName])
) {
$relProperty->setValue($value, self::createNullModel($objId));
} else {
$relProperty->setValue($value, $objId);
}
if (!$isPublic) {
$relProperty->setAccessible(false);
@ -3464,14 +3479,7 @@ class DataMapperAbstract implements DataMapperInterface
$parts[$c] = 'Null' . $name;
$class = \implode('\\', $parts);
$obj = new $class();
if ($id !== null) {
$refClass = new \ReflectionClass($obj);
self::setObjectId($refClass, $obj, $id);
}
return $obj;
return $id !== null ? new $class($id) : new $class();
}
/**

View File

@ -273,7 +273,7 @@ class Localization implements \JsonSerializable
return;
}
$fileContent = \file_get_contents(DEFINITIONS_PATH . 'en_US.json');
$fileContent = \file_get_contents(self::DEFINITIONS_PATH . 'en_US.json');
if ($fileContent === false) {
return; // @codeCoverageIgnore
}

View File

@ -113,7 +113,7 @@ final class ModuleManager
* Constructor.
*
* @param ApplicationAbstract $app Application
* @param string $modulePath Path to modules
* @param string $modulePath Path to modules (must end with '/')
*
* @since 1.0.0
*/

View File

@ -673,7 +673,7 @@ class Directory extends FileAbstract implements DirectoryInterface
/**
* {@inheritdoc}
*/
public function current()
public function current() : FileAbstract
{
$current = \current($this->nodes);
@ -695,7 +695,7 @@ class Directory extends FileAbstract implements DirectoryInterface
/**
* {@inheritdoc}
*/
public function next() : FileAbstract
public function next()
{
$next = \next($this->nodes);

View File

@ -496,7 +496,7 @@ final class Directory extends FileAbstract implements DirectoryInterface
/**
* {@inheritdoc}
*/
public function current() : self
public function current() : FileAbstract
{
$current = \current($this->nodes);
@ -518,7 +518,7 @@ final class Directory extends FileAbstract implements DirectoryInterface
/**
* {@inheritdoc}
*/
public function next() : FileAbstract
public function next()
{
$next = \next($this->nodes);

View File

@ -43,7 +43,7 @@ class ApplicationManagerTest extends \PHPUnit\Framework\TestCase
$app->router = new WebRouter();
$app->dispatcher = new Dispatcher($app);
$app->appSettings = new CoreSettings($app->dbPool->get('admin'));
$app->moduleManager = new ModuleManager($app, __DIR__ . '/../../../Modules');
$app->moduleManager = new ModuleManager($app, __DIR__ . '/../../../Modules/');
$this->appManager = new ApplicationManager($app->moduleManager);
}

View File

@ -375,16 +375,4 @@ class LocalizationTest extends \PHPUnit\Framework\TestCase
$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
* @group framework
*/
public function testInvalidLocalizationLoading() : void
{
$this->expectException(\phpOMS\Stdlib\Base\Exception\InvalidEnumValue::class);
$this->localization->loadFromLanguage('INVALID');
}
}

View File

@ -46,7 +46,7 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
$this->app->router = new WebRouter();
$this->app->dispatcher = new Dispatcher($this->app);
$this->app->appSettings = new CoreSettings($this->app->dbPool->get('admin'));
$this->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../Modules');
$this->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../Modules/');
}
/**
@ -251,7 +251,7 @@ class ModuleManagerTest extends \PHPUnit\Framework\TestCase
*/
public function testInvalidModulePath() : void
{
$moduleManager = new ModuleManager($this->app, __DIR__ . '/Testmodule');
$moduleManager = new ModuleManager($this->app, __DIR__ . '/Testmodule/');
self::assertEquals([], $moduleManager->getAllModules());
self::assertEquals([], $moduleManager->getInstalledModules());

View File

@ -62,7 +62,7 @@ class ClientTest extends \PHPUnit\Framework\TestCase
$this->app->cachePool = new CachePool($this->app->dbPool);
$this->app->accountManager = new AccountManager($GLOBALS['session']);
$this->app->appSettings = new CoreSettings($this->app->dbPool->get());
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules');
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
$this->app->dispatcher = new Dispatcher($this->app);
$this->app->eventManager = new EventManager($this->app->dispatcher);
$this->app->eventManager->importFromFile(__DIR__ . '/../../../Socket/Hooks.php');

View File

@ -55,7 +55,7 @@ $app->orgId = 1;
$app->cachePool = new CachePool($app->dbPool);
$app->accountManager = new AccountManager($GLOBALS['session']);
$app->appSettings = new CoreSettings($app->dbPool->get());
$app->moduleManager = new ModuleManager($app, __DIR__ . '/../../../../Modules');
$app->moduleManager = new ModuleManager($app, __DIR__ . '/../../../../Modules/');
$app->dispatcher = new Dispatcher($app);
$app->eventManager = new EventManager($app->dispatcher);
$app->eventManager->importFromFile(__DIR__ . '/../../../Socket/Hooks.php');

View File

@ -62,7 +62,7 @@ class ServerTest extends \PHPUnit\Framework\TestCase
$this->app->cachePool = new CachePool($this->app->dbPool);
$this->app->accountManager = new AccountManager($GLOBALS['session']);
$this->app->appSettings = new CoreSettings($this->app->dbPool->get());
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules');
$this->app->moduleManager = new ModuleManager($this->app, __DIR__ . '/../../../../Modules/');
$this->app->dispatcher = new Dispatcher($this->app);
$this->app->eventManager = new EventManager($this->app->dispatcher);
$this->app->eventManager->importFromFile(__DIR__ . '/../../../Socket/Hooks.php');