Skip to content

Method offsetUnset does not remove key #123

@prwater

Description

@prwater

Method \Noodlehaus\AbstractConfig::offsetUnset (Deletes a key and its value) does not remove the key from the configuration but only set the value of the key to null.

The following code:

$config = new \Noodlehaus\Config('tests/mocks/pass/config.ini');
print_r($config->all());
$config->offsetUnset('application');
print_r($config->all());

yields the following output:

Array
(
    [host] => localhost
    [port] => 80
    [servers] => Array
        (
            [0] => host1
            [1] => host2
            [2] => host3
        )

    [application] => Array
        (
            [name] => configuration
            [secret] => s3cr3t
        )

)

Array
(
    [host] => localhost
    [port] => 80
    [servers] => Array
        (
            [0] => host1
            [1] => host2
            [2] => host3
        )

    [application] => 
)

The key application is still in the configuration (with value null).

Unit test \Noodlehaus\AbstractConfigTest\testRemove must use assertArrayNotHasKey instead of assertNull:

public function testRemove()
{
     $this->config->remove('application');
     $this->assertArrayNotHasKey('application', $this->config->all());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions