标签: alice-fixtures

Alice夹具生成器中可重用的属性或特征组

可以在Alice中描述夹具继承:

// template.yml
Nelmio\Entity\User:
    user (template):
        username: '<username()>'
        age: '<numberBetween(1, 20)>'
Run Code Online (Sandbox Code Playgroud)

-

include:
  - template.yml

Nelmio\Entity\User:
    user1 (extends user):
        name: '<firstName()>'
        lastname: '<lastName()>'
        city: '<city()>'
        age: '<numberBetween(1, 50)>'
Run Code Online (Sandbox Code Playgroud)

如何定义可重用的属性集合(类似于Traits)?

如果我希望能够定义具有两个属性的模板,例如,该怎么办?

createdAt: <(new \DateTime('2016-01-01'))>
updatedAt: <(new \DateTime('2016-01-02'))>
Run Code Online (Sandbox Code Playgroud)

然后在任何模板中使用它们而不必为每个实体重新定义这些属性?

我知道Alice支持多继承.例如:

Nelmio\Entity\User:
    user_bare (template):
        username: '<username()>'
    user_full (template, extends user_bare):
        name: '<firstName()>'
        lastname: '<lastName()>'
        city: '<city()>'
Run Code Online (Sandbox Code Playgroud)

然而,由于每个模板必须在相同的名称空间(Nelmio\Entity\User)下定义,因此这似乎不是前进的方式,而Traits应该可以在任何名称空间中使用.

是否有一种干净的方法可以在任何命名空间中重用夹具属性组?

fixtures symfony nelmio-alice alice-fixtures

10
推荐指数
0
解决办法
323
查看次数

我可以使用Alice Fixtures覆盖自动增量ID吗?

我正在使用Symfony2和Doctrine,我正在使用Alice Fixture包生成我的灯具进行测试.

在一种情况下,我需要创建一个夹具,其中id为148,用于特定测试.我们所有的id都配置为auto_increment,所以我目前正在创建147个虚拟记录,只是为了创建我需要的记录.

我希望使用此定义强制将id设置为148:

 invoiceClassNoClass (extends invoiceClass):
    id: 148
    sortOrder: 1
    label: 'No Class'
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用.从谷歌搜索我读了一个简短的评论,说我首先需要添加一个setId方法到我的实体.我试过了,但没有什么区别.实际上,如果我不需要,我不想添加为setId方法,因为它违反了我们永远不允许设置id的完整性规则.

也许有可以使用的反射类?也许这是爱丽丝的内置而我不知道呢?

symfony doctrine-orm nelmio-alice alice-fixtures

7
推荐指数
3
解决办法
3251
查看次数

如何在symfony WebTestCase中通过测试中的fixture类型获取doctrine fixture引用?

我正在使用doctrine fixtures在我的symfony应用程序中加载测试数据.

 $this->fixtureLoader = $this->loadFixtures([
            "My\DemonBundle\DataFixtures\ORM\LoadEntity1Data",
            "My\DemonBundle\DataFixtures\ORM\LoadEntity2Data",
            "My\DemonBundle\DataFixtures\ORM\LoadEntity3Data",
            "My\DemonBundle\DataFixtures\ORM\LoadEntity4Data",
            "My\DemonBundle\DataFixtures\ORM\LoadEntity5Data",
            'My\DemonBundle\DataFixtures\ORM\LoadEntity6Data'
]);
Run Code Online (Sandbox Code Playgroud)

在我的测试用例中,我想测试获取分页实体.

public function testGetPaginated()
{

    $entities6 = $this->fixtureLoader->getReferenceRepository()->getReferences();

    $expected = array_slice($entities6, 3, 3);

    $this->client = static::makeClient();
    $this->client->request('GET', '/api/v1/entities6', ["page" => 2, "limit" => 3, "order" => "id", "sort" => "asc"], array(), array(
        'CONTENT_TYPE' => 'application/json',
        'HTTP_ACCEPT' => 'application/json'
    ));


   $this->assertSame($expected, $this->client->getResponse()->getContent());

}
Run Code Online (Sandbox Code Playgroud)

我想比较我的灯具和api响应的页面.问题是线下返回所有夹具参考.我想测试的实体是Entity6类型.Entity6依赖于所有其他类型,因此我必须加载所有其他类型.

$ entities = $ this-> fixtureLoader-> getReferenceRepository() - > getReferences();

我如何才能获得Entity6类型的推荐?我深入研究

Doctrine\Common\DataFixtures\ReferenceRepository :: getReferences代码

/**
 * Get all stored references
 *
 * @return array
 */ …
Run Code Online (Sandbox Code Playgroud)

php fixtures symfony doctrine-orm alice-fixtures

6
推荐指数
1
解决办法
1370
查看次数

与Nelmio Alice的Symfony 4灯具不坚持

我在Symfony 4中使用Alice的数据夹具有问题.

当我运行bin/console doctrine:fixtures:load我被问到是否要清除db并最终命令终止而没有任何错误.

数据库被有效清除,但没有填充数据.

我正在使用Symfony 4.0.3,Doctrine Data Fixtures 1.3和Nelmio Alice 3.1.3.

SRC/DataFixtures/ORM/fixtures.yml

App\Entity\User:
user{1..10}:
    email: '<email()>'
Run Code Online (Sandbox Code Playgroud)

SRC/DataFixtures/ORM/LoadFixtures.php

namespace App\DataFixtures\ORM;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Nelmio\Alice\Loader\NativeLoader;


class LoadFixtures extends Fixture
{
    public function load(ObjectManager $manager)
    {
        $loader = new NativeLoader();
        $objectSet = $loader->loadFile(__DIR__.'/fixtures.yml');

    }
}
Run Code Online (Sandbox Code Playgroud)

SRC /实体/ user.php的

namespace App\Entity;

use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User implements UserInterface
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer")
     */
    private $id;
    /** …
Run Code Online (Sandbox Code Playgroud)

doctrine symfony nelmio-alice alice-fixtures symfony4

4
推荐指数
1
解决办法
2754
查看次数

Alice Faker 库从数组中随机选择

我正在尝试使用AliceBundle for Symfony Framework生成虚拟数据。除了我正在寻找一种方法将数组中的数据随机分配给名为type. 查看faker 库,我可以看到我可以使用randomElement($array = array ('a','b','c'))

我正在尝试将其转换为YML并且我认为这相当于

<randomElement(['a','b','c'])>
Run Code Online (Sandbox Code Playgroud)

但这会产生错误

[Nelmio\Alice\Throwable\Exception\FixtureBuilder\ExpressionLanguage\LexException] 无法对值“['a'”进行词法分析。

这是我的完整 yml

AppBundle\Entity\Job:
    job{1..5}:
        title: <jobTitle()>
        description: <paragraph(3)>
        length: "3_months_full_time"
        type: <randomElement(['a','b','c'])>
        bonus: <paragraph(3)>
        expired_at: "2016-12-21"
        job_user: "@emp*"
Run Code Online (Sandbox Code Playgroud)

symfony nelmio-alice alice-fixtures

4
推荐指数
2
解决办法
1725
查看次数

Alice bundle - 如何在 yml 夹具中使用编码密码

我使用 hautelook/alice-bundle。

由于以下错误($ in 解释为对对象的引用),我无法在我的装置中使用编码的 bcrypt 密码:

在 SimpleObjectGenerator.php 第 114 行:

生成夹具“实习生”(App\Document\Trainee) 时出错:在生成过程中无法解析值。

App\Document\Trainee:
# template
trainee (template):
    firstName:              <fr_FR:firstName()>
    lastName:               <fr_FR:lastName()>
    email (unique):         <fr_FR:email()>
    password :              $2y$13$I5uLW8atzRPmC3NcvirYqO2htdMHH1l4uFQ3z0V8wHowO0FqTXl7u
    plainPassword:          password
    birthdate:              <date('now')>
    address:                '@address_tr_*'
    phoneNumber:            <fr_FR:phoneNumber()>
    profileCompleted:       false
Run Code Online (Sandbox Code Playgroud)

你知道为什么吗?谢谢你

php symfony alice-fixtures

4
推荐指数
1
解决办法
1751
查看次数

为什么 AliceBundle Fixture DateTime 给我一个意外的值?

我目前正在开发一个项目,在该项目中,我使用 Alice-bundle 创建固定装置来运行测试,以确保我的 API 端点正常工作。除了 DateTime 属性之外,一切正常。

无论我传递什么字符串,例如:<dateTime('2019-09-23 14:00:00')>,它总是给我错误的日期和时间,通常类似于:1998-10-25T14:29:45+01:00

即使使用也<dateTime('now')>不起作用——它还给了我一些 2000 年代之前的日期和时间,而这正是我发现的一些示例所使用的。

一个装置可能看起来像这样:

Path\To\Task\Entity: my_task: title: 'My tasks' description: 'These are all the tasks just for me!!!' startsAt: <dateTime('now')> endsAt: <dateTime('now')> createdBy: '@some_higher_user'

理想情况下,我只想向它传递一个字符串,以便我可以定义日期和时间,并确保它以正确的格式正常工作。

如有帮助,我们将不胜感激。

datetime symfony alice-fixtures

4
推荐指数
1
解决办法
1312
查看次数

在nelmio-alice中引用固定项目

我有一套固定装置(这是一个简化):

My\Entity\User:
  user_{1..10}:
    name: <firstName()>

My\Entity\Item:
  item_{1..10}:
    user: '@user_$current'
    data: <numberBetween(111111111, 999999999)>
Run Code Online (Sandbox Code Playgroud)

我想在我的 phpunit 功能测试中获取ItemID 。4

我不能确定自增ID是从1开始的。后面不是1 TRUNCATE。所以这是不正确的

$item4 = $this->em->getRepository(Item::class)->find(4);
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到参考item_4

doctrine symfony doctrine-orm nelmio-alice alice-fixtures

2
推荐指数
1
解决办法
1321
查看次数