Skip to content

Commit

Permalink
Mini-optimization when passed * symbol to get a full array. Also upda…
Browse files Browse the repository at this point in the history
…ted phpunit.xml schema to newest version.
  • Loading branch information
roquie committed Aug 12, 2020
1 parent 42a35a1 commit f0b0d7d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 25 deletions.
53 changes: 28 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./tests</directory>
<directory suffix=".php">./vendor</directory>
</exclude>
</whitelist>
</filter>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<directory suffix=".php">./tests</directory>
<directory suffix=".php">./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 4 additions & 0 deletions src/Dot.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public function get(string $path, $default = null): ResultSet
return new ResultSet($this->items[$path], [$path => $this->items[$path]]);
}

if ($path === $this->wildcard) {
return new ResultSet($this->items, [$path => $this->items]);
}

if (isset(self::$cache[$path])) {
return new ResultSet(...self::$cache[$path]);
}
Expand Down
15 changes: 15 additions & 0 deletions tests/DotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,21 @@ public function testGetItemWithWildcardAndAssociativeArray()
], $dot->get('foo.*.*')->getMap());
}

public function testGetItemWhereWildcardPassedAsSingleSymbol()
{
$array = [
[1, 3, 4]
];

$dot = new Obelix\Dot($array);

$result = $dot->get('*');
$this->assertSame($array, $result->getValue());
$this->assertSame([
'*' => $array
], $result->getMap());
}

public function testGetItemWhenSecondKeyIsNotUniqueInSubArrays()
{
$array = [
Expand Down

0 comments on commit f0b0d7d

Please sign in to comment.