Download the PHP package ryunosuke/phpunit-extension without Composer
On this page you can find all versions of the php package ryunosuke/phpunit-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ryunosuke/phpunit-extension
More information about ryunosuke/phpunit-extension
Files in ryunosuke/phpunit-extension
Package phpunit-extension
Short Description PHPUnit Fluent interface and Custom assertions
License MIT
Informations about the package phpunit-extension
PHPUnit Extension
Description
This package adds Fluent interface. and provides Custom assertion.
- e.g.
that('xxx')->isEqual('xxx')
- e.g.
that(1)->isInt()->isBetween(1, 9)
- e.g.
that('qwe asd zxc')->stringStartsWith('qwe')->stringEndsWith('zxc')
Install
Usage
Actual class
Simplified chart:
method | description | return type |
---|---|---|
__call | call original method no thrown | actual of method's return or expcetion |
__call(...[]) | get original method's callable | actual of method's callable (with bindings) |
__invoke | call original __invoke no thrown | actual of __invoke's return or expcetion |
__invoke(...[]) | get original __invoke's callable | actual of __invoke's callable (with bindings) |
__get | get original property no thrown | actual of property or expcetion |
__set | set original property publicly | void |
offsetGet | get ArrayAccess by key | actual of key's value |
var | get property | original property |
use | get original method's callable | original method as Closure |
callable | get original method's callable | actual of method's callable |
fn | get original invoke's callable | actual of invoke's callable |
do | call original method | actual of method's return |
try | call original method no thrown | actual of method's return or expcetion |
new | call class construct no thrown | actual of object or expcetion |
insteadof | apply callable | actual of applied value |
list | return reference argument | actual of reference argument |
return | return original | original |
echo | dump original | $this |
eval | assert constraint directly | $this |
as | set assertion message | $this |
break | mark breakable test | $this |
and | return latest asserted actual | actual of latest asserted |
final | return assertion statistic | actual of assertion statistic |
declare | rewrite source by actual value | $this |
wasOutputed | assert stdout or echo | $this |
wasErrored | assert stderr or throw | $this |
inElapsedTime | assert elapsed time | $this |
A return value or argument of Actual can transparently use the original method, as shown below.
Custom constraints
Internals:
constraint | description |
---|---|
ClosesTo | assert float by auto approximation |
Contains | assert string/iterable/file contains substring/element/content |
DatetimeEquals | assert Datetimable equals |
EqualsFile | assert string equals file |
EqualsIgnoreWS | assert string equals ignoring whitespace |
EqualsPath | assert path equals other path (compatible posix) |
FileContains | assert file contains string |
FileEquals | assert file equals string |
FileSizeIs | assert file size |
HasKey | assert array/object has key/property |
HtmlMatchesArray | assert html string by array |
InTime | assert processing in time |
Is | assert value with loosely |
IsBetween | assert range of number |
IsBlank | assert blank string |
IsCType | assert value by ctype_xxx |
IsFalsy | assert value like a false |
IsThrowable | assert value is Throwable |
IsTruthy | assert value like a true |
IsValid | assert value by filter_var |
JsonMatchesArray | assert json string based on array |
LengthEquals | assert string/iterable/file length/count/size |
MatchesCountEquals | assert matched count element per array |
OutputMatches | assert output of STDOUT |
StringLengthEquals | assert length of string |
SubsetEquals | assert array by subarray |
SubsetMatches | assert array at preg_match |
Throws | assert callable should throw exception |
Alias:
\ryunosuke\PHPUnit\Actual::$constraintVariations
is searching for variation from other constraint.
User defined:
\ryunosuke\PHPUnit\Actual::$constraintNamespaces
is searching for constraint namespace.
Code completion
Actual class is using \ryunosuke\PHPUnit\Annotation
trait.
If declare this class in your project space, then custom method and code completion are enabled.
That ables to use $actual->isH(oge)
completion and $actual->isF(uga)
method.
Or call \ryunosuke\PHPUnit\Actual::generateAnnotation
.
This method returns annotation via $constraintVariations
and $constraintNamespaces
.
TestCaseTrait
This Trait provides testing utility.
- trapThrowable
- If specified exception is thrown then skip the test.
- restorer
- Reset function base's value. When unset return value recovery prev value.
- finalize
- Run closure at Test end.
- rewriteProperty
- Rewrite private/protected property. When unset return value recovery prev value.
- tryableCallable
- Closurize private/protected method. And bind arguments with default values.
- getEnvOrSkip
- Return getenv(). If novalue then skip the test.
- getConstOrSkip
- Return constant(). If undefined then skip the test.
- getClassMap
- Return all class => file array based on composer
- getClassByDirectory
- Return class names by directory
- getClassByNamespace
- Return class names by namespace
- emptyDirectory
- Ready temporary directory and clean contents.
- backgroundTask
- Run closure asynchronously.
- report
- Report message to test result footer.
Custom printer
This package provides Progress Printer. This printer outputs only in case of failure. It will not output on success.
Custom other
Exporter
This package provides Custom Exporter. This Exporter changes on the following.
- Extended maximum character width for strings
- Changed binary string to quoted string
- Changed to not insert tagged newline characters
- Changed object identifier from hash to id
CodeCoverage
This package provides Custom CodeCoverage. This CodeCoverage changes on the following.
- Suppports
@codeCoverageIgnore
trailing comment- e.g.
foo(); // @codeCoverageIgnore because php8.1 only
- e.g.
Release
Versioning is Semantic Versioning.
4.2.1
- [fixbug] fixed error in php8.2
- [merge] 3.20.2
4.2.0
- [feature] added tryableCallable
- [change] fixed stub generation
4.1.0
- [change] fixed ProgressPrinter
4.0.0
- [change] php>=8.0
- [*change] delete deprecated feature
3.20.2
- [fixbug] fix declare escape
3.20.1
- [fixbug] fixed Start/End is not ignored
3.20.0
- [feature] use compatible original class
3.19.0
- [feature] added finalize
- [feature] improved Traversable
3.18.0
- [feature] added VALID_DOMAIN/VALID_HOSTNAME to IsValid
3.17.0
- [feature] added getClassMap/getClassByDirectory/getClassByNamespace
- [feature] added IsTypeOf constraint
3.16.0
- [feature] added insteadof
- [change] obsolete clear global states
3.15.0
- [refactor] code format and fix inspection
- [feature] added clear state to that
- [fixbug] fixed Constraints and method calls is mixed
- [fixbug] changed getXXXOrSkip to static
3.14.0
- [feature] added TraversableComparator
- [fixbug] fixed self/static type
- [fixbug] fixed multiple markfile
3.13.1
- [fixbug] fixed sub-processes did not terminate when test failed.
- [fixbug] fixed single backquote noticed on Windows
3.13.0
- [feature] add after report
- [feature] generateStub supports glob pattern
3.12.0
- [change] suppressed warning at warning test
- [feature] added backgroundTask
- [fixbug] fixed mixin doesn't append no generated stub
3.11.0
- [change] changed ProgressPrinter format and support breakable test
- [feature] added trapThrowable
- [feature] added breakable
- [change] deprecated function caller
- [refactor] fixed wrong namespace
3.10.1
- [change] changed stub class is hierarchized
- [fixbug] fixed __set does not set ancestor private field
- [fixbug] fixed generateStub losts original type
- [fixbug] fixed generateStub ignores public member
3.10.0
- [feature] implove generateStub
- [feature] added MatchesCountEquals constaint
- [feature] added unwrapping original value if Actual argument
- [feature] added disable function option
- [change] deprecated static calls with __toString of object
- [fixbug] fixed caused exceptions to be implicitly through
- [fixbug] fixed filesystem function denies null string
- [fixbug] fixed __set private field
- [fixbug] fixed "debug" method returns null always
3.9.0
- [change] fixed printer oddities
- improved portability
- prefer specified columns
- enable verbosity
- print result on interrupt
3.8.1
- [feature] mark risky not asserting anything
- [feature] added wasOutputed/wasErrored/inElapsedTime method
3.8.0
- [feature] added restorer
- [feature] added get(Env|Const)OrSkip
- [change] fixed ExpectationFailedException message is too large
- [fixbug] fixed output is swallowed up
3.7.1
- [fixbug] fixed broken dependency
3.7.0
- [fixbug] fixed duplicated annotation
- [feature] added Is constaint (looser than IsEqual)
- [feature] added ClosesTo constaint
- [feature] added DatetimeEquals constaint
- [feature] supported SplFileInfo at file system
- [change] changed as method to variable arguments
3.6.0
- [refactor] changed private field name to be incompatible with stub generation
- [feature] implemented to disable built-in constraints
- [feature] added TestCaseTrait trait
- [feature] added declare method
- [feature] added new method
- [feature] added isUndefined variation
- [feature] added EqualsPath constaint
- [fixbug] fixed no $ in stub generation
- [fixbug] fixed strictly enforced due to frequent unintended function calls
- [fixbug] fixed in __callStatic where original method was not called
3.5.0
- [feature] added htmlMatchesArray supports style attribute
- [fixbug] fixed "try" catches necessary exceptions
- [change] implemented __callStatic omission
3.4.0
- [refactor] fixed annotation
- [feature] added ...[] syntax
- [feature] added stdout to results property
- [feature] added htmlMatchesArray supports class and closure
- [feature] added OutputMatches variation
- [fixbug] fixed the file location was on the test code when an error on the test target
- [fixbug] fixed progress disorder
3.3.0
- [feature] ProgressPrinter to show file location on failure
- [feature] htmlMatchesArray made it easier to understand when A fails
3.2.0
- [feature] add bootstrap.php for boilerplates
- [feature] print Actual value
3.1.0
- [feature] add final method for assertion statistic
- [feature] add raw flag to OutputMatches constraint
- [feature] add fn method for no-method callable
- [refactor] Establish self describing class
3.0.1
- [fixbug] vendor directories have difference during development and release
- [fixbug] callable that not closure/object throws exception
3.0.0
- [*change] see log
2.0.1
- [feature] support php8
2.0.0
- [*change] see log
1.2.0
- [feature] add Annotester class
- [feature] add shorthand closure alias
- [feature] add int, float ValidType
- [feature] add constraint alias mangle argument
- [feature] add "and" property/method
- [fixbug] supports static property/method
- [fixbug] supports minor/patch version of $compatibleVersion
1.1.2
- [feature] add "InTime" constraint
- [feature] add "callable" method
- [change] deprecated "catch" and "print" method
1.1.1
- [fixbug] get/offsetGet implementation leak
- __get: use stringToStructure
- offsetGet: access to original offset
1.1.0
- [feature] add version control property
- [feature] add "prefixIs", "suffixIs" alias
- [feature] support Regex and JSONPath and JMESPath at get/offsetGet
- [feature] implement "__toString" method
- [feature] add depended on other constraint
- [feature] add "FileSizeIs" constraint
- [change] change "Not" position (e.g. NotFileExists -> FileNotExists)
- "notFileExists" can still be used, but will be deleted in the future
- [change] rename "all" -> "each"
- "all*" can still be used, but will be deleted in the future
- [fixbug] normalize directory separator
1.0.0
- release 1.0.0
- [change] drastic change
- [feature] add "function" method
- [feature] add "foreach" method
- [feature] support "Throws" multiple arguments
0.2.0
- [feature] add "var" method
- [feature] add "use" method
- [feature] add "print" method
- [feature] add "return" method
- [feature] add "OutputMatches" constraint
- [change] delete "autoback" method
- [change] rename class/method
0.1.0
- [feature] add "*All" method
- [feature] add "try" method
- [feature] add "message" method
- [feature] add "__invoke" method
- [feature] add "file*" constraint
- [feature] replace with original "logical*" constraint
- [feature] variation adds "is" alias
- [feature] variation supports anonymouse class
- [fixbug] variation ignores arguments
- [change] get/call can access no-public member
0.0.0
- publish
License
MIT