Skip to content

Commit

Permalink
Fix ignored test with duplicate key in dataprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse committed Dec 10, 2018
1 parent c1b8b32 commit e885a77
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Util/Test.php
Expand Up @@ -879,7 +879,7 @@ private static function getDataFromDataProviderAnnotation(string $docComment, st
$data = [];

foreach ($origData as $key => $value) {
if (\is_int($key)) {
if (\is_int($key) || \array_key_exists($key, $data)) {
$data[] = $value;
} else {
$data[$key] = $value;
Expand Down
27 changes: 27 additions & 0 deletions tests/_files/DuplicateKeyDataProviderTest.php
@@ -0,0 +1,27 @@
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;

class DuplicateKeyDataProviderTest extends TestCase
{
public static function dataProvider()
{
yield 'foo' => ['foo'];

yield 'foo' => ['bar'];
}

/**
* @dataProvider dataProvider
*/
public function test($arg): void
{
}
}
10 changes: 10 additions & 0 deletions tests/unit/Util/TestTest.php
Expand Up @@ -562,6 +562,16 @@ public function testWithVariousIterableDataProviders(): void
], $dataSets);
}

public function testWithVDuplicateKeyDataProviders(): void
{
$dataSets = Test::getProvidedData(\DuplicateKeyDataProviderTest::class, 'test');

$this->assertEquals([
'foo' => ['foo'],
['bar'],
], $dataSets);
}

public function testTestWithEmptyAnnotation(): void
{
$result = Test::getDataFromTestWithAnnotation("/**\n * @anotherAnnotation\n */");
Expand Down

0 comments on commit e885a77

Please sign in to comment.