Easily test accessor methods on your models by providing a spec in your test case.
composer require --dev klever/tutor
Extend \Klever\Tutor\AccessMethod\AbstractTestCase
and provide a spec for your model.
\Klever\TutorTest\AccessMethod\AbstractTestCaseIntegrationTest
\Klever\Tutor\AccessMethod\TestConfiguration::fromArray
Override for non-conventional getters.
class Model
{
private $foo;
public function getBar()
{
return $this->foo;
}
}
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'accessor_name' => 'getBar',
],
],
];
}
}
Use an is
accessor instead of a get
accessor.
class Model
{
private $foo = true;
public function isFoo()
{
return $this->foo;
}
}
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'is_state_accessor' => true,
],
],
];
}
}
Default value of a property.
class Model
{
private $foo = 'bar';
public function getFoo()
{
return $this->foo;
}
}
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'default_value' => 'bar',
],
],
];
}
}
Value set into a property. This will be validated as the expected_value
by default.
class Model
{
private $foo;
public function getFoo()
{
return $this->foo;
}
public function setFoo($foo)
{
$this->foo = $foo;
}
}
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'bar',
],
],
];
}
}
Expected value of a property.
class Model
{
private $foo;
public function getFoo()
{
return $this->foo;
}
public function setFoo($foo)
{
$this->foo = $foo . 'bar';
}
}
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'foo',
'expected_value' => 'foobar',
],
],
];
}
}
Validates that the setter returns the model.
class Model
{
private $foo;
public function setFoo($foo)
{
$this->foo = $foo;
return $this;
}
}
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'foo',
'injection_method_fluent' => true,
],
],
];
}
}
Override for non-conventional setters.
class Model
{
private $foo;
public function setBar($bar)
{
$this->foo = $bar;
}
}
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'foo',
'injector_name' => 'setBar',
],
],
];
}
}
See composer.json.
git clone [email protected]:tklever/tutor.git && cd tutor
composer update && vendor/bin/phing
This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.