Skip to content

Commit 7abc754

Browse files
committed
Improve phpDoc class docs
1 parent 48a5ed7 commit 7abc754

File tree

7 files changed

+106
-19
lines changed

7 files changed

+106
-19
lines changed

psalm.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
<?xml version="1.0"?>
2+
<!--
3+
~ PHPUnitThrowableAssertions - Throwable-related PHPUnit assertions.
4+
~
5+
~ @copyright Copyright (c) 2021, Daniel Rudolf (<https://www.daniel-rudolf.de>)
6+
~
7+
~ This file is copyrighted by the contributors recorded in the version control
8+
~ history of the file, available from the following original location:
9+
~
10+
~ <https://github.com/PhrozenByte/phpunit-throwable-asserts/blob/master/psalm.xml>
11+
~
12+
~ @license http://opensource.org/licenses/MIT The MIT License
13+
~
14+
~ SPDX-License-Identifier: MIT
15+
~ License-Filename: LICENSE
16+
-->
17+
218
<psalm
319
errorLevel="4"
420
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

src/Assert.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
/**
2323
* A set of throwable-related assertion methods.
2424
*
25-
* This static class just uses the `ThrowableAssertsTrait` trait. Refer to
26-
* {@class PhrozenByte\PHPUnitThrowableAsserts\ThrowableAssertsTrait} for
27-
* more info.
25+
* This static class just uses the {@see ThrowableAssertsTrait} trait. Refer to
26+
* {@see ThrowableAssertsTrait} for more info.
2827
*/
2928
class Assert
3029
{

src/Constraint/AbstractCallableThrows.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
use PHPUnit\Framework\Constraint\Constraint;
2323
use PHPUnit\Framework\Constraint\IsEqual;
24-
use PHPUnit\Framework\Exception as PHPUnitException;
2524
use PHPUnit\Framework\ExpectationFailedException;
2625
use PHPUnit\Framework\InvalidArgumentException;
2726
use PhrozenByte\PHPUnitThrowableAsserts\CallableProxy;
@@ -31,6 +30,8 @@
3130
/**
3231
* Abstract base class for the `CallableThrows` and `CallableThrowsNot`
3332
* constraints implementing some common methods.
33+
*
34+
* @internal
3435
*/
3536
abstract class AbstractCallableThrows extends Constraint
3637
{
@@ -54,7 +55,7 @@ abstract class AbstractCallableThrows extends Constraint
5455
* @param int|string|null $code value to match the Throwable's code
5556
* @param bool $exactMatch whether an exact match of the Throwable's class is required
5657
*
57-
* @throws PHPUnitException
58+
* @throws InvalidArgumentException
5859
*/
5960
public function __construct(string $className, $message, $code, bool $exactMatch)
6061
{
@@ -74,7 +75,16 @@ public function __construct(string $className, $message, $code, bool $exactMatch
7475
}
7576

7677
/**
77-
* {@inheritDoc}
78+
* Throws a ExpectationFailedException exception for the compared value.
79+
*
80+
* @param mixed $other evaluated value or object
81+
* @param string $description additional information about the test
82+
* @param ComparisonFailure|null $comparisonFailure additional information about string inequality
83+
* @param Throwable|null $throwable instance of a unexpectedly thrown Throwable
84+
*
85+
* @throws ExpectationFailedException
86+
*
87+
* @psalm-return never-return
7888
*/
7989
protected function fail(
8090
$other,
@@ -105,7 +115,7 @@ protected function fail(
105115
}
106116

107117
/**
108-
* Returns additional failure description for a Throwable
118+
* Returns additional failure description for a Throwable.
109119
*
110120
* @param Throwable|null $throwable the Throwable that was thrown
111121
*
@@ -133,7 +143,14 @@ protected function throwableFailureDescription(?Throwable $throwable): string
133143
}
134144

135145
/**
136-
* {@inheritDoc}
146+
* Returns the description of the failure.
147+
*
148+
* The beginning of failure messages is "Failed asserting that" in most
149+
* cases. This method should return the second part of that sentence.
150+
*
151+
* @param mixed $other the evaluated value
152+
*
153+
* @return string the failure description
137154
*/
138155
protected function failureDescription($other): string
139156
{
@@ -149,7 +166,7 @@ protected function failureDescription($other): string
149166
}
150167

151168
/**
152-
* {@inheritDoc}
169+
* Returns the number of assertions performed by this Constraint.
153170
*/
154171
public function count(): int
155172
{

src/Constraint/CallableThrows.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
namespace PhrozenByte\PHPUnitThrowableAsserts\Constraint;
2121

2222
use PHPUnit\Framework\Constraint\Constraint;
23+
use PHPUnit\Framework\Exception as PHPUnitException;
2324
use PHPUnit\Framework\ExpectationFailedException;
2425
use PHPUnit\Framework\InvalidArgumentException;
2526
use Throwable;
@@ -75,7 +76,9 @@ public function __construct(
7576
}
7677

7778
/**
78-
* @inheritDoc
79+
* Returns a human-readable string representation of this Constraint.
80+
*
81+
* @return string string representation of the Constraint
7982
*/
8083
public function toString(): string
8184
{
@@ -87,7 +90,23 @@ public function toString(): string
8790
}
8891

8992
/**
90-
* {@inheritDoc}
93+
* Evaluates whether the given value matches the Constraint.
94+
*
95+
* If `$returnResult` is set to `false` (default), an exception is thrown
96+
* in case of a failure. `null` is returned otherwise.
97+
*
98+
* If `$returnResult` is `true`, the result of the evaluation is returned
99+
* as a boolean instead: `true` in case of success, `false` in case of a
100+
* failure.
101+
*
102+
* @param mixed $other the value to evaluate
103+
* @param string $description additional information about the test
104+
* @param bool $returnResult whether to return the evaluation result
105+
*
106+
* @return bool|null evaluation result if `$returnResult` is set `true`
107+
*
108+
* @throws ExpectationFailedException
109+
* @throws PHPUnitException
91110
*/
92111
public function evaluate($other, string $description = '', bool $returnResult = false)
93112
{

src/Constraint/CallableThrowsNot.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use PHPUnit\Framework\Constraint\Constraint;
2323
use PHPUnit\Framework\Exception as PHPUnitException;
2424
use PHPUnit\Framework\ExpectationFailedException;
25+
use PHPUnit\Framework\InvalidArgumentException;
2526
use Throwable;
2627

2728
/**
@@ -52,7 +53,7 @@ class CallableThrowsNot extends AbstractCallableThrows
5253
* @param int|string|null $code catch Throwables with the given code only
5354
* @param bool $exactMatch whether an exact match of the Throwable class is caught only
5455
*
55-
* @throws PHPUnitException
56+
* @throws InvalidArgumentException
5657
*/
5758
public function __construct(
5859
string $className = Throwable::class,
@@ -64,7 +65,9 @@ public function __construct(
6465
}
6566

6667
/**
67-
* @inheritDoc
68+
* Returns a human-readable string representation of this Constraint.
69+
*
70+
* @return string string representation of the Constraint
6871
*/
6972
public function toString(): string
7073
{
@@ -76,7 +79,23 @@ public function toString(): string
7679
}
7780

7881
/**
79-
* {@inheritDoc}
82+
* Evaluates whether the given value matches the Constraint.
83+
*
84+
* If `$returnResult` is set to `false` (default), an exception is thrown
85+
* in case of a failure. `null` is returned otherwise.
86+
*
87+
* If `$returnResult` is `true`, the result of the evaluation is returned
88+
* as a boolean instead: `true` in case of success, `false` in case of a
89+
* failure.
90+
*
91+
* @param mixed $other the value to evaluate
92+
* @param string $description additional information about the test
93+
* @param bool $returnResult whether to return the evaluation result
94+
*
95+
* @return bool|null evaluation result if `$returnResult` is set `true`
96+
*
97+
* @throws ExpectationFailedException
98+
* @throws PHPUnitException
8099
*/
81100
public function evaluate($other, string $description = '', bool $returnResult = false)
82101
{

src/ThrowableAssertsTrait.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@
2828
use PhrozenByte\PHPUnitThrowableAsserts\Constraint\CallableThrowsNot;
2929
use Throwable;
3030

31+
/**
32+
* A set of Throwable-related assertion methods.
33+
*
34+
* This trait implements an assertion method and constraint creation method per
35+
* implemented constraint, namely
36+
*
37+
* - the `assertCallableThrows()` and `callableThrows()` methods for
38+
* {@see CallableThrows}, and
39+
* - the `assertCallableThrowsNot()` and `callableThrowsNot()` methods for
40+
* {@see CallableThrowsNot}.
41+
*
42+
* This trait additionally implements some helper methods to create new
43+
* instances of the callable proxy classes, namely
44+
*
45+
* - the `callableProxy()` method for {@see CallableProxy}, and
46+
* - the `cachedCallableProxy()` method for {@see CachedCallableProxy}.
47+
*/
3148
trait ThrowableAssertsTrait
3249
{
3350
/**
@@ -156,7 +173,7 @@ public static function callableThrowsNot(
156173

157174
/**
158175
* Returns a new instance of CallableProxy.
159-
* *
176+
*
160177
* @param callable $callable the Callable to invoke
161178
* @param mixed ...$arguments the arguments to pass to the Callable
162179
*
@@ -169,7 +186,7 @@ public static function callableProxy(callable $callable, ...$arguments): Callabl
169186

170187
/**
171188
* Returns a new instance of CachedCallableProxy.
172-
* *
189+
*
173190
* @param callable $callable the Callable to invoke
174191
* @param mixed ...$arguments the arguments to pass to the Callable
175192
*

tests/Utils/TestConstraint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ public function __construct(array $options = [])
4848
}
4949

5050
/**
51-
* @inheritDoc
51+
* {@inheritDoc}
5252
*/
5353
public function toString(): string
5454
{
5555
return $this->toString;
5656
}
5757

5858
/**
59-
* @inheritDoc
59+
* {@inheritDoc}
6060
*/
6161
protected function matches($other): bool
6262
{
6363
return $this->matches;
6464
}
6565

6666
/**
67-
* @inheritDoc
67+
* {@inheritDoc}
6868
*/
6969
public function count(): int
7070
{

0 commit comments

Comments
 (0)