Search by

yireo / magento2-test-generator

yireo

N/A

Package info

github.com/yireo/Yireo_TestGenerator

Type:magento2-module

pkg:composer/yireo/magento2-test-generator

Fund package maintenance!

yireo

www.paypal.me/yireo

Statistics

Installs: 550

Dependents: 0

Suggesters: 0

Stars: 7

Open Issues: 0

0.0.6 2026-11-26 01:39 UTC

This package is auto-updated.

Last update: 2026-11-30 09:41:44 UTC


README

Magento version PHP version License Latest Version

Use this module to kickstart unit tests or integration tests for your existing module.

Installation

composer require --dev yireo/magento2-test-generator
bin/magento module:enable Yireo_TestGenerator

This module writes PHP files into module folders. Only install it as a development dependency and do not deploy it to production. In production mode, the command refuses to run unless you add the --force flag.

Usage

Generate integration tests for the module Yireo_Example if they don't exist yet:

bin/magento yireo:test:generate Yireo_Example

Or generate integration tests, overriding existing tests as well (DANGEROUS) unless there is a token @test-generator-skip-override found in the test file contents:

bin/magento yireo:test:generate Yireo_Example --override-existing

Or generate unit tests:

bin/magento yireo:test:generate Yireo_Example --type=unit

Generate unit tests, overriding the original test, for a specific class only:

bin/magento yireo:test:generate --override-existing --type unit -- 'LokiCheckout_AccountType' '\Loki\CheckoutAccountType\Config\Source\AccountTypeOptions'

AI generated tests

This module also offers to generate unit tests or integration tests by using AI. The tests generated might not always be perfect and might not even work. To the least, they offer you a kickstart instead of needing to code things yourself.

The following coding AIs are currently supported:

  • OpenAI (ChatGPT)
  • Anthropic (Claude AI)

Both require an API key to be used. Note that these AI platforms will bill you according to your usage.

In the Store Configuration under Yireo > Test Generator you can enable each AI and configure an API key. The API keys are stored encrypted.

AI generators are only used when you add the --ai flag. This sends the full source code of each class to the AI provider, so make sure that this is allowed for the code you are working on:

bin/magento yireo:test:generate Yireo_Example --type=unit --ai

AI responses are only written to disk when they contain valid PHP code that defines the expected test class.

Extending test types

The Integration Tests can be created by using a custom generator. For instance, there is a ConfigTestGenerator which allows for a specific config test case to be created, as long as the PHP class name matches with *\Config\Config.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Yireo\TestGenerator\Generator\IntegrationTest\AdditionalTestGeneratorListing">
        <arguments>
            <argument name="testGenerators" xsi:type="array">
                <item name="custom" xsi:type="object">YireoTraining\ExampleTestGenerator\Generator\IntegrationTest\CustomTestGenerator</item>
            </argument>
        </arguments>
    </type>
</config>

This generator class needs to implement \Yireo\TestGenerator\Generator\IntegrationTest\SourceTestGeneratorInterface. See the \Yireo\TestGenerator\Generator\IntegrationTest\ConfigTestGenerator for a full example.

Todo

  • Move the AI mechanisms in separate modules
  • Allow to configure the AI prompt yourself
  • Add a dry-run flag

Current status

Static Tests Unit Tests Integration Tests Playwright DI Compilation