Skip to content

Add test infrastructure + unit test for ProcessVariablePlaceholderResolver #10

Description

@schmunk42

Context

ProcessVariablePlaceholderResolver (added in #9, released in 0.5.0) resolves {{ name }} process-variable placeholders in form schemas server-side. It shipped without a test because the bundle has no test infrastructure yet — no autoload-dev, no tests/ directory, no phpunit.dist.xml, no CI workflow (phpunit/phpunit is only present in require-dev).

Setting up test infra for a shared bundle is a separate decision from the feature, so it is tracked here rather than done inline.

Tasks

  • Add autoload-dev PSR-4 mapping Dmstr\\Flowable\\Tests\\tests/ to composer.json.
  • Add a phpunit.dist.xml (PHPUnit ^12, already in require-dev).
  • Add a GitHub Actions workflow running vendor/bin/phpunit (mirror dmstr/openapi-json-schema-bundle's CLI-only Docker Compose / .github/workflows/tests.yml).
  • Add the drop-in unit test below.

Drop-in test

tests/Schema/ProcessVariablePlaceholderResolverTest.php

<?php

declare(strict_types=1);

namespace Dmstr\Flowable\Tests\Schema;

use Dmstr\Flowable\Schema\ProcessVariablePlaceholderResolver;
use PHPUnit\Framework\TestCase;

final class ProcessVariablePlaceholderResolverTest extends TestCase
{
    public function testSubstitutesBareIdentifierTokens(): void
    {
        $schema = ['properties' => ['user' => ['x-collection' => '/api/user?rolle=aussendienst_{{ kreisnummer }}']]];
        $out = ProcessVariablePlaceholderResolver::resolve($schema, ['kreisnummer' => 115]);

        self::assertSame('/api/user?rolle=aussendienst_115', $out['properties']['user']['x-collection']);
    }

    public function testLeavesDottedJedisonTokensUntouched(): void
    {
        $schema = ['x-template' => 'fogu-{{ jahr.value }}-{{ revierId.value }}'];
        $out = ProcessVariablePlaceholderResolver::resolve($schema, ['jahr' => 2026]);

        self::assertSame('fogu-{{ jahr.value }}-{{ revierId.value }}', $out['x-template']);
    }

    public function testLeavesUnknownIdentifiersUntouched(): void
    {
        $out = ProcessVariablePlaceholderResolver::resolve(['a' => '{{ missing }}'], ['other' => 'x']);

        self::assertSame('{{ missing }}', $out['a']);
    }

    public function testStringifiesBooleanAndDropsNonScalar(): void
    {
        $out = ProcessVariablePlaceholderResolver::resolve(
            ['flag' => '{{ on }}', 'arr' => 'x={{ list }}'],
            ['on' => true, 'list' => [1, 2]],
        );

        self::assertSame('true', $out['flag']);
        self::assertSame('x=', $out['arr']);
    }

    public function testEmptyVariableMapReturnsSchemaUnchanged(): void
    {
        $schema = ['a' => '{{ x }}'];
        self::assertSame($schema, ProcessVariablePlaceholderResolver::resolve($schema, []));
    }

    public function testWalksNestedArraysAndPreservesNonStrings(): void
    {
        $schema = ['deep' => ['n' => 5, 'url' => 'r_{{ k }}', 'flag' => true]];
        $out = ProcessVariablePlaceholderResolver::resolve($schema, ['k' => 'v']);

        self::assertSame(['deep' => ['n' => 5, 'url' => 'r_v', 'flag' => true]], $out);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions