hshn/phpunit-object-constraint

Maintainers

Package info

github.com/hshn/phpunit-object-constraint

pkg:composer/hshn/phpunit-object-constraint

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v0.1.0 2018-01-17 15:20 UTC

This package is not auto-updated.

Last update: 2026-03-01 12:56:03 UTC


README

PHPUnit helper for explicit object comparison.

Make it easier to your apps more safety by providing easy object assertion.

How to use

1. Import helper trait into your class

use Hshn\PHPUnit\Framework\Constraint\ObjectConstraintSupport;

class MyTest extends \PHPUnit_Framework_TestCase 
{
    use ObjectConstraintSupport;
}

2. Build your object constraint using constraint builder

public function test1()
{
    // this constraint means: 
    //      property 'foo' start with 'a' and end with 'e'
    //  and property 'bar' is true 
    $constraint = $this->constraintFor(\stdClass::class)
        ->property('foo')
            ->stringStartsWith('a')
            ->stringEndsWith('e')
        ->property('bar')
            ->isTrue()
        ->getConstraint();
}

3. Assert any value with the constraint you built

self::assertThat($value, $constraint);