Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement #[CoversMethod] attribute for #5175
- Loading branch information
1 parent
88af11b
commit fa8db04
Showing
9 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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\Framework\Attributes; | ||
|
||
use Attribute; | ||
|
||
/** | ||
* @psalm-immutable | ||
* | ||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] | ||
final readonly class CoversMethod | ||
{ | ||
/** | ||
* @psalm-var class-string | ||
*/ | ||
private string $className; | ||
|
||
/** | ||
* @psalm-var non-empty-string | ||
*/ | ||
private string $methodName; | ||
|
||
/** | ||
* @psalm-param class-string $className | ||
* @psalm-param non-empty-string $methodName | ||
*/ | ||
public function __construct(string $className, $methodName) | ||
{ | ||
$this->className = $className; | ||
$this->methodName = $methodName; | ||
} | ||
|
||
/** | ||
* @psalm-return class-string | ||
*/ | ||
public function className(): string | ||
{ | ||
return $this->className; | ||
} | ||
|
||
/** | ||
* @psalm-return non-empty-string | ||
*/ | ||
public function methodName(): string | ||
{ | ||
return $this->methodName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?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\Metadata; | ||
|
||
/** | ||
* @psalm-immutable | ||
* | ||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
final readonly class CoversMethod extends Metadata | ||
{ | ||
/** | ||
* @psalm-var class-string | ||
*/ | ||
private string $className; | ||
|
||
/** | ||
* @psalm-var non-empty-string | ||
*/ | ||
private string $methodName; | ||
|
||
/** | ||
* @psalm-param 0|1 $level | ||
* @psalm-param class-string $className | ||
* @psalm-param non-empty-string $methodName | ||
*/ | ||
protected function __construct(int $level, string $className, string $methodName) | ||
{ | ||
parent::__construct($level); | ||
|
||
$this->className = $className; | ||
$this->methodName = $methodName; | ||
} | ||
|
||
/** | ||
* @psalm-assert-if-true CoversMethod $this | ||
*/ | ||
public function isCoversMethod(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @psalm-return class-string | ||
*/ | ||
public function className(): string | ||
{ | ||
return $this->className; | ||
} | ||
|
||
/** | ||
* @psalm-return non-empty-string | ||
*/ | ||
public function methodName(): string | ||
{ | ||
return $this->methodName; | ||
} | ||
|
||
/** | ||
* @psalm-return non-empty-string | ||
* | ||
* @internal This method is not covered by the backward compatibility promise for PHPUnit | ||
*/ | ||
public function asStringForCodeUnitMapper(): string | ||
{ | ||
return $this->className . '::' . $this->methodName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.