PHP code example of memran / php-testify

1. Go to this page and download the library: Download memran/php-testify 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/ */

    

memran / php-testify example snippets




return [
    'bootstrap' => __DIR__ . '/vendor/autoload.php',
    'test_patterns' => [
        __DIR__ . '/tests/*Test.php',
        __DIR__ . '/tests/*_test.php',
    ],
];



declare(strict_types=1);

use function Testify\describe;
use function Testify\expect;
use function Testify\it;

describe('cart totals', function (): void {
    it('adds line items', function (): void {
        $items = [12, 8, 5];

        expect(array_sum($items))->toBe(25);
        expect($items)->toHaveLength(3);
    });
});



declare(strict_types=1);

use function Testify\describe;
use function Testify\expect;
use function Testify\it;

describe('cart totals', function (): void {
    it('adds line items', function (array $items, int $expected): void {
        expect(array_sum($items))->toBe($expected);
    })->with([
        'two items' => [[12, 8], 20],
        'three items' => [[12, 8, 5], 25],
    ])->group('cart', 'fast');
})->group('unit');



declare(strict_types=1);

use function Testify\beforeEach;
use function Testify\describe;
use function Testify\expect;
use function Testify\it;

describe('account state', function (): void {
    $balance = 0;

    beforeEach(function () use (&$balance): void {
        $balance = 100;
    });

    it('withdraws funds', function () use (&$balance): void {
        $balance -= 40;

        expect($balance)->toBe(60);
        expect($balance)->not()->toBe(100);
    });
});



declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class InvoiceCalculatorTest extends TestCase
{
    public function testRoundsTaxAmount(): void
    {
        self::assertSame(13, (int) round(12.6));
    }
}



declare(strict_types=1);

use function Testify\describe;
use function Testify\expect;
use function Testify\it;

describe('invoice presentation', function (): void {
    it('contains a currency symbol', function (): void {
        expect('$12.50')->toContain('$');
    });
});



declare(strict_types=1);

use function Testify\describe;
use function Testify\incomplete;
use function Testify\it;
use function Testify\skip;

describe('feature rollout', function (): void {
    it('ships later', function (): void {
    })->skip('waiting for backend support');

    it('needs more implementation', function (): void {
        incomplete('validation rules still missing');
    });

    it('is planned work', function (): void {
        todo('queued for next sprint');
    });
});

expect($value)->toBe('exact');
expect($value)->toEqual(['loose' => 'match']);
expect($value)->toBeTruthy();
expect($value)->toBeGreaterThan(10);
expect($value)->toBeGreaterThanOrEqual(10);
expect($array)->toContain('item');
expect($array)->toHaveCount(3);
expect($array)->toHaveKey('name');
expect($array)->toHaveKeyWithValue('role', 'admin');
expect('php-testify')->toStartWith('php');
expect('php-testify')->toEndWith('fy');
expect('php-testify')->toMatch('/test/i');
expect(3.14159)->toBeCloseTo(3.14, 0.01);
expect($callable)->toThrow(RuntimeException::class);
expect($callable)->toThrowWithMessage(RuntimeException::class, 'boom');
expect($callable)->toThrowWithCode(RuntimeException::class, 42);
expect($object)->toBeInstanceOf(User::class);
expect($object)->not()->toBeSameObject($otherObject);
bash
composer 
bash
php bin/testify
bash
php bin/testify --filter invoice
php bin/testify --group api
php bin/testify --group api --exclude-group slow
php bin/testify --verbose
php bin/testify --watch