Skip to content

adhocore/asserts

Repository files navigation

adhocore/asserts

Latest Version Travis Build Scrutinizer CI Codecov branch StyleCI Software License

Installation

composer require --dev adhocore/asserts

Usage

use Ahc\Asserts\Asserts;
use PHPUnit\Framework\TestCase;

class MyTest extends Testcase
{
    use Asserts;

    public function testSomething()
    {
        $this->assertJsonSubset($expectedSubset, $actualJson);

        $this->assertJsonSubsets($expectedSubset1, $expectedSubset2, ... , $actualJson);

        $this->assertFloatEquals($expected = 1.66666666, $actual = 1.666666689, $precision = 4);

        $this->assertArrayHasKeys($expected = ['a', 'b'], $actual = ['a' => 1, 'b' => 2]);

        $this->assertIsAssocArray(['key' => 'value']);

        $this->assertIsNotAssocArray([1, 2, 3, 4, 5]);

        $this->assertFileIsExecutable('/bin/sh');

        $this->assertFileIsNotExecutable('/bin/not-found');

        $this->assertAll(
            $expectations = [
                'equals' => 1,
                'lessThan' => 10,
                'greaterThan' => 0,
            ],
            $actual = 1,
            $messages = [
                'greaterThan' => 'Should be postitive number',
            ]
        );
    }
}

Contributing

Please check the guide

LICENSE

© MIT | 2019, Jitendra Adhikari