GithubHelp home page GithubHelp logo

phpower's Introduction

phpower

Latest Stable Version Latest Unstable Version License

Implement assertion like Power Assert in PHP.

Install

composer require --dev phpunit/phpunit ngyuki/phpower:dev-master

Example

Write test code with assert.

<?php
namespace Test;

use PHPUnit\Framework\TestCase;

class SomeTest extends TestCase
{
    public function test_01()
    {
        $a = 1;
        $b = 2;
        $c = 3;
        assert(($a + ($b + 3)) === ($c * 3));
    }

    public function test_02()
    {
        $s = "x\ny\nz";
        assert("a\nb\nc" === strrev($s));
    }

    public function test_03()
    {
        $a = [1,2,3];
        $b = [7,8,9];
        assert($a == array_reverse($b));
    }

    public function test_ok()
    {
        $a = [1,2,3];
        $b = [3,2,1];
        assert($a == array_reverse($b));
    }
    public function test_04()
    {
        $a = [
            'name' => 'alice',
            'uid' => 1000,
            'gid' => 1000,
        ];
        assert($a == [
            'name' => 'bob',
            'uid' => 2000,
            'gid' => 2000,
        ]);
    }
}

Run the test.

vendor/bin/phpunit tests/example/

The following result is displayed.

PHPUnit 8.5.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.4.2
Configuration: /path/to/phpower/phpunit.xml.dist

FFF.F                                                               5 / 5 (100%)

Time: 261 ms, Memory: 4.00 MB

There were 4 failures:

1) Test\SomeTest::test_01
Assertion failed ($a + ($b + 3)) === ($c * 3) -> false
# $a -> 1
# $b -> 2
# $b + 3 -> 5
# $a + ($b + 3) -> 6
# $c -> 3
# $c * 3 -> 9

/path/to/phpower/tests/example/SomeTest.php:13

2) Test\SomeTest::test_02
Assertion failed "a\nb\nc" === strrev($s) -> false
# $s -> "x\ny\nz"
# strrev($s) -> "z\ny\nx"

/path/to/phpower/tests/example/SomeTest.php:19

3) Test\SomeTest::test_03
Assertion failed $a == array_reverse($b) -> false
# $a
#  -> [
#       1,
#       2,
#       3,
#     ]
#
# $b
#  -> [
#       7,
#       8,
#       9,
#     ]
#
# array_reverse($b)
#  -> [
#       9,
#       8,
#       7,
#     ]
#

/path/to/phpower/tests/example/SomeTest.php:26

4) Test\SomeTest::test_04
Assertion failed $a == ['name'=>'bob','uid'=>2000,'gid'=>2000,] -> false
# $a
#  -> [
#       "name" => "alice",
#       "uid" => 1000,
#       "gid" => 1000,
#     ]
#

/path/to/phpower/tests/example/SomeTest.php:46

FAILURES!
Tests: 5, Assertions: 5, Failures: 4.

Limitations

Only for phpunit installed locally in project with composer (phpunit.phar is not supported).

LICENCE

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.