phodam / phodam
A library to provide populated objects for testing
dev-main
2022-11-25 17:40 UTC
Requires (Dev)
- friendsofphp/php-cs-fixer: ~3.8
- phpstan/extension-installer: 1.2.x-dev
- phpstan/phpstan: ~1.7
- phpstan/phpstan-phpunit: 1.1.x-dev
- phpunit/phpunit: ~9.5
- squizlabs/php_codesniffer: ~3.6
This package is auto-updated.
Last update: 2025-05-17 04:02:55 UTC
README
Phodam is inspired by PODAM.
Phodam (pronounced Faux-dam) is a PHP library used to generate objects for unit tests. The main feature of PODAM is that you can give it a class and it generates a populated Object with all fields populated.
Phodam, in its current state, will populate objects as long as it's given a TypeProviderInterface
for a specific class.
Usage
Basic Usage
$value = $this->phodam->create(SimpleType::class);
Populating a Type with untyped fields
// Since PHP classes don't require types on fields, you may need to provide some hints // You only need to provide field definitions for fields that can't automatically be mapped $definition = [ 'myInt' => new FieldDefinition('int'), 'myString' => new FieldDefinition('string') ]; $this->phodam->registerTypeDefinition(SimpleTypeMissingSomeFieldTypes::class, $definition); $value = $this->phodam->create(SimpleTypeMissingSomeFieldsTypes::class);
Populating a Type with array (list) fields
$definition = [ 'myArray' => (new FieldDefinition(SimpleType::class)) ->setArray(true) ]; $this->phodam->registerTypeDefinition(SimpleTypeWithAnArray::class, $definition); $value = $this->phodam->create(SimpleTypeWithAnArray::class);
Local Build
./quickBuild.sh