{"id":22920714,"url":"https://github.com/teamneusta/pimcore-testing-framework","last_synced_at":"2025-06-11T15:03:45.713Z","repository":{"id":173954495,"uuid":"644842780","full_name":"teamneusta/pimcore-testing-framework","owner":"teamneusta","description":"Tools for Pimcore unit/integration testing with PHPUnit.","archived":false,"fork":false,"pushed_at":"2025-04-09T13:13:31.000Z","size":125,"stargazers_count":6,"open_issues_count":3,"forks_count":0,"subscribers_count":11,"default_branch":"v0.12","last_synced_at":"2025-06-10T06:05:17.972Z","etag":null,"topics":["pimcore","testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teamneusta.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-24T11:23:19.000Z","updated_at":"2025-04-09T13:13:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"d5854794-db46-4fe2-8d5a-ea5756fa1fc8","html_url":"https://github.com/teamneusta/pimcore-testing-framework","commit_stats":null,"previous_names":["teamneusta/pimcore-testing-framework"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/teamneusta/pimcore-testing-framework","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamneusta%2Fpimcore-testing-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamneusta%2Fpimcore-testing-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamneusta%2Fpimcore-testing-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamneusta%2Fpimcore-testing-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teamneusta","download_url":"https://codeload.github.com/teamneusta/pimcore-testing-framework/tar.gz/refs/heads/v0.12","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamneusta%2Fpimcore-testing-framework/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259286900,"owners_count":22834831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pimcore","testing"],"created_at":"2024-12-14T07:16:45.524Z","updated_at":"2025-06-11T15:03:45.673Z","avatar_url":"https://github.com/teamneusta.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pimcore Testing Framework\n\nProvides tools for Pimcore unit/integration testing with PHPUnit.\n\n## Installation\n\n1.  **Require the bundle**\n\n    ```shell\n    composer require --dev teamneusta/pimcore-testing-framework\n    ```\n\n## Usage\n\n### Bootstrapping Pimcore\n\nWe provide a convenience method to bootstrap Pimcore for running tests.\nJust call `BootstrapPimcore::bootstrap()` in your `tests/bootstrap.php` as seen below, and you're done.\n\n```php\n# tests/bootstrap.php\n\u003c?php\n\ninclude dirname(__DIR__).'/vendor/autoload.php';\n\nNeusta\\Pimcore\\TestingFramework\\Pimcore\\BootstrapPimcore::bootstrap();\n```\n\nYou can also pass any environment variable via named arguments to this method:\n\n```php\n# tests/bootstrap.php\nNeusta\\Pimcore\\TestingFramework\\Pimcore\\BootstrapPimcore::bootstrap(\n    APP_ENV: 'custom',\n    SOMETHING: 'else',\n);\n```\n\n#### Integration Tests For a Bundle\n\nIf you want to add integration tests for a Bundle, you need to set up an application with a kernel.\nPimcore also expects some configuration\n(e.g., for the [`security`](https://github.com/pimcore/skeleton/blob/10.2/config/packages/security.yaml)) to be present.\n\nYou can use the `\\Neusta\\Pimcore\\TestingFramework\\Kernel\\TestKernel` as a base,\nwhich already provides all necessary configurations with default values\n(see: `dist/config` and `dist/pimcore10/config` or `dist/pimcore11/config`, depending on your Pimcore version).\n\nFor a basic setup, you can use the `TestKernel` directly:\n\n```php\n# tests/bootstrap.php\n\u003c?php\n\nuse Neusta\\Pimcore\\TestingFramework\\Kernel\\TestKernel;\nuse Neusta\\Pimcore\\TestingFramework\\Pimcore\\BootstrapPimcore;\n\ninclude dirname(__DIR__).'/vendor/autoload.php';\n\nBootstrapPimcore::bootstrap(\n    PIMCORE_PROJECT_ROOT: __DIR__.'/app',\n    KERNEL_CLASS: TestKernel::class,\n);\n```\n\n\u003e [!IMPORTANT]  \n\u003e Don't forget to create the `tests/app` directory!\n\u003e ```shell\n\u003e mkdir -p tests/app\n\u003e echo '/var' \u003e tests/app/.gitignore\n\u003e ```\n\n\u003e [!NOTE]\n\u003e Since the kernels of Pimcore 10 and 11 are not compatible (the signature of the method `configureContainer()` differs),\n\u003e we have extended our `TestKernel` with the ability to load separate configuration files depending on the version.\n\u003e Configuration that is compatible with both Pimcore versions belongs to the `config/` folder of the test app as before.\n\u003e Version specific configuration can be placed inside the `config/pimcore10/`\n\u003e or `config/pimcore11/` folder and will be loaded last.\n\n### Switch Common Behavior on/off in Test Cases\n\nWe provide traits to switch common behavior on/off in whole test case classes.\n\n#### Admin Mode\n\nThe admin mode is disabled by default when calling `BootstrapPimcore::bootstrap()`.\n\nTo enable it again, you can use the `WithAdminMode` trait.\n\n#### Cache\n\n- `WithoutCache`\n\n#### Inherited Values of DataObjects\n\n- `WithInheritedValues`\n- `WithoutInheritedValues`\n\n### Integration Tests With a Configurable Kernel\n\nThe `TestKernel` can be configured dynamically for each test.\nThis is useful if different configurations or dependent bundles are to be tested.\nTo do this, your test class must inherit from `ConfigurableKernelTestCase`:\n\n```php\nuse Neusta\\Pimcore\\TestingFramework\\Kernel\\TestKernel;\nuse Neusta\\Pimcore\\TestingFramework\\Test\\ConfigurableKernelTestCase;\n\nclass SomeTest extends ConfigurableKernelTestCase\n{\n    public function test_bundle_with_different_configuration(): void\n    {\n        // Boot the kernel with a config closure\n        $kernel = self::bootKernel(['config' =\u003e static function (TestKernel $kernel) {\n            // Add some other bundles we depend on\n            $kernel-\u003eaddTestBundle(OtherBundle::class);\n\n            // Add some configuration\n            $kernel-\u003eaddTestConfig(__DIR__.'/config.yaml');\n            \n            // Configure some extension\n            $kernel-\u003eaddTestExtensionConfig('my_bundle', ['some_config' =\u003e true]);\n            \n            // Add some compiler pass\n            $kernel-\u003eaddTestCompilerPass(new MyBundleCompilerPass());\n        }]);\n    }\n}\n```\n\n#### Attributes\n\nAn alternative to passing a `config` closure in the `options` array to `ConfigurableKernelTestCase::bootKernel()` \nis to use attributes for the kernel configuration.\n\n```php\nuse Neusta\\Pimcore\\TestingFramework\\Test\\Attribute\\ConfigureContainer;\nuse Neusta\\Pimcore\\TestingFramework\\Test\\Attribute\\ConfigureExtension;\nuse Neusta\\Pimcore\\TestingFramework\\Test\\Attribute\\RegisterBundle;\nuse Neusta\\Pimcore\\TestingFramework\\Test\\Attribute\\RegisterCompilerPass;\nuse Neusta\\Pimcore\\TestingFramework\\Test\\ConfigurableKernelTestCase;\n\n#[RegisterBundle(SomeBundle::class)]\nclass SomeTest extends ConfigurableKernelTestCase \n{\n    #[ConfigureContainer(__DIR__ . '/Fixtures/some_config.yaml')]\n    #[ConfigureExtension('some_extension', ['config' =\u003e 'values'])]\n    #[RegisterCompilerPass(new SomeCompilerPass())]\n    public function test_something(): void\n    {\n        self::bootKernel();\n\n        // test something\n    }\n}\n```\n\n\u003e [!TIP]\n\u003e All attributes can be used on class *and* test method level.\n\n#### Data Provider\n\nYou can also use the `RegisterBundle`, `ConfigureContainer`, `ConfigureExtension`, or `RegisterCompilerPass` classes \nto configure the kernel in a data provider.\n\n```php\nuse Neusta\\Pimcore\\TestingFramework\\Test\\Attribute\\ConfigureExtension;\nuse Neusta\\Pimcore\\TestingFramework\\Test\\ConfigurableKernelTestCase;\n\nclass SomeTest extends ConfigurableKernelTestCase \n{\n    public function provideTestData(): iterable\n    {\n        yield [\n            'some value', \n            new ConfigureExtension('some_extension', ['config' =\u003e 'some value']),\n        ];\n\n        yield [\n            new ConfigureExtension('some_extension', ['config' =\u003e 'other value']), \n            'other value',\n        ];\n    }\n\n    /** @dataProvider provideTestData */\n    public function test_something(string $expected): void\n    {\n        self::assertSame($expected, self::getContainer()-\u003egetParameter('config'));\n    }\n}\n```\n\n\u003e [!TIP]\n\u003e The kernel configuration objects are *not* passed as arguments to the test method,\n\u003e which means you can use them anywhere between your provided real test data.\n\n#### Custom Attributes\n\nYou can create your own kernel configuration attributes by implementing the `KernelConfiguration` interface:\n\n```php\nuse Neusta\\Pimcore\\TestingFramework\\Kernel\\TestKernel;\nuse Neusta\\Pimcore\\TestingFramework\\Test\\Attribute\\KernelConfiguration;\n\n#[\\Attribute(\\Attribute::TARGET_CLASS | \\Attribute::TARGET_METHOD)]\nclass ConfigureSomeBundle implements KernelConfiguration\n{\n    public function __construct(\n        private readonly array $config,\n    ) {\n    }\n\n    public function configure(TestKernel $kernel): void\n    {\n        $kernel-\u003eaddTestBundle(SomeBundle::class);\n        $kernel-\u003eaddTestExtensionConfig('some', array_merge(\n            ['default' =\u003e 'config'],\n            $this-\u003econfig,\n        ));\n    }\n}\n```\n\nThen you can use the new class as an attribute or inside a data provider.\n\n### Integration Tests With a Database\n\nIf you write integration tests that use the database, we've got you covered too.\n\nWe provide the `ResetDatabase` trait, which does the heavy lifting:\nJust use it in one of your test case classes,\nand it'll install a fresh Pimcore into the configured database before the first test is run.\nIt'll also reset the database between each test, so you don't have to worry about leftovers from previous tests.\n\n#### Using a Dump\n\nIf you already have a database dump that you want to use instead of a fresh Pimcore installation,\nthere's the `DATABASE_DUMP_LOCATION` environment variable.\nPoint it to the location of your dump, and it'll be used instead.\n\n#### Faster Database Reset\n\nBy default, resetting the database between the tests works by dropping the database,\nrecreating it and reinstalling Pimcore (or reimporting the dump).\n\nThis is rather slow, but there are some tricks that can speed it up:\n\n##### Storing the Database in the RAM\n\nNormally, the database is stored on the disk, so that the data is persisted.\nBut we don't really need this for testing, so if you're using Docker, you can configure it to store it in RAM instead:\n\n```yaml\n# compose.yaml\nservices:\n  db:\n    image: 'mariadb:10.10' # or 'mysql:8.0'\n    tmpfs:\n      - /tmp\n      - /var/lib/mysql\n```\n\n##### Wrapping Each Test in a Transaction\n\nWe support the [`dama/doctrine-test-bundle`](https://packagist.org/packages/dama/doctrine-test-bundle),\nwhich isolates database tests by wrapping them into a transaction.\nYou just have to [install the bundle according to its readme](https://github.com/dmaicher/doctrine-test-bundle#how-to-install-and-use-this-bundle),\nand it'll automatically be used.\n\n## Contribution\n\nFeel free to open issues for any bug, feature request, or other ideas.\n\nPlease remember to create an issue before creating large pull requests.\n\n### Local Development\n\nTo develop on local machine, the vendor dependencies are required.\n\n```shell\nbin/composer install\n```\n\nWe use composer scripts for our main quality tools. They can be executed via the `bin/composer` file as well.\n\n```shell\nbin/composer cs:fix\nbin/composer phpstan\n```\n\nFor the tests there is a different script, that includes a database setup.\n\n```shell\nbin/run-tests\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamneusta%2Fpimcore-testing-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteamneusta%2Fpimcore-testing-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamneusta%2Fpimcore-testing-framework/lists"}