Skip to content
Merged
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
19 changes: 19 additions & 0 deletions src/Metadata/Api/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ public function providedData(string $className, string $methodName): ?array
}

if ($dataProvider->isNotEmpty()) {
if ($testWith->isNotEmpty()) {
$method = new ReflectionMethod($className, $methodName);

Event\Facade::emitter()->testTriggeredPhpunitWarning(
Comment thread
sebastianbergmann marked this conversation as resolved.
new TestMethod(
$className,
$methodName,
$method->getFileName(),
$method->getStartLine(),
Event\Code\TestDoxBuilder::fromClassNameAndMethodName(
$className,
$methodName,
),
MetadataCollection::fromArray([]),
Event\TestData\TestDataCollection::fromArray([]),
),
'Mixing #[DataProvider*] and #[TestWith*] attributes is not supported, only the data provided by #[DataProvider*] will be used',
);
}
$data = $this->dataProvidedByMethods($className, $methodName, $dataProvider);
} else {
$data = $this->dataProvidedByMetadata($testWith);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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\Attributes\DataProviderExternal;
use PHPUnit\Framework\TestCase;

final class TestDataProviderExternalAndDataProviderTest extends TestCase
{
public static function externalProvider(): iterable
{
yield 'foo' => ['bar', 'baz'];
}

public static function provider(): iterable
{
yield 'foo2' => ['bar', 'baz'];
}

#[DataProvider('provider')]
#[DataProviderExternal(self::class, 'externalProvider')]
public function testWithDifferentProviderTypes($one, $two): void
{
$this->assertTrue(true);
}
}
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\TestWith;
use PHPUnit\Framework\Attributes\TestWithJson;
use PHPUnit\Framework\TestCase;

final class TestWithAndTestWithJsonDataProviderTest extends TestCase
{
public static function provider(): iterable
{
yield 'foo' => ['bar', 'baz'];
}

#[TestWith(['a', 'b'], 'foo')]
#[TestWithJson('[1, 2]')]
public function testWithDifferentProviderTypes($one, $two): void
{
$this->assertTrue(true);
}
}
30 changes: 30 additions & 0 deletions tests/end-to-end/_files/TestWithAttributeAndDataProviderTest.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\Attributes\TestWith;
use PHPUnit\Framework\TestCase;

final class TestWithAttributeAndDataProviderTest extends TestCase
{
public static function provider(): iterable
{
yield 'foo' => ['bar', 'baz'];
}

#[TestWith(['a', 'b'], 'foo')]
#[DataProvider('provider')]
public function testWithDifferentProviderTypes($one, $two): void
{
$this->assertTrue(true);
}
}
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\DataProviderExternal;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;

final class TestWithAttributeAndExternalDataProviderTest extends TestCase
{
public static function provider(): iterable
{
yield 'foo' => ['bar', 'baz'];
}

#[TestWith(['a', 'b'], 'foo')]
#[DataProviderExternal(self::class, 'provider')]
public function testWithDifferentProviderTypes($one, $two): void
{
$this->assertTrue(true);
}
}
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\Attributes\TestWithJson;
use PHPUnit\Framework\TestCase;

final class TestWithJsonAttributeAndDataProviderTest extends TestCase
{
public static function provider(): iterable
{
yield 'foo' => ['bar', 'baz'];
}

#[TestWithJson('[1, 2, 3]')]
#[DataProvider('provider')]
public function testWithDifferentProviderTypes($one, $two): void
{
$this->assertTrue(true);
}
}
21 changes: 21 additions & 0 deletions tests/end-to-end/metadata/mix-attribute-dataproviders.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
phpunit ../_files/TestDataProviderExternalAndDataProviderTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/TestDataProviderExternalAndDataProviderTest.php';

require __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)
21 changes: 21 additions & 0 deletions tests/end-to-end/metadata/mix-test-with-dataproviders.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
phpunit ../_files/TestWithAndTestWithJsonDataProviderTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/TestWithAndTestWithJsonDataProviderTest.php';

require __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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
phpunit ../_files/TestWithJsonAttributeAndDataProviderTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/TestWithJsonAttributeAndDataProviderTest.php';

require __DIR__ . '/../../bootstrap.php';

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

Runtime: %s

W 1 / 1 (100%)

Time: %s, Memory: %s

1 test triggered 1 PHPUnit warning:

1) PHPUnit\TestFixture\TestWithJsonAttributeAndDataProviderTest::testWithDifferentProviderTypes
Mixing #[DataProvider*] and #[TestWith*] attributes is not supported, only the data provided by #[DataProvider*] will be used

%sTestWithJsonAttributeAndDataProviderTest.php:%d

OK, but there were issues!
Tests: 1, Assertions: 1, PHPUnit Warnings: 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
phpunit ../_files/TestWithAttributeAndDataProviderTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/TestWithAttributeAndDataProviderTest.php';

require __DIR__ . '/../../bootstrap.php';

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

Runtime: %s

W 1 / 1 (100%)

Time: %s, Memory: %s

1 test triggered 1 PHPUnit warning:

1) PHPUnit\TestFixture\TestWithAttributeAndDataProviderTest::testWithDifferentProviderTypes
Mixing #[DataProvider*] and #[TestWith*] attributes is not supported, only the data provided by #[DataProvider*] will be used

%sTestWithAttributeAndDataProviderTest.php:%d

OK, but there were issues!
Tests: 1, Assertions: 1, PHPUnit Warnings: 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
phpunit ../_files/TestWithAttributeAndExternalDataProviderTest.php
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/TestWithAttributeAndExternalDataProviderTest.php';

require __DIR__ . '/../../bootstrap.php';

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

Runtime: %s

W 1 / 1 (100%)

Time: %s, Memory: %s

1 test triggered 1 PHPUnit warning:

1) PHPUnit\TestFixture\TestWithAttributeAndExternalDataProviderTest::testWithDifferentProviderTypes
Mixing #[DataProvider*] and #[TestWith*] attributes is not supported, only the data provided by #[DataProvider*] will be used

%sTestWithAttributeAndExternalDataProviderTest.php:%d

OK, but there were issues!
Tests: 1, Assertions: 1, PHPUnit Warnings: 1.