<?php require '../vendor/autoload.php'; use Testify\Testify; $tf = new Testify("Testify test himself"); $test = new Testify("//"); $tf->before(function ($tf) use($test) { $test->data->arr = array(1, 2, 3); }); $tf->test("Pass/Fail test", function ($tf) use($test) { $tf->assert(true, "To be sure that initial test pass !"); $tf->assertFalse(false); $tf->assert($test->pass()); $tf->assertFalse(!$test->pass()); $tf->assert(!$test->fail()); $tf->assertFalse($test->fail()); }); $tf->test("Basic assert test", function ($tf) use($test) { $tf->assert($test->assert(true)); $tf->assert(!$test->assert(false)); $tf->assertFalse($test->assert(false)); $tf->assertFalse(!$test->assert(true)); }); $tf->test("assertEquals/assertNotEquals test", function ($tf) use($test) { $tf->assert($test->assertEquals(1, 1)); $tf->assert($test->assertEquals(-1337, '-1337')); $tf->assert($test->assertEquals(42.0, 42)); $tf->assert($test->assertEquals(0, null)); $tf->assert($test->assertEquals(0, "")); $tf->assert($test->assertEquals(1, true)); $tf->assert($test->assertEquals(array(0, 1, 1), array(false, "1", true)));
<?php use Testify\Testify; require '_routerBootstrap.php'; define("URL", "http://localhost/Via/test/"); require __DIR__ . '/../vendor/autoload.php'; $tf = new Testify("Via special tests"); $tf->test("Rewrite engine", function ($tf) { $url = URL . "rewriteEngine.php"; $urlClean = substr(URL, 0, -1); $req = Requests::get($url . '/test/'); $tf->assertSame($req->body, '/test/*', '/test/'); $req = Requests::get($urlClean . '/test/'); $tf->assertSame($req->body, '/test/*', '/test/ [rewrite]'); $req = Requests::get($url . '/test/asd'); $tf->assertSame($req->body, '/test/*', '/test/asd'); $req = Requests::get($urlClean . '/test/asd'); $tf->assertSame($req->body, '/test/*', '/test/asd [rewrite]'); $req = Requests::get($url . '//test'); $tf->assertSame($req->body, '/*/test', '//test'); $req = Requests::get($urlClean . '//test'); $tf->assertSame($req->body, '/*/test', '//test [rewrite]'); }); $tf();
/* * A more complex example using beforeEach and data * */ require '../vendor/autoload.php'; use Testify\Testify; $tf = new Testify("A bit more advanced test suite"); // Before each is called before every test case $tf->beforeEach(function ($tf) { // Use the data property to share variables across tests $tf->data->arr = array('a', 'b', 'c', 'd', 'e', 'f'); }); $tf->test("Testing Array Pop", function ($tf) { $arr =& $tf->data->arr; $tf->assertEquals(array_pop($arr), 'f'); $tf->assertEquals(array_pop($arr), 'e'); $tf->assertEquals(array_pop($arr), 'd'); $tf->assertEquals(array_pop($arr), 'c'); }); $tf->test("Testing In Array", function ($tf) { // beforeEach has restored the array $arr =& $tf->data->arr; $tf->assertInArray('a', $arr); $tf->assertInArray('b', $arr); $tf->assertInArray('c', $arr); $tf->assertInArray('d', $arr); $tf->assertInArray('e', $arr); $tf->assertInArray('f', $arr); $tf->assertNotInArray('g', $arr); }); # It is even possible to include additional files with tests:
<?php /* * This is a minimal example of Testify * */ require '../vendor/autoload.php'; use Testify\Testify; $tf = new Testify("A basic test suite."); // Add a test case $tf->test("Just testing around", function ($tf) { $tf->assert(true, "Must pass !"); $tf->assertFalse(false); $tf->assertEquals(1, '1'); $tf->assertSame(1, 1); $tf->assertInArray('a', array(1, 2, 3, 4, 5, 'a')); $tf->pass("Always pass"); }); $tf->test("I've got a bad feeling about this one", function ($tf) { $tf->assert(false); $tf->assertFalse(true); $tf->assertEquals(1, '-21'); $tf->assertSame(1, '1'); $tf->assertInArray('b', array(1, 2, 3, 4, 5, 'a')); $tf->fail(); }); $tf();
<?php require 'vendor/autoload.php'; use Testify\Testify; $tf = new Testify("My test suite"); // add a test case $tf->test("Some tests", function ($tf) { $tf->assert(true); $tf->assertFalse(!true); $tf->assertEquals(1337, '1337'); $tf->assertNotEquals(array('a', 'b', 'c'), array('a', 'c', 'd'), "Not the same order"); $tf->assertEquals(new stdClass(), new stdClass(), "Classes are equals"); }); $tf->test(function ($tf) { $tf->assert(true, "Always true !"); $tf->assertSame(1024, pow(2, 10)); $tf->assertNotSame(new stdClass(), new stdClass(), "Not the same classes !"); }); $tf(); // run all tests