Tester - Unit Testing for Php
Its a unit testing library. But phpunit is probably better.
New Features (beta)
- internet server testing
- run tests like
phptest -host production
- the
host
config lists urls to use forget()
&post()
requests
- run tests like
- multi-server (localhost) support.
- The
server.dir
&server.router
configs are the old version which will likely be removed inv0.4
- the
server
config defines deliver scripts. Start your servers withphptest server [name of server]
& specify the server name when callingget()
orpost()
- The
Install
composer require taeluf/tester v0.3.x-dev
or in your composer.json
{"require":{ "taeluf/tester": "v0.3.x-dev"}}
Usage
In a terminal, run phptest
or ./vendor/bin/phptest
from your project root. (depending whether you installed via bash or composer)
Example Test class:
See the available assertions below
<?php
namespace Tlf\Tester\Test\Runner;
class NestedTest extends \Tlf\Tester {
/** called before tests are run */
public function prepare(){}
/** Test methods must prefix with `test` */
public function testAnything(){
$this->compare(true,true);
}
}
Sample config
This goes at test/config.json
. This is a copy of the config file for tests of this lib.
Note: The multi-server support is in beta & may change.
{
"dir.test":["test/run"],
"dir.exclude":[],
"file.require":["test/bootstrap.php"],
"dir.require":["test/src"],
"results.writeHtml":false,
"server.dir":"test/Server/",
"server.router":"deliver.php",
"servers":{
"1":"test/Server1/deliver.php",
"2":"test/Server2/deliver.php"
},
"host":{
"production":"https://some-site-whatever.whatever",
"test":"https://some-site-whatever.whatever"
},
"bench.threshold": 0.0001,
"test":[],
"class":[]
}
cli
-
phptest init
to initialize test setups for a new project -
phptest server
to run a localhost php development server, used for testing-
phptest server NAME
to specify a specific server to run (theservers
config)
-
-
phptest -host NAME
to run server tests on the configured host url -
phptest -test TestName
to only run the given test. Multiple-test TestName
flags can be given -
phptest -class ClassName
where for\Ns\Test\ClassName
, you just passClassName
. accepts multiple-class
flags. - any other flags found in test/config.json can be passed as to
phptest
as well.
Available Assertions
I'll properly document assertions after I write the php grammar for my taeluf/php/lexer
See code/Tester/Assertions.php and for other functionality, see the traits in code/Tester/
Alternate Installation
This also requires code-scrawl for development, which is not handled by this script.
copy+paste this into a bash terminal
pwd="$(pwd)";
command="phptest"
downloadDir=~/.gitclone
mkdir -p "$downloadDir"
cd "$downloadDir"
git clone https://gitlab.com/taeluf/php/php-tests.git ${command}
echo "alias ${command}=\"${downloadDir}/${command}/code/phptest\"" >> ~/.bashrc
chmod ug+x "${downloadDir}/${command}/code/phptest"
cd "$pwd";
source ~/.bashrc
echo "You can now run \`${command}\`"