Git Product home page Git Product logo

sliver's Introduction

sliver

A simple, closure-based Test class.

Quick start

Rope in sliver as a Composer dependency:

# composer require --dev maxvu/sliver

Instantiate maxvu\sliver\Test, using a closure exhibiting the behavior to test as its only constructor argument.

<?php
use maxvu\sliver\Test;

$tests = [
    (new Test( function ( $test ) {
        # ...
    } ))->name( '1 + 1 = 2' );
];
?>

Use $test->assert() to capture a value and any of the following methods to apply expectations to it:

<?php
$test->assert( $a )->like( $b )       # $a == $b
$test->assert( $a )->eq( $b )         # $a === $b
$test->assert( $a )->ne( $b )         # $a != $b
$test->assert( $a )->gt( $b )         # $a > $b
$test->assert( $a )->ge( $b )         # $a >= $b
$test->assert( $a )->lt( $b )         # $a < $b
$test->assert( $a )->le( $b )         # $a <= $b
$test->assert( $a )->null( $b )       # $a === null
$test->assert( $a )->true( $b )       # $a === true
$test->assert( $a )->false( $b )      # $a === false
$test->assert( $a )->truthy( $b )     # $a
$test->assert( $a )->falsy( $b )      # !$a
$test->assert( $a )->contains( $b )   # in_array( $b, $a ) OR
                                      # false !== strpos( strval( $a ), strval( $b ) )
$test->assert( $a )->matches( $b )    # preg_match( $b, $a );
?>

Provide a list of these Tests to a maxvu\sliver\Runner (like maxvu\sliver\ConsoleRunner) and call run() on it:

<?php
require 'vendor/autoload.php';
use maxvu\sliver\Test;
use maxvu\sliver\ConsoleRunner;

(new ConsoleRunner([
    (new Test( function ( $test ) {
        $test->assert( 1 + 1 )->eq( 2 );
    } ))->name( '1 + 1 = 2' )
]))->show_passing( 1 )->run();
?>

Have printed out to the console information about each test:

$ php tests.php

    1 + 1 = 2 [ OK ] (0.00045s)

    1 / 1 tests passing (100.00%)
    2 / 2 conditions passing (100.00%)

$

sliver's People

Contributors

maxvu avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dseguy nevikkings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.