yireo/shopware6-integration-test-helper
最新稳定版本:1.0.0
Composer 安装命令:
composer require yireo/shopware6-integration-test-helper
包简介
Utilities to help you test your Shopware plugins
README 文档
README
Shopware 6 plugin and library to help you build PHPUnit-based integration tests easier
Features
- Custom PHPUnit bootstrap
- Support for various environment variables
- Various PHP traits
assertBundleIsInstalled(string $bundleName)assertServiceExists(string $serviceId)assertEntityExtensionExists(string $entityExtensionClass)
- PHP class
\Yireo\IntegrationTestHelper\Test\Integration\AbstractTestCase- Includes all PHP traits already
Installation
Install this plugin and activate it:
composer require yireo/shopware6-integration-test-helper --dev bin/console plugin:refresh bin/console plugin:install --activate YireoIntegrationTestHelper
PHPUnit configuration
Next, configure your PHPUnit file to use the file vendor/yireo/shopware6-integration-test-helper/src/test_bootstrap.php as a bootstrap. Also configure the DATABASE_URL (pointing to a different database than your regular Shopware database).
An example PHPUnit file is here:
<?xml version="1.0" encoding="UTF-8"?> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="vendor/yireo/shopware6-integration-test-helper/src/test_bootstrap.php" colors="true" cacheResult="false"> <php> <ini name="error_reporting" value="E_ALL"/> <server name="KERNEL_CLASS" value="Shopware\Core\Kernel"/> <env name="FORCE_INSTALL" value="1"/> <env name="FORCE_INSTALL_PLUGINS" value="1"/> <env name="FORCE_INSTALL_ADDITIONAL_PLUGINS" value="YireoExample"/> <env name="APP_ENV" value="test"/> <env name="APP_DEBUG" value="1"/> <env name="APP_SECRET" value="s$cretf0rt3st"/> <env name="SHELL_VERBOSITY" value="-1"/> <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" /> <env name="LOCK_DSN" value="flock" /> <env name="DATABASE_URL" value="mysql://root:root@mysql:3306/shopware6_test" /> </php> </phpunit>
Instead of using the PHPUnit file for this, you could also add the environment variables to a file .env.test instead.
- When
FORCE_INSTALLis1, Shopware will do a reinstallation; - When
FORCE_INSTALL_PLUGINSis1, plugins will be refreshed, installed and activated; - When
FORCE_INSTALL_ADDITIONAL_PLUGINScontains a comma-separate list of plugins, each plugin will be installed and activated. Make sure to include at least your own plugin (in this exampleYireoExample);
Usage of PHP parent class
namespace Swag\Example\Test\Integration; use Yireo\IntegrationTestHelper\Test\Integration\AbstractTestCase; class BasicPluginTest extends AbstractTestCase { public function testIfBundleIsRegistered() { $this->assertBundleIsInstalled(); } }
Usage of PHP traits
namespace Swag\Example\Test\Integration; use PHPUnit\Framework\TestCase; use Shopware\Core\Framework\Test\TestCaseBase\IntegrationTestBehaviour; use Yireo\IntegrationTestHelper\Traits\AssertBundleIsInstalled; class BasicPluginTest extends TestCase { use IntegrationTestBehaviour; use AssertBundleIsInstalled; public function getName(): string { return self::class; // Shopware 6.5 requires you to implement this method } public function testIfBundleIsRegistered() { $this->assertBundleIsInstalled(); } }
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-19