我正在使用 api-platform 并使用固定装置(https://api-platform.com/docs/distribution/testing/#testing-the-api)编写单元测试。当我为特定类运行测试时,我得到了相同的夹具数据,但是当我运行所有测试时,我得到了一些随机数据。
这是我的固定装置:
# one file
App\Entity\User:
user_{1..11}:
nickname: '<username()>'
avatar: '@image_user_<current()>'
firstname: '<firstname()>'
lastname: '<lastname()>'
user_{12..13}:
nickname: '<username()>'
avatar: null
firstname: '<firstname()>'
lastname: '<lastname()>'
# other file
App\Entity\Project:
project_{1..7}:
name: '<company()>'
author: '@user_<numberBetween(3, 13)>'
main_image: '@image_project_<current()>'
score: '<randomFloat(null, 0, 5)>'
created_at: <dateTime('2020-08-11 09:24')>
Nelmio_alice 配置看起来像:
> bin/api debug:config nelmio_alice
Current configuration for extension with alias "nelmio_alice"
=============================================================
nelmio_alice:
functions_blacklist:
- current
- shuffle
- date
- time
- file
- md5
- sha1
locale: en_US
seed: 1
loading_limit: 5
max_unique_values_retry: 150
当我每次通过一个类时运行测试时(所有数据都相同):
bin/api-test tests/Entity/UserTest
bin/api-test tests/Entity/ProjectTest
但是当我想运行所有测试时,我得到了用户的随机数据
bin/api-test
当我清除缓存时,我也获得了项目的随机数据,但在下一次运行项目测试通过时,用户不会
bin/api cache:clear --env=test
bin/api-test
// some projects and users test fail
bin/api-test
// projects tests pass, users not
bin/api
是一个别名docker-compose exec php bin/console
bin/api-test
是一个别名docker-compose exec php bin/phpunit