open-popo
Small library for quick testing your Plain Old PHP Objects., (*1)
(inspired by open-pojo), (*2)
Installation
composer require smt/open-popo
Usage
Example
<?php
use Smt\OpenPopo\Reflection\PopoClass;
use Smt\OpenPopo\Validator\Validator;
use Smt\OpenPopo\Rule\Impl\GetterMustExist;
use Smt\OpenPopo\Rule\Impl\SetterMustExist;
use Smt\OpenPopo\Tester\Impl\GetterTester;
use Smt\OpenPopo\Tester\Impl\FluentSetterTester; // You can also remove "Fluent" prefix if you don't want to check
// this functional
class EntityTest extends PHPUnit_Framework_TestCase
{
public function testAll()
{
Validator::create()
->addRule(GetterMustExist::create())
->addRule(
SetterMustExist::create()
->skip('iWantThisPropertyToHaveNoSetter')
)
->addTester(GetterTester::create())
->addTester(FluentSetterTester::create())
->validate(PopoClass::fromClassName(Entity::class)
;
}
}
Notes (need to rewrite into documentation)
Available rules:, (*3)
GetterMustExist
SetterMustExist
Available testers:, (*4)
-
GetSetTester
deprecated
-
FluentGetSetTester
deprecated
GetterTester
SetterTester
FluentSetterTester
Planned:, (*5)
- Collection rules/testers (
add*
/remove*
)
Every rule and tester:, (*6)
- has
skip
method to specify properties to skip
- can be instantiated directly (via
new
) or via factory method (::create()
)
Validator can be instantiated directly (via new
) or via factory method (::create()
), (*7)
License
This package is licensed under MIT license, (*8)