search hotlink icon profile hotlink icon
Re Public | 1.1.x - 1.x.x

On This Page

Note

This example is based on the Basic Example Config and assumes that you have created the config and the CLI file using the suggested names.

Fusion automatically indexes all auto-loadable code when case-insensitive package identifier segments either match or form a prefix of the namespace segments. Since Reflex is a dependency of your buildable package, such a package identifier already exists. Replace the placeholder <Your\Package\ID\Segments> used in the example files with your actual package identifier.

Production Code File

Create the file Counter.php in the configured src directory with the following content:

                namespace <Your\Package\ID\Segments>;

class Counter
{
    public function __construct(private int $number) {}

    public function add(int $number): void
    {
        $this->number += $number;
    }

    public function get(): int
    {
        return $this->number;
    }
}
            

The project structure changes afterward:

  • src: Configured dir where the runner finds your code for coverage
    • Counter.php: Production code to test

Shareable Test File

Create the file CounterTest.php in the configured tests/Units directory with the following content:

                namespace <Your\Package\ID\Segments>\Tests\Units;

use <Your\Package\ID\Segments>\Counter;
use Valvoid\Reflex\Test\Wrapper;

class CounterTest extends Wrapper
{
    public function testCounter(): void
    {
        $counter = new Counter(1);
        $counter->add(2);

        $this->validate($counter->get())
            ->as(3);
    }
}
            

The project structure changes afterward:

  • tests/Units: Configured directory where the runner finds your tests
    • CounterTest.php: Custom unit test

Common State Prefixes

For autoloading, Reflex uses the generated prefixes.php file located in its own stateful files directory:

                    '<Your\Package\ID\Segments>\Tests' => '/tests',
'<Your\Package\ID\Segments>' => '/src'
                

If your configured src or tests directories were empty until now, you must generate the missing prefixes once from these example files by running the lightweight register command:

                    fusion register
                

Default Test Runner

After creating the production and test files shown above, run the default test runner again:

                        php reflex units
                    

This time, Reflex discovers the custom test file and executes its test method. If your code directory already contained other files, the reported code coverage may be below 100%, since only this single test is executed.

Note

Tests should be written to verify behavior, not to optimize coverage percentages.