sebastianknott / hamcrest-object-accessor
Adds a Matcher to Hamcrest which can access properties and methods of objects.
Package info
github.com/sebastianknott/hamcrestObjectAccessor
pkg:composer/sebastianknott/hamcrest-object-accessor
Requires
- php: ^8.3
- hamcrest/hamcrest-php: ^2.0
- symfony/property-access: ^4|^5|^6|^7|^8
Requires (Dev)
- infection/infection: >=0.29.14 <1.0
- mockery/mockery: 1.6.11
- phpunit/phpunit: ~12.0.7
- psalm/plugin-phpunit: ^0.19.2
- roave/security-advisories: dev-master
- sebastianknott/coding-standard: ^2.3.1
- vimeo/psalm: ^6.8.9
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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.