Skip to content
Snippets Groups Projects
Commit 0940c028 authored by Alexey Korepov's avatar Alexey Korepov
Browse files

Fix some minor bugs

parent 7166ed2e
No related branches found
Tags 1.0.0-beta11
No related merge requests found
......@@ -38,6 +38,18 @@ class ConfigFactoryStub extends ConfigFactory {
parent::__construct($storage, $event_dispatcher, $typed_config);
}
/**
* {@inheritdoc}
*/
protected function doLoadMultiple(array $names, $immutable = TRUE) {
// Now the static cache clearing is based on events (onConfigSave,
// onConfigDelete), that are not working in Unit Tests context, so to
// workaround just forces clearing the cache.
// @todo Invent a better way to do this.
$this->clearStaticCache();
return parent::doLoadMultiple($names, $immutable);
}
/**
* Sets a config value.
*
......@@ -49,14 +61,7 @@ class ConfigFactoryStub extends ConfigFactory {
* Store as immutable.
*/
public function stubSetConfig(string $name, $data, bool $immutable = FALSE): void {
// $config = $this->getEditable($name);
// $config->setData($data);
// $key = $this->getConfigCacheKey($name, FALSE);
// $keyImmutable = $this->getConfigCacheKey($name, TRUE);
// $this->storage->write($key, ['data' => $config]);
// // @todo Split to separate immutable and non-immutable sets.
// $this->cache[$key] = $config;
// $this->cache[$keyImmutable] = $config;
$this->clearStaticCache();
$this->storage->write($name, $data);
}
......
......@@ -899,17 +899,17 @@ class TestHelpers {
* The query object to check.
* @param \Drupal\Core\Entity\Query\ConditionInterface|\Drupal\Core\Database\Query\ConditionInterface $conditionsExpectedObject
* The query object with expected conditions.
* @param bool $onlyListed
* @param bool|null $onlyListed
* Forces to return false, if the checking query object contains more
* conditions than in object with expected conditions.
* @param bool $throwErrors
* @param bool|null $throwErrors
* Enables throwing notice errors when matching fails, with the explanation
* what exactly doesn't match.
*
* @return bool
* True if is subset, false if not.
*/
public static function matchConditions(object $conditionsObject, object $conditionsExpectedObject, bool $onlyListed = FALSE, bool $throwErrors = FALSE): bool {
public static function matchConditions(object $conditionsObject, object $conditionsExpectedObject, bool $onlyListed = NULL, bool $throwErrors = FALSE): bool {
if ($conditionsObject instanceof EntityQueryConditionInterface) {
if (strcasecmp($conditionsObject->getConjunction(), $conditionsExpectedObject->getConjunction()) != 0) {
$throwErrors && self::throwMatchError('conjunction', $conditionsObject->getConjunction(), $conditionsExpectedObject->getConjunction());
......@@ -951,6 +951,7 @@ class TestHelpers {
if ($conditionGroupMatchResult === TRUE) {
$conditionsExpectedFound[$conditionsExpectedDelta] = TRUE;
$conditionsFound[$conditionDelta] = TRUE;
break;
}
}
elseif ($condition == $conditionExpected) {
......@@ -958,11 +959,13 @@ class TestHelpers {
if ($condition['value'] == $conditionExpected['value']) {
$conditionsExpectedFound[$conditionsExpectedDelta] = TRUE;
$conditionsFound[$conditionDelta] = TRUE;
break;
}
}
else {
$conditionsExpectedFound[$conditionsExpectedDelta] = TRUE;
$conditionsFound[$conditionDelta] = TRUE;
break;
}
}
}
......
......@@ -93,7 +93,7 @@ class UnitTestCaseWrapper extends UnitTestCase {
*/
public function createPartialMockWithConstructor(string $originalClassName, array $methods = NULL, array $constructorArgs = NULL, array $addMethods = NULL): MockObject {
$mockBuilder = $this->getMockBuilder($originalClassName)
->setConstructorArgs($constructorArgs)
->setConstructorArgs($constructorArgs ?? [])
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes();
......
......@@ -44,6 +44,11 @@ class ConfigFactoryStubTest extends UnitTestCase {
$this->assertEquals($config1['foo'], $configFactory->get('config1')->get('foo'));
$this->assertEquals($config1['foo'], $configFactory->getEditable('config1')->get('foo'));
$configFactory->stubSetConfig('config.two', ['foo3']);
$this->assertEquals(['foo3'], $configFactory->get('config.two')->get());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment