Verde

a BDD Style Library for your PHP Tests

Get Started →

BDD Style

Easy and clear syntax inspired to Jest and Jasmine

Spy Everything

Spy on Function and Classes with the power of runkit

Easy mocking

Easy to use syntax for mocking class

# Quick start

composer require "verdephp/verde" --dev

# BDD Style syntax

Easy and clear syntax inspired to Jest and Jasmine

<?php
use function Verde\expect;

$answer = 42;
expect($answer, 'The Answer to Everything')->toBe(42);

# Spy Everything

Easy and clear syntax inspired to Jest and Jasmine

<?php
use function Verde\expect;
use function Verde\spyOn;

function getAnswerToEverything() {
    return 42;
}

$spy = spyOn('getAnswerToEverything'); 

getAnswerToEverything();
expect($spy)->toHaveBeenCalledWith();

NOTE: Spies require runkit7 to work!

# Easy mocking

Easy to use syntax for mocking class

<?php
use function Verde\expect;
use function Verde\mock;

class DummyClass {
    public function doSomething(): string
    {
        return 'done';
    }
}

function doIt() {
    $dummy = new \Verde\Test\DummyClass();
    
    return $dummy->doSomething();
}

$func = func(function () { return 'ciao'; });

$mock = mock(DummyClass::class, [
    'doSomething' => $func
]);

$result = doIt();

expect($func)->toHaveBeenCalledWith();
expect($result)->toBe('ciao');

NOTE: Mocking a class requires runkit7 to work!