Skip to content

LaravelTestGenerator ​

Class: Unusualify\Modularous\Generators\LaravelTestGenerator
Source: src/Generators/LaravelTestGenerator.php
Extends: Generator

Scaffolds a PHPUnit test file (Unit or Feature) for Modularous backend code. Mirrors the structure of VueTestGenerator but targets the package's PHP test directory.

Test Types ​

Type keyImport dirTarget dirNamingStub
unitUnit/UnitPascalCasetests/laravel-unit
featureFeature/FeaturePascalCasetests/laravel-feature

Target Path ​

All PHP test files are written to the package's src/Tests directory:

get_modularous_vendor_path('src/Tests')/{target_dir}/{kebab-name}.php

Properties ​

PropertyTypeDescription
$typestringActive test type key (unit or feature)
$subImportDirstring|nullOptional subdirectory appended to the import path
$subTargetDirstring|nullOptional subdirectory appended to the target path

Key Methods ​

setType(string $type) ​

Sets the active type. Must be 'unit' or 'feature'.

getTypeTargetDir(): string ​

Returns 'Unit' or 'Feature' based on the active type.

getTestFileName(): string ​

Returns {kebab-name}.php.

generate(): int ​

Renders the type-specific stub with four replacements and writes the file:

ReplacementValue
$STUDLY_NAME$StudlyCase name
$CAMEL_CASE$camelCase name
$NAMESPACE$test/{target_dir}/{test-file-name}
$IMPORT$Import path with .php extension

Files are never overwritten if they already exist.

Usage ​

php
$generator = new LaravelTestGenerator('PostRepository', $config, $filesystem, $console, $module);
$generator
    ->setType('unit')
    ->generate();
// → Creates: src/Tests/Unit/post-repository.php