Download the PHP package nette/tester without Composer
On this page you can find all versions of the php package nette/tester. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package tester
Short Description Nette Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏
License BSD-3-Clause GPL-2.0-only GPL-3.0-only
Homepage https://tester.nette.org
Informations about the package tester
<!---->
Introduction
Nette Tester is a productive and enjoyable unit testing framework. It's used by the Nette Framework and is capable of testing any PHP code.
Documentation is available on the Nette Tester website. Read the blog for new information.
<!---->
Support Tester
Do you like Nette Tester? Are you looking forward to the new features?
Thank you!
<!---->
Installation
The recommended way to install Nette Tester is through Composer:
Alternatively, you can download the tester.phar file.
Nette Tester 2.5 is compatible with PHP 8.0 to 8.4. Collecting and processing code coverage information depends on Xdebug or PCOV extension, or PHPDBG SAPI.
<!---->
Writing Tests
Imagine that we are testing this simple class:
So we create test file named greeting.test.phpt
:
Thats' all!
Now we run tests from command-line using the tester
command:
Nette Tester prints dot for successful test, F for failed test and S when the test has been skipped.
<!---->
Assertions
This table shows all assertions (class Assert
means Tester\Assert
):
Assert::same($expected, $actual)
- Reports an error if $expected and $actual are not the same.Assert::notSame($expected, $actual)
- Reports an error if $expected and $actual are the same.Assert::equal($expected, $actual)
- Like same(), but identity of objects and the order of keys in the arrays are ignored.Assert::notEqual($expected, $actual)
- Like notSame(), but identity of objects and arrays order are ignored.Assert::contains($needle, array $haystack)
- Reports an error if $needle is not an element of $haystack.Assert::contains($needle, string $haystack)
- Reports an error if $needle is not a substring of $haystack.Assert::notContains($needle, array $haystack)
- Reports an error if $needle is an element of $haystack.Assert::notContains($needle, string $haystack)
- Reports an error if $needle is a substring of $haystack.Assert::true($value)
- Reports an error if $value is not true.Assert::false($value)
- Reports an error if $value is not false.Assert::truthy($value)
- Reports an error if $value is not truthy.Assert::falsey($value)
- Reports an error if $value is not falsey.Assert::null($value)
- Reports an error if $value is not null.Assert::nan($value)
- Reports an error if $value is not NAN.Assert::type($type, $value)
- Reports an error if the variable $value is not of PHP or class type $type.Assert::exception($closure, $class, $message = null, $code = null)
- Checks if the function throws exception.Assert::error($closure, $level, $message = null)
- Checks if the function $closure throws PHP warning/notice/error.Assert::noError($closure)
- Checks that the function $closure does not throw PHP warning/notice/error or exception.Assert::match($pattern, $value)
- Compares result using regular expression or mask.Assert::matchFile($file, $value)
- Compares result using regular expression or mask sorted in file.Assert::count($count, $value)
- Reports an error if number of items in $value is not $count.Assert::with($objectOrClass, $closure)
- Executes function that can access private and protected members of given object via $this.
Testing exceptions:
Testing PHP errors, warnings or notices:
Testing private access methods:
<!---->
Tips and features
Running unit tests manually is annoying, so let Nette Tester to watch your folder with code and automatically re-run tests whenever code is changed:
Running tests in parallel is very much faster and Nette Tester uses 8 threads as default. If you wish to run the tests in series use:
How do you find code that is not yet tested? Use Code-Coverage Analysis. This feature
requires you have installed Xdebug or PCOV
extension, or you are using PHPDBG SAPI. This will generate nice HTML report in coverage.html
.
We can load Nette Tester using Composer's autoloader. In this case it is important to setup Nette Tester environment:
We can also test HTML pages. Let the template engine generate
HTML code or download existing page to $html
variable. We will check whether
the page contains form fields for username and password. The syntax is the
same as the CSS selectors:
For more inspiration see how Nette Tester tests itself.
<!---->
Running tests
The command-line test runner can be invoked through the tester
command (or php tester.php
). Take a look
at the command-line options: