예제 #1
0
 public function run(Testify &$testify)
 {
     foreach ($this->classes as $class) {
         $fullyQualifiedClass = $class;
         $test = new $fullyQualifiedClass($this->preParser);
         //the idea here is to take WYSIWYGWikiLingo Markup, and to turn it into WikiLingo Markup, so source comes from the WikiLingoWYSIWYG Parser
         $actual = $this->parser->parse($test->source);
         $test->source = preg_replace('/\\r/', "", $test->source);
         $actual = preg_replace('/\\r/', "", $actual);
         $test->expected = preg_replace('/\\r/', "", $test->expected);
         $message = (new WikiLingo\Test\VisualFeedbackTable($class))->setSource($test->source)->setExpected($test->expected)->setActual($actual)->render();
         $testify->assertEquals($actual, $test->expected, $message);
     }
 }
예제 #2
0
 /**
  * @param Testify $testify
  */
 public function run(Testify &$testify)
 {
     foreach ($this->classes as $class) {
         $test = new $class($this->parser);
         if (!property_exists($test, 'source')) {
             continue;
         }
         $actual = $this->parser->parse($test->source);
         $test->source = preg_replace('/\\r/', "", $test->source);
         $actual = preg_replace('/\\r/', "", $actual);
         $test->expected = preg_replace('/\\r/', "", $test->expected);
         $table = (new VisualFeedbackTable($class))->setSource($test->source)->setExpected($test->expected)->setActual($actual);
         if ($actual === null) {
             $table->setErrors($this->parser->lexerErrors, $this->parser->parserErrors);
         } else {
             if (!empty($test->postParseDelegates)) {
                 $test->triggerPostParse($this);
             }
         }
         $this->parser->lexerErrors = array();
         $this->parser->parserErrors = array();
         $message = $table->render();
         $testify->assertEquals($actual, $test->expected, $message);
         $this->parser->clearTypes();
     }
 }
예제 #3
0
<?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)));
예제 #4
0
파일: index.php 프로젝트: enpowi/enpowi
<?php

define('testing', true);
require_once '../modules/index.php';
use Testify\Testify;
use Enpowi\App;
use RedBeanPHP\R;
$tf = new Testify(App::$config->siteName . ' Test Suite');
$tf->beforeEach(function () {
    R::nuke();
});
$di = new RecursiveDirectoryIterator('server', RecursiveDirectoryIterator::SKIP_DOTS);
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
    require $filename;
}
$tf();
예제 #5
0
<?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();
예제 #6
0
<?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();
예제 #7
0
<?php

/*
 * 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);
예제 #8
0
<?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