cycle / annotated

Schema generation using annotated entities and mappers
MIT License
23 stars 12 forks source link

Covers schema modifiers with tests #32

Closed butschster closed 2 years ago

butschster commented 2 years ago

For readme

Schema modifier

namespace App\SchemaModifiers;

use Cycle\ORM\SchemaInterface;
use Cycle\Schema\Registry;
use Cycle\Schema\SchemaModifierInterface;

/**
 * @Annotation
 * @Target({"CLASS"})
 * @Attributes({
 *      @Attribute("class", type="string", required=true)
 * })
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
class MapperSegmentSchemaModifier implements SchemaModifierInterface
{
    private string $role;
    private string $class;

    public function __construct(array $values)
    {
        foreach ($values as $key => $value) {
            $this->$key = $value;
        }
    }

    public function withRole(string $role): static
    {
        $this->role = $role;
        return $this;
    }

    public function compute(Registry $registry): void {}

    public function render(Registry $registry): void {}

    public function modifySchema(array &$schema): void
    {
        $schema[SchemaInterface::MAPPER] = $this->class;
    }
}

Entity

namespace App\Entities;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use App\SchemaModifiers\MapperSegmentSchemaModifier;

/**
 * @Entity
 * @MapperSegmentSchemaModifier(class=SuperMapper::class)
 */
#[Entity]
#[MapperSegmentSchemaModifier(class: SuperMapper::class)]
class Post
{
    /** @Column(type="integer", primary=true) */
    #[Column(type: 'integer', primary: true)]
    protected int $id;

    /** @Column(type="string") */
    #[Column(type: 'string')]
    protected string $name;
}
codecov[bot] commented 2 years ago

Codecov Report

Merging #32 (435df70) into 2.0 (3a53daa) will increase coverage by 0.22%. The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##                2.0      #32      +/-   ##
============================================
+ Coverage     90.54%   90.76%   +0.22%     
  Complexity      188      188              
============================================
  Files            16       16              
  Lines           444      444              
============================================
+ Hits            402      403       +1     
+ Misses           42       41       -1     
Impacted Files Coverage Δ
src/Configurator.php 86.06% <0.00%> (+0.81%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 3a53daa...435df70. Read the comment docs.