Skip to content

Commit

Permalink
Fix - Return previous value when setting a new value (consistency). R…
Browse files Browse the repository at this point in the history
  • Loading branch information
nibra committed Oct 11, 2021
1 parent f74644f commit 173d9ca
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 200 deletions.
18 changes: 10 additions & 8 deletions Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,21 @@ public function testARegistryInstanceInstantiatedWithAStringOfDataIsCorrectlyMan
// Check top level values
$this->assertSame('bar', $a->get('foo'));
$this->assertSame('bar', $a->def('foo'));
$this->assertSame('far', $a->set('foo', 'far'));
$this->assertSame('bar', $a->set('foo', 'far'));
$this->assertSame('far', $a->get('foo'));

// Check nested values
$this->assertSame('bar', $a->get('nested.foo'));
$this->assertSame('bar', $a->def('nested.foo'));
$this->assertSame('far', $a->set('nested.foo', 'far'));
$this->assertSame('bar', $a->set('nested.foo', 'far'));
$this->assertSame('far', $a->get('nested.foo'));

// Check adding a new nested object
$a->set('new.nested', ['foo' => 'bar', 'goo' => 'car']);
$this->assertSame('bar', $a->get('new.nested.foo'));
$this->assertSame('bar', $a->def('new.nested.foo'));
$this->assertSame('far', $a->set('new.nested.foo', 'far'));
$this->assertSame('bar', $a->set('new.nested.foo', 'far'));
$this->assertSame('far', $a->get('new.nested.foo'));
}

/**
Expand Down Expand Up @@ -491,15 +494,14 @@ public function testAValueIsStoredToTheRegistry()
{
$a = new Registry;

$this->assertSame(
'testsetvalue1',
$this->assertNull(
$a->set('foo', 'testsetvalue1'),
'The current value should be returned when assigning a key for the first time.'
'Null should be returned when assigning a key for the first time.'
);
$this->assertSame(
'testsetvalue2',
'testsetvalue1',
$a->set('foo', 'testsetvalue2'),
'The new value should be returned when assigning a key multiple times.'
'The previous value should be returned when assigning a key multiple times.'
);
}

Expand Down
79 changes: 42 additions & 37 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
{
"name": "joomla/registry",
"type": "joomla-package",
"description": "Joomla Registry Package",
"keywords": ["joomla", "framework", "registry"],
"homepage": "https://github.com/joomla-framework/registry",
"license": "GPL-2.0-or-later",
"require": {
"php": "^7.2.5",
"joomla/utilities": "^1.4.1|^2.0"
},
"require-dev": {
"joomla/coding-standards": "^3.0@dev",
"symfony/yaml": "^3.4|^4.4|^5.0",
"phpunit/phpunit": "^8.5|^9.0"
},
"conflict": {
"symfony/yaml": "<3.4"
},
"suggest": {
"symfony/yaml": "Install symfony/yaml if you require YAML support."
},
"autoload": {
"psr-4": {
"Joomla\\Registry\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Joomla\\Registry\\Tests\\": "Tests/"
}
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-2.0-dev": "2.0-dev"
}
}
"name": "joomla/registry",
"type": "joomla-package",
"description": "Joomla Registry Package",
"keywords": [
"joomla",
"framework",
"registry"
],
"homepage": "https://github.com/joomla-framework/registry",
"license": "GPL-2.0-or-later",
"require": {
"php": "^7.2.5",
"joomla/utilities": "^1.4.1|^2.0"
},
"require-dev": {
"ext-json": "*",
"joomla/coding-standards": "^3.0@dev",
"symfony/yaml": "^3.4|^4.4|^5.0",
"phpunit/phpunit": "^8.5|^9.0"
},
"conflict": {
"symfony/yaml": "<3.4"
},
"suggest": {
"symfony/yaml": "Install symfony/yaml if you require YAML support."
},
"autoload": {
"psr-4": {
"Joomla\\Registry\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Joomla\\Registry\\Tests\\": "Tests/"
}
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-2.0-dev": "2.0-dev"
}
}
}
Loading

0 comments on commit 173d9ca

Please sign in to comment.