Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.
 
 

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Hamcrest Object Accessor

This package extends the collection of matchers in Hamcrest. For general informationan about Hamcrest please visit their website. It's worth it ^^.

hasProperty

This Matcher tries to access a property of an object by name. It uses Getters, public properties, hassers and issers.

Example Class

class HasPropertyFixture
{
    public $bla = 'blub';
    private $getable = 'blub';
    private $issable = true;
    private $hassable = true;
    private $notGettable = 'nope';

    public function getGetable()
    {
        return $this->getable;
    }

    public function isIssable()
    {
        return $this->issable;
    }

    public function hasHassable()
    {
        return $this->hassable;
    }
}

Matcher

$object = new hasPropertyFixture();
MatcherAssert::assertThat(
    $object, 
    hasProperty(
        'bla', // property name
        stringValue() // matcher the property value has to match
    )
);

MatcherAssert::assertThat(
    $object, 
    hasProperty(
        'Getable', 
        stringValue()
    )
);

MatcherAssert::assertThat(
    $object, 
    hasProperty(
        'isIssable', 
        boolValue()
    )
);

Installation

You may include this package by composer.

composer require --dev sebastianknott/hamcrest-object-accessor

I recommend to use this matcher in dev environments only!

Setup

Once the Package is installed you can call the matcher staticly ...

HasProperty::hasProperty('bla', stringValue()));

... or by requiring src/functions.php provided by this package.

About

This repository contains another matcher for hamcrest

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages