PHPackages                             r83dev/test-entity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. r83dev/test-entity

ActiveLibrary[Testing &amp; Quality](/categories/testing)

r83dev/test-entity
==================

Entity properties trait to test properties of an entity.

v1.2.0(1y ago)02.6k↓61.4%MITPHPPHP ^8.0

Since Apr 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/rengaw83/test-entity)[ Packagist](https://packagist.org/packages/r83dev/test-entity)[ RSS](/packages/r83dev-test-entity/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (2)Versions (6)Used By (0)

Testing Entities Trait
======================

[](#testing-entities-trait)

A helper class for testing, especially for unit tests to easily test properties of entities or data transfer objects.

Installation
------------

[](#installation)

Install via composer:

```
dcrr composer req --dev r83dev/test-entity

```

Usage
-----

[](#usage)

Use the `EntityPropertiesTrait` in your test and create `getEntityClass` and `getEntityProperties` methods:

Example entity `MyEntity````
class MyEntity
{
    private int $id;

    private string $name = '';

    private ?Collection $categories;

    private bool $active = false;

    public function __construct(
        private readonly string $key
    ) {
        $this->categories = new ArrayCollection();
    }

    public function getId(): int
    {
        if (!isset($this->id)) {
            throw new \LogicException('Entity not yet initialized or made persistent.');
        }

        return $this->id;
    }

    public function getKey(): string
    {
        return $this->key;
    }

    public function getName(): string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

    public function getCategories(): Collection
    {
        return $this->categories;
    }

    public function setCategories(Collection $categories): self
    {
        $this->categories = $categories;

        return $this;
    }

    public function isActive(): bool
    {
        return $this->active;
    }

    public function setActive(bool $active): self
    {
        $this->active = $active;

        return $this;
    }
}
```

```
/**
 * @extends R83Dev\TestEntity\EntityPropertiesTrait
 */
class MyEntityTest {
    use R83Dev\TestEntity\EntityPropertiesTrait;

    /**
     * The entities fully qualified class name.
     */
    protected static function getEntityClass(): string
    {
        return MyEntity::class;
    }

    /**
     * Constructor arguments required to create the entity instance.
     * Required for entities with mandatory constructor arguments only
     */
    protected static function getEntityConstructorArguments(): array
    {
        return ['key'];
    }

    /**
     * All properties of the entity.
     * Properties can be private, protected, public, readonly, ...
     */
    protected static function getEntityProperties(): array
    {
        return [
            'id' => 5,
            'name' => 'My Entity',
            'categories' => new ArrayCollection(['category1']),
            'active' => true,
        ];
    }

    /**
     * Add your own custom tests to check special logic.
     */
    #[\PHPUnit\Framework\Attributes\Test]
    public function getIdThrowsException(): void
    {
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('Entity not yet initialized or made persistent.');
        $this->getEntity()->getId();
    }

}
```

The Trait will now test the getters, setters and issers of the properties

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance46

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Total

5

Last Release

409d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5131653?v=4)[Michael Wagner](/maintainers/rengaw83)[@rengaw83](https://github.com/rengaw83)

---

Top Contributors

[![rengaw83](https://avatars.githubusercontent.com/u/5131653?v=4)](https://github.com/rengaw83 "rengaw83 (6 commits)")

---

Tags

phpphpunitentitytesting-tools

### Embed Badge

![Health badge](/badges/r83dev-test-entity/health.svg)

```
[![Health](https://phpackages.com/badges/r83dev-test-entity/health.svg)](https://phpackages.com/packages/r83dev-test-entity)
```

###  Alternatives

[brianium/paratest

Parallel testing for PHP

2.5k136.1M985](/packages/brianium-paratest)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

77559.8k16](/packages/robiningelbrecht-phpunit-pretty-print)[juampi92/test-seo

Easy way to test your SEO

26346.2k](/packages/juampi92-test-seo)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

17143.1k51](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
