Skip to content

Commit e07e972

Browse files
We also need an UnknownTrigger type
1 parent 4215e86 commit e07e972

File tree

6 files changed

+83
-5
lines changed

6 files changed

+83
-5
lines changed

src/Event/Value/Test/Issue/DirectTrigger.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
namespace PHPUnit\Event\Code\DeprecationTrigger;
10+
namespace PHPUnit\Event\Code\IssueTrigger;
1111

1212
/**
1313
* @psalm-immutable
@@ -25,4 +25,9 @@ public function isDirect(): true
2525
{
2626
return true;
2727
}
28+
29+
public function asString(): string
30+
{
31+
return 'first-party code triggered issue in third-party code';
32+
}
2833
}

src/Event/Value/Test/Issue/IndirectTrigger.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
namespace PHPUnit\Event\Code\DeprecationTrigger;
10+
namespace PHPUnit\Event\Code\IssueTrigger;
1111

1212
/**
1313
* @psalm-immutable
@@ -25,4 +25,9 @@ public function isIndirect(): true
2525
{
2626
return true;
2727
}
28+
29+
public function asString(): string
30+
{
31+
return 'third-party code triggered issue in third-party code';
32+
}
2833
}

src/Event/Value/Test/Issue/IssueTrigger.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
namespace PHPUnit\Event\Code\DeprecationTrigger;
10+
namespace PHPUnit\Event\Code\IssueTrigger;
1111

1212
/**
1313
* @psalm-immutable
@@ -31,6 +31,11 @@ public static function indirect(): IndirectTrigger
3131
return new IndirectTrigger;
3232
}
3333

34+
public static function unknown(): UnknownTrigger
35+
{
36+
return new UnknownTrigger;
37+
}
38+
3439
final private function __construct()
3540
{
3641
}
@@ -64,4 +69,14 @@ public function isIndirect(): bool
6469
{
6570
return false;
6671
}
72+
73+
/**
74+
* @psalm-assert-if-true UnknownTrigger $this
75+
*/
76+
public function isUnknown(): bool
77+
{
78+
return false;
79+
}
80+
81+
abstract public function asString(): string;
6782
}

src/Event/Value/Test/Issue/SelfTrigger.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
namespace PHPUnit\Event\Code\DeprecationTrigger;
10+
namespace PHPUnit\Event\Code\IssueTrigger;
1111

1212
/**
1313
* @psalm-immutable
@@ -25,4 +25,9 @@ public function isSelf(): true
2525
{
2626
return true;
2727
}
28+
29+
public function asString(): string
30+
{
31+
return 'first-party code triggered issue in first-party code';
32+
}
2833
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Event\Code\IssueTrigger;
11+
12+
/**
13+
* @psalm-immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
16+
*/
17+
final class UnknownTrigger extends IssueTrigger
18+
{
19+
/**
20+
* @psalm-assert-if-true UnknownTrigger $this
21+
*/
22+
public function isUnknown(): true
23+
{
24+
return true;
25+
}
26+
27+
public function asString(): string
28+
{
29+
return 'unknown whether this issue was triggered in first-party or third-party code';
30+
}
31+
}

tests/unit/Event/Value/Test/IssueTriggerTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
10-
namespace PHPUnit\Event\Code\DeprecationTrigger;
10+
namespace PHPUnit\Event\Code\IssueTrigger;
1111

1212
use PHPUnit\Framework\Attributes\CoversClass;
1313
use PHPUnit\Framework\Attributes\Small;
@@ -26,6 +26,8 @@ public function testCanBeSelf(): void
2626
$this->assertTrue($trigger->isSelf());
2727
$this->assertFalse($trigger->isDirect());
2828
$this->assertFalse($trigger->isIndirect());
29+
$this->assertFalse($trigger->isUnknown());
30+
$this->assertSame('first-party code triggered issue in first-party code', $trigger->asString());
2931
}
3032

3133
public function testCanBeDirect(): void
@@ -35,6 +37,8 @@ public function testCanBeDirect(): void
3537
$this->assertTrue($trigger->isDirect());
3638
$this->assertFalse($trigger->isSelf());
3739
$this->assertFalse($trigger->isIndirect());
40+
$this->assertFalse($trigger->isUnknown());
41+
$this->assertSame('first-party code triggered issue in third-party code', $trigger->asString());
3842
}
3943

4044
public function testCanBeIndirect(): void
@@ -44,5 +48,18 @@ public function testCanBeIndirect(): void
4448
$this->assertTrue($trigger->isIndirect());
4549
$this->assertFalse($trigger->isSelf());
4650
$this->assertFalse($trigger->isDirect());
51+
$this->assertFalse($trigger->isUnknown());
52+
$this->assertSame('third-party code triggered issue in third-party code', $trigger->asString());
53+
}
54+
55+
public function testCanBeUnknown(): void
56+
{
57+
$trigger = IssueTrigger::unknown();
58+
59+
$this->assertFalse($trigger->isSelf());
60+
$this->assertFalse($trigger->isDirect());
61+
$this->assertFalse($trigger->isIndirect());
62+
$this->assertTrue($trigger->isUnknown());
63+
$this->assertSame('unknown whether this issue was triggered in first-party or third-party code', $trigger->asString());
4764
}
4865
}

0 commit comments

Comments
 (0)