klever / tutor
PHPUnit Extensions to easily spec-test data models
Installs: 20 402
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.0|^5.5
- phpunit/phpunit: ^5.0|^4.8
Requires (Dev)
- humbug/humbug: dev-master
- jakub-onderka/php-parallel-lint: ^0.9
- phing/phing: ^2.9
- squizlabs/php_codesniffer: ^2.5
This package is not auto-updated.
Last update: 2024-11-07 19:28:59 UTC
README
Easily test accessor methods on your models by providing a spec in your test case.
Installation
composer require --dev klever/tutor
Usage
Extend \Klever\Tutor\AccessMethod\AbstractTestCase
and provide a spec for your model.
Example
\Klever\TutorTest\AccessMethod\AbstractTestCaseIntegrationTest
Configuration
\Klever\Tutor\AccessMethod\TestConfiguration::fromArray
accessor_name
Override for non-conventional getters.
Sample Class
class Model
{
private $foo;
public function getBar()
{
return $this->foo;
}
}
Sample Config
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'accessor_name' => 'getBar',
],
],
];
}
}
is_state_accessor
Use an is
accessor instead of a get
accessor.
Sample Class
class Model
{
private $foo = true;
public function isFoo()
{
return $this->foo;
}
}
Sample Config
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'is_state_accessor' => true,
],
],
];
}
}
default_value
Default value of a property.
Sample Class
class Model
{
private $foo = 'bar';
public function getFoo()
{
return $this->foo;
}
}
Sample Config
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'default_value' => 'bar',
],
],
];
}
}
injectable_value
Value set into a property. This will be validated as the expected_value
by default.
Sample Class
class Model
{
private $foo;
public function getFoo()
{
return $this->foo;
}
public function setFoo($foo)
{
$this->foo = $foo;
}
}
Sample Config
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'bar',
],
],
];
}
}
expected_value
Expected value of a property.
Sample Class
class Model
{
private $foo;
public function getFoo()
{
return $this->foo;
}
public function setFoo($foo)
{
$this->foo = $foo . 'bar';
}
}
Sample Config
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'foo',
'expected_value' => 'foobar',
],
],
];
}
}
injection_method_fluent
Validates that the setter returns the model.
Sample Class
class Model
{
private $foo;
public function setFoo($foo)
{
$this->foo = $foo;
return $this;
}
}
Sample Config
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'foo',
'injection_method_fluent' => true,
],
],
];
}
}
injector_name
Override for non-conventional setters.
Sample Class
class Model
{
private $foo;
public function setBar($bar)
{
$this->foo = $bar;
}
}
Sample Config
class ModelTest extends \Klever\Tutor\AccessMethod\AbstractTestCase
{
public function getClassAccessMethodTestConfiguration()
{
return [
'accessors' => [
'foo' => [
'injectable_value' => 'foo',
'injector_name' => 'setBar',
],
],
];
}
}
Dependencies
See composer.json.
Contributing
git clone git@github.com: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.