PHP code example of hshn / phpunit-object-constraint

1. Go to this page and download the library: Download hshn/phpunit-object-constraint 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/ */

    

hshn / phpunit-object-constraint example snippets



use Hshn\PHPUnit\Framework\Constraint\ObjectConstraintSupport;

class MyTest extends \PHPUnit_Framework_TestCase 
{
    use ObjectConstraintSupport;
}


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();
}

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