Exemplo n.º 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);
     }
 }
Exemplo n.º 2
0
$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)));
    $tf->assert($test->assertEquals(new \StdClass(), (object) array()));
    $tf->assert($test->assertNotEquals(-1, ""));
    $tf->assertFalse($test->assertEquals(-1, ""));
    $tf->assertFalse($test->assertEquals(array(1), 1));
    $tf->assertFalse($test->assertEquals(array(9, 8), (object) array(9, 8)));
    $tf->assertFalse($test->assertNotEquals(1.0, 1));
});
$tf->test("assertSame/assertNotSame test", function ($tf) use($test) {
    $tf->assert($test->assertSame(-1, -1));
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
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();
Exemplo n.º 5
0
/*
 * 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);
});
Exemplo n.º 6
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