Download the PHP package radziuk/php-tt without Composer
On this page you can find all versions of the php package radziuk/php-tt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download radziuk/php-tt
More information about radziuk/php-tt
Files in radziuk/php-tt
Package php-tt
Short Description Docblock unit tests library, unit test methods of your class directly in your doc block
License MIT
Informations about the package php-tt
Install the package
Run tests
Use Laravel integrated runner
Specify the folder
By default the runner uses the "app" folder to look for tests. You can specify a custom folder
Self-test the package
After the package is install you can run the selftest script included in the package
Should input something like this:
Test examples
Simple test, pass "hello" to the function, should return "hello"
Text example #2
Text example #3
Text example #4, passing an array
Text example #5, calling a method on the object before testing
Text example #6, mocking $this->... method
Text example #7, mocking method of a dependency
Text example #8, mocking global functions and methods
Text example #9, mocking a property
Text example #10, mocking anything
Define your test data in a separate file
By default, the runner is looking for tests/php-tt-data folder, so you can create your data files there
Create a data file
In your data file
In your class
Use custom keys in your data file. The default key is the method name.
In your data file
In your class
Use data files to create mocks
In your class
In your data file
Other assertions
Assert exception.
This asserts that the method will throw any exception
This asserts that the method will throw an exception of a certain class
Assert exception contains
This asserts that the method will throw an exception and the message will contain the text
Assert contains & preg
This asserts that the result will contain the specified substring
This asserts that the result will match the specified regular expression
Assert callable
This assertion allows you do define a callable that will handle the result of the method's execution and perform comparison with the expected result
In your tests/php-tt-data/TestData.php
Pass more parameters
In your tests/php-tt-data/TestData.php
Create an alias
In your tests/php-tt-data/TestData.php
Use custom data folder
Increase verbosity of the output
Any 1-digit number is interpreted as verbosity level. You can specify you custom folder and verbosity level like the following:
Create your custom runner
Support of traits
As of version 0.3 the support of trait has been added. During the testing, an anonymous class implementing the trait is initialized. To override this default behaviour you can use @php-tt-use-class
Laravel integration
lararun.php
lararun.php boots your laravel without database, logs and other providers, so in your tests you have access to lots of Laravel functionality, eg. facades, various providers etc Please note that currently lararun.php is in alpha version, and it is highly recommended to mock out all the code that can cause permanent changes to your data
Create your custom Laravel command
In app/Console/Commands/PhpTT.php
In app/Console/Kernel.php
Create your custom assertion (same as alias)
In your tests