phodam/phodam

A library to provide populated objects for testing

dev-main 2022-11-25 17:40 UTC

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