php-solution / sf-functional-test
为使用Symfony功能测试提供额外功能
v6.0.0
2024-02-06 09:48 UTC
Requires
- php: >=8.1
- ext-json: *
- doctrine/data-fixtures: >=1.2
- justinrainbow/json-schema: >=5.2
- nelmio/alice: >=3.0
- phpspec/prophecy-phpunit: >=2.0
- phpunit/phpunit: >=10.0
- symfony/browser-kit: >=5.0
- symfony/console: >=5.0
- symfony/framework-bundle: >=5.0
- symfony/property-access: >=5.0
- theofidry/alice-data-fixtures: >=1.0
Requires (Dev)
- doctrine/mongodb-odm: >=2.0
- doctrine/orm: >=2.0
- ramsey/uuid: >=3.9
- symfony/dotenv: >=5.0
- symfony/uid: >=5.0
Suggests
- doctrine/doctrine-bundle: for use Doctrine on test cases
- doctrine/migrations: for use Listener which run Doctrine migrations before test suite
- symfony/dotenv: for use Env Listener which load env vars from paths
- v6.0.0
- v5.0.7
- v5.0.6
- v5.0.5
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.x-dev
- v4.8.2
- v4.8.1
- v4.8.0
- v4.7.3
- v4.7.2
- v4.7.1
- v4.7
- v4.6
- v4.5.2
- v4.5.1
- v4.5.0
- v4.4.5
- v4.4.4
- v4.4.3
- v4.4.2
- v4.4.1
- v4.4
- v4.3.16
- v4.3.15
- v4.3.14
- v4.3.13
- 4.3.12
- 4.3.11
- 4.3.10
- 4.3.9
- 4.3.8
- 4.3.7
- 4.3.6
- v4.3.5
- v4.3.4
- v4.3.3
- v4.3.2
- v4.3.1
- 4.3
- v4.2.9
- v4.2.8
- v4.2.7
- v4.2.6
- v4.2.5
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.1.0
- v4.0.2
- v4.0.1
- v4.0.0
- v1.x-dev
- v1.3
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2
- v1.1
- v1.0
- v0.x-dev
- v0.1.1
- v0.1
- dev-master / 1.x-dev
This package is auto-updated.
Last update: 2024-09-06 11:03:08 UTC
README
安装
$ composer require php-solution/sf-functional-test
从文件中加载环境变量
将扩展添加到您的phpunit.xml中并配置路径(从您的phpunit.xml配置文件中,以逗号分隔的相对文件路径)
<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunEnvLoaderExtension"> <parameter name="paths" value="../.env,.env"/> </bootstrap>
在测试用例之前加载Doctrine数据集
将扩展添加到您的phpunit.xml中
<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunCommandLauncherExtension"> <parameter name="command" value="functional-test:fixtures:load"/> <!--Default is false. If true, if command's exit code > 0 then tests will fail immediately--> <parameter name="exitOnError" value="true" /> </bootstrap>
在测试用例之前运行Doctrine迁移
将扩展添加到您的phpunit.xml中
<bootstrap class="\PhpSolution\FunctionalTest\PhpUnit\Extension\DoctrineMigrationExtension" />
或者简单地
<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunCommandLauncherExtension"> <parameter name="command" value="doctrine:migration:migrate --no-interaction"/> <parameter name="exitOnError" value="true" /> </bootstrap>
使用参数运行sf命令
将扩展添加到您的phpunit.xml中
<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunCommandLauncherExtension"> <parameter name="command" value="doctrine:mongodb:schema:drop --collection"/> </bootstrap>
使用参数运行本地命令
将扩展添加到您的phpunit.xml中
<bootstrap class="PhpSolution\FunctionalTest\PhpUnit\Extension\PreRunNativeCommandLauncherExtension"> <parameter name="command" value="bin/console doctrine:mongodb:schema:drop --collection"/> </bootstrap>
使用测试用例附加功能 PhpSolution\FunctionalTest\TestCase\AppTestCase
使用授权
- 添加到您的config_test.yml
security:
firewalls:
your_secured_category:
http_basic: ~
- 在测试用例中使用
$client = $this->getAuthorizedClient('user_login', 'password');
与Doctrine(ORM、ODM)一起工作
- 将EntityTrait或DocumentTrait添加到您的测试用例中
$this->getDoctrine()
- 查找实体辅助方法
protected function findEntity(string $entityClass, string $orderBy = 'id', array $findBy = [])
protected function findDocument(string $documentClass, array $criteria = [])
protected function findDocuments(string $documentClass, array $criteria = [], array $orderBy = [])
- 刷新实体
protected function refreshEntity($entity)
protected function refreshDocument($document)
测试电子邮件
- 添加配置
swiftmailer: disable_delivery: true spool: type: file path: '%kernel.project_dir%/var/spool' delivery_addresses: ~
- 添加SpoolTrait及其方法
public function purgeSpool()
public function getSpooledEmails()
public function getEmailContent($file)
protected function getSpoolDir()
正确项目结构的示例
有关功能测试的正确项目结构和配置,请参阅链接