PHP code example of sebastianknott / hamcrest-object-accessor
1. Go to this page and download the library: Download sebastianknott/hamcrest-object-accessor 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/ */
sebastianknott / hamcrest-object-accessor example snippets
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;
}
}
$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()
)
);