Skip to content

Commit c4f0c78

Browse files
Initial work on value object for representing issue triggers
1 parent 2adcde1 commit c4f0c78

File tree

5 files changed

+199
-0
lines changed

5 files changed

+199
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\DeprecationTrigger;
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 DirectTrigger extends IssueTrigger
18+
{
19+
/**
20+
* Your own code triggers an issue in your own code.
21+
*
22+
* @psalm-assert-if-true DirectTrigger $this
23+
*/
24+
public function isDirect(): true
25+
{
26+
return true;
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\DeprecationTrigger;
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 IndirectTrigger extends IssueTrigger
18+
{
19+
/**
20+
* Your own code triggers an issue in your own code.
21+
*
22+
* @psalm-assert-if-true IndirectTrigger $this
23+
*/
24+
public function isIndirect(): true
25+
{
26+
return true;
27+
}
28+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\DeprecationTrigger;
11+
12+
/**
13+
* @psalm-immutable
14+
*
15+
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
16+
*/
17+
abstract class IssueTrigger
18+
{
19+
public static function self(): SelfTrigger
20+
{
21+
return new SelfTrigger;
22+
}
23+
24+
public static function direct(): DirectTrigger
25+
{
26+
return new DirectTrigger;
27+
}
28+
29+
public static function indirect(): IndirectTrigger
30+
{
31+
return new IndirectTrigger;
32+
}
33+
34+
final private function __construct()
35+
{
36+
}
37+
38+
/**
39+
* Your own code triggers an issue in your own code.
40+
*
41+
* @psalm-assert-if-true SelfTrigger $this
42+
*/
43+
public function isSelf(): bool
44+
{
45+
return false;
46+
}
47+
48+
/**
49+
* Your own code triggers an issue in third-party code.
50+
*
51+
* @psalm-assert-if-true DirectTrigger $this
52+
*/
53+
public function isDirect(): bool
54+
{
55+
return false;
56+
}
57+
58+
/**
59+
* Third-party code triggers an issue either in your own code or in third-party code.
60+
*
61+
* @psalm-assert-if-true IndirectTrigger $this
62+
*/
63+
public function isIndirect(): bool
64+
{
65+
return false;
66+
}
67+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\DeprecationTrigger;
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 SelfTrigger extends IssueTrigger
18+
{
19+
/**
20+
* Your own code triggers an issue in your own code.
21+
*
22+
* @psalm-assert-if-true SelfTrigger $this
23+
*/
24+
public function isSelf(): true
25+
{
26+
return true;
27+
}
28+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\DeprecationTrigger;
11+
12+
use PHPUnit\Framework\Attributes\CoversClass;
13+
use PHPUnit\Framework\Attributes\Small;
14+
use PHPUnit\Framework\TestCase;
15+
16+
#[CoversClass(SelfTrigger::class)]
17+
#[CoversClass(DirectTrigger::class)]
18+
#[CoversClass(IndirectTrigger::class)]
19+
#[Small]
20+
final class IssueTriggerTest extends TestCase
21+
{
22+
public function testCanBeSelf(): void
23+
{
24+
$trigger = IssueTrigger::self();
25+
26+
$this->assertTrue($trigger->isSelf());
27+
$this->assertFalse($trigger->isDirect());
28+
$this->assertFalse($trigger->isIndirect());
29+
}
30+
31+
public function testCanBeDirect(): void
32+
{
33+
$trigger = IssueTrigger::direct();
34+
35+
$this->assertTrue($trigger->isDirect());
36+
$this->assertFalse($trigger->isSelf());
37+
$this->assertFalse($trigger->isIndirect());
38+
}
39+
40+
public function testCanBeIndirect(): void
41+
{
42+
$trigger = IssueTrigger::indirect();
43+
44+
$this->assertTrue($trigger->isIndirect());
45+
$this->assertFalse($trigger->isSelf());
46+
$this->assertFalse($trigger->isDirect());
47+
}
48+
}

0 commit comments

Comments
 (0)