php-forge/support

Support utilities for enhanced testing capabilities.

Package info

github.com/php-forge/support

pkg:composer/php-forge/support

Statistics

Installs: 81โ€‰904

Dependents: 40

Suggesters: 0

Stars: 1

Open Issues: 6

0.3.2 2026-02-03 23:57 UTC

Requires

  • php: ^8.1

Suggests

None

Provides

None

Conflicts

None

Replaces

None

BSD-3-Clause 21a68279578e3e6c4847bd38f6bb6619a7edd8b1

phptestingtestssupportphp-forge


README

๐Ÿ‘ PHP Forge

Support


๐Ÿ‘ PHPUnit
๐Ÿ‘ Mutation Testing
๐Ÿ‘ PHPStan

Support utilities for PHPUnit-focused development
Reflection helpers, line ending normalization, and filesystem cleanup for deterministic tests.

Features

๐Ÿ‘ Feature Overview

Installation

composer require php-forge/support:^0.2 --dev

Quick start

This package provides helper classes for PHPUnit tests.

It supports reflection-based access to non-public members, deterministic string comparisons across platforms, and filesystem cleanup for isolated test environments.

Accessing private properties

<?php

declare(strict_types=1);

use PHPForge\Support\ReflectionHelper;
use PHPUnit\Framework\TestCase;

final class AccessPrivatePropertyTest extends TestCase
{

 public function testInaccessibleProperty(): void
 {
 $object = new class () {
 private string $secretValue = 'hidden';
 };

 $value = ReflectionHelper::inaccessibleProperty($object, 'secretValue');

 self::assertSame('hidden', $value);
 }
}

Invoking protected methods

<?php

declare(strict_types=1);

use PHPForge\Support\ReflectionHelper;
use PHPUnit\Framework\TestCase;

final class InvokeProtectedMethodTest extends TestCase
{

 public function testInvokeMethod(): void
 {
 $object = new class () {
 protected function calculate(int $a, int $b): int
 {
 return $a + $b;
 }
 };

 $result = ReflectionHelper::invokeMethod($object, 'calculate', [5, 3]);

 self::assertSame(8, $result);
 }
}

Normalize line endings

<?php

declare(strict_types=1);

use PHPForge\Support\LineEndingNormalizer;
use PHPUnit\Framework\TestCase;

final class NormalizeLineEndingsTest extends TestCase
{

 public function testNormalizedComparison(): void
 {
 self::assertSame(
 LineEndingNormalizer::normalize("Foo\r\nBar"),
 LineEndingNormalizer::normalize("Foo\nBar"),
 );
 }
}

Remove files from directory

<?php

declare(strict_types=1);

use PHPForge\Support\DirectoryCleaner;
use PHPUnit\Framework\TestCase;

final class RemoveFilesFromDirectoryTest extends TestCase
{

 public function testCleanup(): void
 {
 $testDir = sys_get_temp_dir() . '/php-forge-support-' . bin2hex(random_bytes(8));
 mkdir($testDir);

 try {
 file_put_contents($testDir . '/artifact.txt', 'test');
 file_put_contents($testDir . '/.gitignore', "*\n");

 DirectoryCleaner::clean($testDir);

 self::assertFileDoesNotExist($testDir . '/artifact.txt');
 self::assertFileExists($testDir . '/.gitignore');
 } finally {
 @unlink($testDir . '/.gitignore');
 @rmdir($testDir);
 }
 }
}

Set inaccessible property

<?php

declare(strict_types=1);

use PHPForge\Support\ReflectionHelper;
use PHPUnit\Framework\TestCase;

final class SetInaccessiblePropertyTest extends TestCase
{

 public function testSetProperty(): void
 {
 $object = new class () {
 private string $config = 'default';
 };

 ReflectionHelper::setInaccessibleProperty($object, 'config', 'test-mode');

 $newValue = ReflectionHelper::inaccessibleProperty($object, 'config');

 self::assertSame('test-mode', $newValue);
 }
}

Enum data provider

Use PHPForge\Support\EnumDataProvider to build deterministic datasets from UnitEnum::cases() and normalized enum values.

Attribute fragment output (HTML)
<?php

declare(strict_types=1);

namespace App\Tests;

use PHPForge\Support\EnumDataProvider;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use UnitEnum;

enum Size
{
 case Small;
 case Large;
}

final class EnumDataProviderHtmlTest extends TestCase
{
 public static function provideEnumAttributes(): array
 {
 return EnumDataProvider::attributeCases(Size::class, 'data-size', true);
 }

 #[DataProvider('provideEnumAttributes')]
 public function testBuildsAttributeFragment(UnitEnum $case, array $args, string $expected, string $message): void
 {
 $normalized = $case->name;
 $attributeFragment = " data-size=\"{$normalized}\"";

 self::assertSame($expected, $attributeFragment, $message);
 }
}
Enum instance output (non-HTML)
<?php

declare(strict_types=1);

namespace App\Tests;

use PHPForge\Support\EnumDataProvider;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use UnitEnum;

enum State
{
 case Active;
 case Disabled;
}

final class EnumDataProviderEnumTest extends TestCase
{
 public static function provideEnumInstances(): array
 {
 return EnumDataProvider::attributeCases(State::class, 'state', false);
 }

 #[DataProvider('provideEnumInstances')]
 public function testReturnsEnumInstance(UnitEnum $case, array $args, UnitEnum $expected, string $message): void
 {
 self::assertSame($case, $expected, $message);
 }
}
Tag cases
<?php

declare(strict_types=1);

namespace App\Tests;

use PHPForge\Support\EnumDataProvider;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

enum Heading
{
 case H1;
 case H2;
}

final class EnumDataProviderTagCasesTest extends TestCase
{
 public static function provideTags(): array
 {
 return EnumDataProvider::tagCases(Heading::class, 'heading');
 }

 #[DataProvider('provideTags')]
 public function testProvidesNormalizedTag(Heading $case, string $normalized): void
 {
 self::assertSame($case->name, $normalized);
 }
}

Documentation

For detailed configuration options and advanced usage.

Package information

๐Ÿ‘ PHP
๐Ÿ‘ Latest Stable Version
๐Ÿ‘ Total Downloads

Quality code

๐Ÿ‘ Codecov
๐Ÿ‘ PHPStan Level Max
๐Ÿ‘ Super-Linter
๐Ÿ‘ StyleCI

Our social networks

๐Ÿ‘ Follow on X

License

๐Ÿ‘ License