Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer-indexed cases #428

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Framework/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function load(string $file, string $query = ''): array
}

foreach ($data as $key => $value) {
if (!is_int($key) && !self::testQuery($key, $query)) {
if (!self::testQuery((string) $key, $query)) {
unset($data[$key]);
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/Framework/DataProvider.load.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ require __DIR__ . '/../bootstrap.php';

test(function () {
$expect = [
1 => [],
1 => ['integer' => 'abc'],
2 => ['integer' => 'def'],
'foo' => [],
'bar' => [],
];

Assert::same($expect, DataProvider::load('fixtures/dataprovider.ini'));
Assert::same($expect, DataProvider::load('fixtures/dataprovider.php'));

foreach (array_keys($expect) as $key) {
Assert::same([$key => $expect[$key]], DataProvider::load('fixtures/dataprovider.ini', (string) $key));
Assert::same([$key => $expect[$key]], DataProvider::load('fixtures/dataprovider.php', (string) $key));
}
});


Expand Down
4 changes: 4 additions & 0 deletions tests/Framework/fixtures/dataprovider.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[1]
integer = abc

[2]
integer = def

[foo]

Expand Down
3 changes: 2 additions & 1 deletion tests/Framework/fixtures/dataprovider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

return [
1 => [], // integer key
1 => ['integer' => 'abc'], // first integer key
2 => ['integer' => 'def'], // second integer key
'foo' => [],
'bar' => [],
];
3 changes: 3 additions & 0 deletions tests/Runner/Runner.multiple.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ $path = __DIR__ . DIRECTORY_SEPARATOR . 'multiple' . DIRECTORY_SEPARATOR;
Assert::same([
['dataProvider.multiple.phptx', [['dataprovider', "1|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '0']]],
['dataProvider.multiple.phptx', [['dataprovider', "1|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '1']]],
['dataProvider.multiple.phptx', [['dataprovider', "2|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '0']]],
['dataProvider.multiple.phptx', [['dataprovider', "2|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '1']]],
['dataProvider.multiple.phptx', [['dataprovider', "bar|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '0']]],
['dataProvider.multiple.phptx', [['dataprovider', "bar|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '1']]],
['dataProvider.multiple.phptx', [['dataprovider', "foo|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '0']]],
['dataProvider.multiple.phptx', [['dataprovider', "foo|$path../../Framework/fixtures/dataprovider.ini"], ['multiple', '1']]],

['dataProvider.phptx', [['dataprovider', "1|$path../../Framework/fixtures/dataprovider.ini"]]],
['dataProvider.phptx', [['dataprovider', "2|$path../../Framework/fixtures/dataprovider.ini"]]],
['dataProvider.phptx', [['dataprovider', "bar|$path../../Framework/fixtures/dataprovider.ini"]]],
['dataProvider.phptx', [['dataprovider', "foo|$path../../Framework/fixtures/dataprovider.ini"]]],

Expand Down