klever/tutor

There is no license information available for the latest version (v0.1.0-alpha) of this package.

PHPUnit Extensions to easily spec-test data models

v0.1.0-alpha 2016-09-12 23:46 UTC

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.

Build Status

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.