Skip to content

Commit

Permalink
Add test for providing named arguments in DataProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jnoordsij committed Oct 6, 2023
1 parent 533b577 commit 0f81bc5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/_files/DataProviderNamedArgumentsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types=1);
/*
* 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.
*/
namespace PHPUnit\TestFixture;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class DataProviderNamedArgumentsTest extends TestCase
{
public static function providerMethod()
{
return [
['a' => 1, 'b' => 2, 'c' => 3],
['c' => 3, 'a' => 2, 'b' => 1],
];
}

#[DataProvider('providerMethod')]
public function testAdd($a, $b, $c): void
{
$this->assertEquals($c, $a + $b);
}
}
20 changes: 20 additions & 0 deletions tests/end-to-end/generic/dataprovider-named-arguments.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
phpunit ../../_files/DataProviderNamedArgumentsTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../../_files/DataProviderNamedArgumentsTest.php';

require_once __DIR__ . '/../../bootstrap.php';
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Runtime: %s

.. 2 / 2 (100%)

Time: %s, Memory: %s

OK (2 tests, 2 assertions)

0 comments on commit 0f81bc5

Please sign in to comment.