Skip to content

Commit 8a28de3

Browse files
Widen type from array to mixed so that invalid values can be handled in the right place
1 parent 0aed983 commit 8a28de3

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

src/Metadata/Metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public static function testDoxOnMethod(string $text): TestDox
413413
return new TestDox(self::METHOD_LEVEL, $text);
414414
}
415415

416-
public static function testWith(array $data): TestWith
416+
public static function testWith(mixed $data): TestWith
417417
{
418418
return new TestWith(self::METHOD_LEVEL, $data);
419419
}

src/Metadata/TestWith.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
*/
1717
final class TestWith extends Metadata
1818
{
19-
private readonly array $data;
19+
private readonly mixed $data;
2020

2121
/**
2222
* @psalm-param 0|1 $level
2323
*/
24-
protected function __construct(int $level, array $data)
24+
protected function __construct(int $level, mixed $data)
2525
{
2626
parent::__construct($level);
2727

@@ -36,7 +36,7 @@ public function isTestWith(): bool
3636
return true;
3737
}
3838

39-
public function data(): array
39+
public function data(): mixed
4040
{
4141
return $this->data;
4242
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\Metadata\Attribute;
11+
12+
use PHPUnit\Framework\Attributes\TestWithJson;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class TestWithInvalidValueTest extends TestCase
16+
{
17+
#[TestWithJson('false')]
18+
public function testOne($one, $two): void
19+
{
20+
$this->assertTrue(true);
21+
}
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
The right events are emitted in the right order for a test that uses a TestWithJson attribute which provides an invalid value
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = '--debug';
8+
$_SERVER['argv'][] = __DIR__ . '/../../_files/Metadata/Attribute/tests/TestWithInvalidValueTest.php';
9+
10+
require __DIR__ . '/../../bootstrap.php';
11+
12+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
13+
--EXPECTF--
14+
PHPUnit Started (PHPUnit %s using %s)
15+
Test Runner Configured
16+
Test Triggered PHPUnit Error (PHPUnit\TestFixture\Metadata\Attribute\TestWithInvalidValueTest::testOne)
17+
The data provider specified for PHPUnit\TestFixture\Metadata\Attribute\TestWithInvalidValueTest::testOne is invalid
18+
Data set #0 is invalid
19+
Test Runner Triggered Warning (No tests found in class "PHPUnit\TestFixture\Metadata\Attribute\TestWithInvalidValueTest".)
20+
Test Suite Loaded (0 tests)
21+
Event Facade Sealed
22+
Test Runner Started
23+
Test Suite Sorted
24+
Test Runner Execution Started (0 tests)
25+
Test Runner Execution Finished
26+
Test Runner Finished
27+
PHPUnit Finished (Shell Exit Code: 2)

0 commit comments

Comments
 (0)