PHP code example of v2e4lisp / preview

1. Go to this page and download the library: Download v2e4lisp/preview library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

v2e4lisp / preview example snippets



namespace Preview\DSL\BDD;

;

describe("Stack", function () {
    before_each(function () {
        $this->stack = new \Stack(array(1,2,3));
    });

    describe("#size", function () {
        it("returns the size of stack", function () {
            ok($this->stack->size() == 3);
        });
    });

    describe("#peek", function () {
        it("returns the last element", function () {
            ok($this->stack->peek() == 3);
        });
    });

    describe("#push", function () {
        it("pushes an element to stack", function () {
            $this->stack->push(4);
            ok($this->stack->peek() == 4);
            ok($this->stack->size() == 4);
        });
    });

    describe("#pop", function () {
        it("pops out the last element", function () {
            ok($this->stack->pop() == 3);
            ok($this->stack->size() == 2);
        });
    });
});


namespace Preview\DSL\TDD;

;

suite("Stack", function () {
    setup(function () {
        $this->stack = new \Stack(array(1,2,3));
    });

    suite("#size", function () {
        test("returns the size of stack", function () {
            ok($this->stack->size() == 3);
        });
    });

    suite("#peek", function () {
        test("returns the last element", function () {
            ok($this->stack->peek() == 3);
        });
    });

    suite("#push", function () {
        test("pushes an element to stack", function () {
            $this->stack->push(4);
            ok($this->stack->peek() == 4);
            ok($this->stack->size() == 4);
        });
    });

    suite("#pop", function () {
        test("pops out the last element", function () {
            ok($this->stack->pop() == 3);
            ok($this->stack->size() == 2);
        });
    });
});


namespace Preview\DSL\Qunit;


suite("Stack");

setup(function () {
    $this->stack = new \Stack(array(1,2,3));
});

test("#size returns the size of stack", function () {
    ok($this->stack->size() == 3);
});

test("#peek eturns the last element", function () {
    ok($this->stack->peek() == 3);
});

test("#push pushes an element to stack", function () {
    $this->stack->push(4);
    ok($this->stack->peek() == 4);
    ok($this->stack->size() == 4);
});

test("#pop pops out the last element", function () {
    ok($this->stack->pop() == 3);
    ok($this->stack->size() == 2);
});


namespace Preview\DSL\Export;

$suite = array(
    "before each" => function () {
        $this->stack = new \Stack(array(1,2,3));
    },

    "#sizereturns the size of stack" => function () {
        ok($this->stack->size() == 3);
    },

    "#peek eturns the last element" => function () {
        ok($this->stack->peek() == 3);
    },

    "#push pushes an element to stack" => function () {
        $this->stack->push(4);
        ok($this->stack->peek() == 4);
        ok($this->stack->size() == 4);
    },

    "#pop pops out the last element" => function () {
        ok($this->stack->pop() == 3);
        ok($this->stack->size() == 2);
    }
);

export("Stack", $suite);


namespace Preview\DSL\Testify;

suite = new Suite("Stack[testify]");

$suite->before_each(function () {
    $this->stack = new \Stack(array(1,2,3));

})->test("#size returns the size of stack", function () {
    ok($this->stack->size() == 3);

})->test("#peek eturns the last element", function () {
    ok($this->stack->peek() == 3);

})->test("#push pushes an element to stack", function () {
    $this->stack->push(4);
    ok($this->stack->peek() == 4);
    ok($this->stack->size() == 4);

})->test("#pop pops out the last element", function () {
    ok($this->stack->pop() == 3);
    ok($this->stack->size() == 2);

})->load();