Skip to content

netresearch/typo3-testing-skill / skills/typo3-testing

typo3-testing

Flagged

Use when reproducing defects as failing tests, testing template or rendered output changes, confirming changes on a running TYPO3 instance, or setting up TYPO3 extension tests: unit/functional/E2E, PHPUnit 11-13, mutation testing, final-class mocks (v14), CI matrix across TYPO3 12/13/14.3 LTS, typo3-ci-workflows meta-package, CI failures. Also: transaction rollback, worker crashes, competing requests, testing-framework setup, test matrix, integration/e2e testing, coverage, test generation.

FileKindSize
SKILL.mdskill md6.8 KB
assets/.php-cs-fixer.dist.phpscript7.0 KB
assets/AGENTS.mdmarkdown5.0 KB
assets/Build/Scripts/runTests.shexecutablescript27.5 KB
assets/Build/playwright/.nvmrcother6 B
assets/Build/playwright/package.jsonmanifest535 B
assets/Build/playwright/playwright.config.tsscript1.3 KB
assets/Build/playwright/tests/playwright/accessibility/modules.spec.tsscript2.0 KB
assets/Build/playwright/tests/playwright/config.tsscript712 B
assets/Build/playwright/tests/playwright/e2e/backend-module.spec.tsscript1.9 KB
assets/Build/playwright/tests/playwright/fixtures/setup-fixtures.tsscript2.7 KB
assets/Build/playwright/tests/playwright/helper/login.setup.tsscript975 B
assets/FunctionalTests.xmlconfig1.4 KB
assets/FunctionalTestsBootstrap.phpscript1.6 KB
assets/Makefileother2.3 KB
assets/UnitTests.xmlconfig890 B
assets/UnitTestsBootstrap.phpscript2.1 KB
assets/bootstrap.phpscript1.4 KB
assets/codecov.ymlconfig1.6 KB
assets/docker/codeception.ymlconfig979 B
assets/docker/docker-compose.ymlconfig1.4 KB
assets/example-tests/ExampleAcceptanceCest.phpscript2.2 KB
assets/example-tests/ExampleFunctionalTest.phpscript2.4 KB
assets/example-tests/ExampleUnitTest.phpscript1.6 KB
assets/fixtures/README.mdmarkdown2.0 KB
assets/fixtures/be_users.csvother361 B
assets/fixtures/pages.csvother257 B
assets/fixtures/sys_category.csvother228 B
assets/fixtures/tt_content.csvother338 B
assets/github-actions-e2e.ymlconfig8.8 KB
assets/github-actions-tests.ymlconfig6.3 KB
assets/infection.json5other2.8 KB
assets/phpat.neonother330 B
assets/phpat.phpscript8.4 KB
assets/phpstan-baseline.neonother365 B
assets/phpstan.neonother1.4 KB
assets/rector.phpscript2.9 KB
checkpoints.yamlconfig61.7 KB
references/accessibility-testing.mdmarkdown7.6 KB
references/architecture-testing.mdmarkdown4.4 KB
references/asset-templates-guide.mdmarkdown3.4 KB
references/backend-module-render-verification.mdmarkdown9.7 KB
references/backend-user-access-testing.mdmarkdown9.5 KB
references/captainhook-setup.mdmarkdown2.4 KB
references/ci-cd.mdmarkdown39.5 KB
references/ci-debugging.mdmarkdown20.0 KB
references/ci-workflows-meta-package.mdmarkdown11.6 KB
references/crash-and-concurrency-testing.mdmarkdown4.8 KB
references/crypto-testing.mdmarkdown16.6 KB
references/datahandler-silent-rewrites.mdmarkdown7.2 KB
references/ddev-testing.mdmarkdown1.3 KB
references/e2e-testing.mdmarkdown53.0 KB
references/enforcement-rules.mdmarkdown5.7 KB
references/event-dispatch-testing.mdmarkdown2.8 KB
references/framework-compat-gate.mdmarkdown4.9 KB
references/functional-test-patterns.mdmarkdown11.0 KB
references/functional-testing.mdmarkdown46.3 KB
references/fuzz-testing.mdmarkdown8.6 KB
references/integration-testing.mdmarkdown14.1 KB
references/javascript-testing.mdmarkdown29.3 KB
references/live-instance-verification.mdmarkdown8.6 KB
references/mock-validity.mdmarkdown15.7 KB
references/mutation-testing.mdmarkdown36.0 KB
references/performance-testing.mdmarkdown11.2 KB
references/quality-tools.mdmarkdown25.5 KB
references/release-workflow-validation.mdmarkdown3.6 KB
references/sonarcloud.mdmarkdown18.8 KB
references/synthetic-secret-fixtures.mdmarkdown3.8 KB
references/tdd-discipline.mdmarkdown9.1 KB
references/test-environment-guards.mdmarkdown18.5 KB
references/test-runners.mdmarkdown24.6 KB
references/typo3-ci-config-patterns.mdmarkdown9.0 KB
references/typo3-v14-final-classes.mdmarkdown16.5 KB
references/unit-testing.mdmarkdown59.1 KB
scripts/generate-test.shexecutablescript6.0 KB
scripts/setup-testing.shexecutablescript6.3 KB
scripts/validate-setup.shexecutablescript4.0 KB

scripts/generate-test.sh

View on GitHub
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Netresearch DTT GmbH

#
# Generate TYPO3 test class
#
# Usage: ./generate-test.sh <type> <ClassName>
# Example: ./generate-test.sh unit EmailValidator
#

set -e

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

# Parse arguments
TEST_TYPE="$1"
CLASS_NAME="$2"

if [ -z "${TEST_TYPE}" ] || [ -z "${CLASS_NAME}" ]; then
    echo "Usage: $0 <type> <ClassName>"
    echo
    echo "Types:"
    echo "  unit         - Unit test (fast, no database)"
    echo "  functional   - Functional test (with database)"
    echo "  acceptance   - Acceptance test (browser-based)"
    echo
    echo "Example:"
    echo "  $0 unit EmailValidator"
    echo "  $0 functional ProductRepository"
    echo "  $0 acceptance Login"
    exit 1
fi

# Validate test type
case ${TEST_TYPE} in
    unit|functional|acceptance)
        ;;
    *)
        echo -e "${RED}Error: Invalid test type '${TEST_TYPE}'${NC}"
        echo "Valid types: unit, functional, acceptance"
        exit 1
        ;;
esac

# The class name becomes a file name and a PHP identifier. A path such as
# Domain/Model/Foo produced a file that does not parse, and ../Foo wrote
# the file outside Tests/.
if [[ ! "${CLASS_NAME}" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]]; then
    echo -e "${RED}Error: Invalid class name '${CLASS_NAME}'${NC}"
    echo "Use the short class name without namespace or path, for example EmailValidator"
    exit 1
fi

# Determine paths
PROJECT_DIR="$(pwd)"

# Check if Tests directory exists
if [ ! -d "${PROJECT_DIR}/Tests" ]; then
    echo -e "${RED}Error: Tests directory not found${NC}"
    echo "Run setup-testing.sh first"
    exit 1
fi

# Set target directory based on test type
case ${TEST_TYPE} in
    unit)
        TEST_DIR="${PROJECT_DIR}/Tests/Unit"
        TEST_SUFFIX="Test"
        ;;
    functional)
        TEST_DIR="${PROJECT_DIR}/Tests/Functional"
        TEST_SUFFIX="Test"
        ;;
    acceptance)
        TEST_DIR="${PROJECT_DIR}/Tests/Acceptance"
        TEST_SUFFIX="Cest"
        ;;
esac

# Extract namespace from composer.json
# shellcheck disable=SC2016  # PHP code: the $ variables belong to php -r, not to the shell
NAMESPACE=$(php -r '
    $composer = json_decode(file_get_contents("composer.json"), true);
    foreach ($composer["autoload"]["psr-4"] ?? [] as $ns => $path) {
        if (strpos($path, "Classes") !== false) {
            echo rtrim($ns, "\\");
            break;
        }
    }
')

if [ -z "${NAMESPACE}" ]; then
    echo -e "${RED}Error: Could not determine namespace from composer.json${NC}"
    exit 1
fi

# Determine test file path
TEST_FILE="${TEST_DIR}/${CLASS_NAME}${TEST_SUFFIX}.php"

# Check if file already exists
if [ -f "${TEST_FILE}" ]; then
    echo -e "${RED}Error: Test file already exists: ${TEST_FILE}${NC}"
    exit 1
fi

# Create test file directory if needed
mkdir -p "$(dirname "${TEST_FILE}")"

echo -e "${GREEN}Generating ${TEST_TYPE} test for ${CLASS_NAME}...${NC}"

# The generated test imports the subject class and PHPUnit's Test attribute.
# PHP class names are case-insensitive, so a subject named Test would clash
# with the attribute import; alias the attribute in that case.
TEST_ATTRIBUTE="Test"
TEST_ATTRIBUTE_IMPORT="PHPUnit\\Framework\\Attributes\\Test"
if [ "$(printf '%s' "${CLASS_NAME}" | tr '[:upper:]' '[:lower:]')" = "test" ]; then
    TEST_ATTRIBUTE="TestAttribute"
    TEST_ATTRIBUTE_IMPORT="PHPUnit\\Framework\\Attributes\\Test as TestAttribute"
fi

# Generate test class based on type
case ${TEST_TYPE} in
    unit)
        cat > "${TEST_FILE}" << EOF
<?php

declare(strict_types=1);

namespace ${NAMESPACE}\\Tests\\Unit;

use ${TEST_ATTRIBUTE_IMPORT};
use TYPO3\\TestingFramework\\Core\\Unit\\UnitTestCase;
use ${NAMESPACE}\\${CLASS_NAME};

/**
 * Unit test for ${CLASS_NAME}
 */
final class ${CLASS_NAME}${TEST_SUFFIX} extends UnitTestCase
{
    protected ${CLASS_NAME} \$subject;

    protected function setUp(): void
    {
        parent::setUp();
        \$this->subject = new ${CLASS_NAME}();
    }

    #[${TEST_ATTRIBUTE}]
    public function canBeInstantiated(): void
    {
        self::assertInstanceOf(${CLASS_NAME}::class, \$this->subject);
    }
}
EOF
        ;;

    functional)
        cat > "${TEST_FILE}" << EOF
<?php

declare(strict_types=1);

namespace ${NAMESPACE}\\Tests\\Functional;

use ${TEST_ATTRIBUTE_IMPORT};
use TYPO3\\TestingFramework\\Core\\Functional\\FunctionalTestCase;
use ${NAMESPACE}\\${CLASS_NAME};

/**
 * Functional test for ${CLASS_NAME}
 */
final class ${CLASS_NAME}${TEST_SUFFIX} extends FunctionalTestCase
{
    protected ${CLASS_NAME} \$subject;

    protected array \$testExtensionsToLoad = [
        'typo3conf/ext/your_extension',
    ];

    protected function setUp(): void
    {
        parent::setUp();
        \$this->subject = \$this->get(${CLASS_NAME}::class);
    }

    #[${TEST_ATTRIBUTE}]
    public function canBeInstantiated(): void
    {
        self::assertInstanceOf(${CLASS_NAME}::class, \$this->subject);
    }
}
EOF

        # Create fixture file
        FIXTURE_FILE="${PROJECT_DIR}/Tests/Functional/Fixtures/${CLASS_NAME}.csv"
        if [ ! -f "${FIXTURE_FILE}" ]; then
            mkdir -p "$(dirname "${FIXTURE_FILE}")"
            echo "# Fixture for ${CLASS_NAME}${TEST_SUFFIX}" > "${FIXTURE_FILE}"
            echo -e "${GREEN}✓ Created fixture: ${FIXTURE_FILE}${NC}"
        fi
        ;;

    acceptance)
        cat > "${TEST_FILE}" << EOF
<?php

declare(strict_types=1);

namespace ${NAMESPACE}\\Tests\\Acceptance;

use ${NAMESPACE}\\Tests\\Acceptance\\AcceptanceTester;

/**
 * Acceptance test for ${CLASS_NAME/Cest/} workflow
 */
final class ${CLASS_NAME}${TEST_SUFFIX}
{
    public function _before(AcceptanceTester \$I): void
    {
        // Setup before each test
    }

    public function exampleTest(AcceptanceTester \$I): void
    {
        \$I->amOnPage('/');
        \$I->see('Welcome');
    }
}
EOF
        ;;
esac

echo -e "${GREEN}✓ Created: ${TEST_FILE}${NC}"
echo
echo "Run test:"
echo "  vendor/bin/phpunit ${TEST_FILE}"
echo
echo "Or via composer:"
echo "  composer ci:test:php:${TEST_TYPE}"
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall