运行所有测试时,爱丽丝会生成随机数据

问题描述

我使用的是api平台,并使用夹具(https://api-platform.com/docs/distribution/testing/#testing-the-api)编写unittest。当我为特定类别进行测试时,我得到了相同的灯具数据,但是当我进行所有测试时,我得到了一些随机数据。

这是我的固定装置:

# 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,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/apidocker-compose exec php bin/console的别名
  • bin/api-testdocker-compose exec php bin/phpunit的别名

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)