PHPackages                             r83dev/test-accessible - 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-accessible

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

r83dev/test-accessible
======================

Accessible trait to call protected methods, properties and constants in tests.

v1.2.0(8mo ago)04.0k↓35.4%1MITPHPPHP ^8.0

Since May 30Pushed 8mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (1)

Testing Accessible Trait
========================

[](#testing-accessible-trait)

A helper class for testing, especially for unit tests to access inaccessible methods or to get/inject properties.

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

[](#installation)

Install via composer:

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

```

Usage
-----

[](#usage)

Use the `AccessibleTrait` in your test:

```
class MyTest {
    use R83Dev\TestAccessible\AccessibleTrait;
}
```

Use one of the helper function to access private or protected stuff of an instantiated object.

### Methods

[](#methods)

#### Call inaccessible method

[](#call-inaccessible-method)

```
$this->callInaccessibleMethod($object, 'method_name', 'argument1', 'argument2', ...);
```

#### Get inaccessible property

[](#get-inaccessible-property)

```
$this->getInaccessibleProperty($object, 'property_name');
```

#### Set inaccessible property

[](#set-inaccessible-property)

```
$this->setInaccessibleProperty($object, 'property_name', 'new_property_value');
```

#### Set multiple inaccessible properties

[](#set-multiple-inaccessible-properties)

```
$this->setInaccessibleProperties($object, ['property_name' => 'new_property_value']);
```

#### Get inaccessible constant

[](#get-inaccessible-constant)

```
$this->getInaccessibleConstant($object, 'CONSTANT_NAME');
```

### PHPUnitTest Example

[](#phpunittest-example)

This is just a features demo, not useful in terms of content.

Example of a unit to be tested:

```
class MyUnit
{
    protected const STATE_ON = 'on';
    protected const STATE_OFF = 'off';
    private string $state = self::STATE_ON;

    protected function setState(string $state): void
    {
        $this->state = $state;
    }

    public function getState(): string
    {
        return $this->state;
    }
}
```

Example unittest:

```
class MyUnitTest extends PHPUnit\Framework\TestCase
{
    use R83Dev\TestAccessible\AccessibleTrait;

    private ?MyUnit $unit;

    protected function setUp(): void
    {
        $this->unit = new MyUnit();
    }

    #[\PHPUnit\Framework\Attributes\Test]
    public function getStateShouldReturnCorrectInitialValue(): void
    {
        $this->assertSame(
            $this->getInaccessibleConstant($this->unit, 'STATE_ON'),
            $this->getInaccessibleProperty($this->unit, 'state')
        );
    }

    #[\PHPUnit\Framework\Attributes\Test]
    public function getStateReturnsNewValueFromSetter(): void
    {
        $off = $this->getInaccessibleConstant($this->unit, 'STATE_OFF');
        $this->callInaccessibleMethod($this->unit, 'setState', $off)
        $this->assertSame($off, $this->unit->getState());
    }

    #[\PHPUnit\Framework\Attributes\Test]
    public function getStateReturnsNewValueFromPropertyAllocation(): void
    {
        $this->assertSame(
            'unknown',
            $this->setInaccessibleProperty($this->unit, 'state', 'unknown')->getState()
        );
    }
}
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance58

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

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 ~226 days

Total

3

Last Release

265d 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 (4 commits)")

---

Tags

phpphpunittesting-toolsaccessible

### Embed Badge

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

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

###  Alternatives

[nunomaduro/mock-final-classes

Allows mocking of final methods and classes in PHP.

113854.3k23](/packages/nunomaduro-mock-final-classes)[hot/phpunit-runner

The lib allows to watch phpunit tests

3066.9k4](/packages/hot-phpunit-runner)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)[phrozenbyte/phpunit-array-asserts

Provides various array-related PHPUnit assertions, primarily used for API testing.

1055.0k1](/packages/phrozenbyte-phpunit-array-asserts)[cable8mm/water-melon

Water Melon is simple melon.com api sdk for php

182.7k](/packages/cable8mm-water-melon)

PHPackages © 2026

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