swisscom/aliceconnector
Composer 安装命令:
composer require swisscom/aliceconnector
包简介
Neos Flow package for expressive fixture generation based on alice
README 文档
README
Neos Flow package for expressive fixture generation based on Alice.
The Swisscom.AliceConnector simply provides a Context that connects your functional test cases with Alice.
Getting started
Install the package through composer. You likely require it for dev only.
composer require --dev swisscom/aliceconnector
Configuration
Set the path to your fixture files in the Settings.yaml:
Swisscom: AliceConnector: fixtureSets: default: '%FLOW_PATH_PACKAGES%Application/Your.Package/Tests/Fixtures/{name}.yaml'
Fixture creation
Create your file based Alice fixtures under the path defined in fixtureSets.
This basic example stored as Company.yaml defines a single fixture object for the domain model Company:
Your\Package\Domain\Model\Company: company1: name: 'Swisscom'
For a more real case example and documentation reference about the notation go to "[What does Alice?](#What does Alice?)".
Usage
Use the Context in your test and load the fixtures. $testablePersistenceEnabled should be enabled to work with persistence.
<?php namespace Your\Package\Tests\Functional; use Swisscom\AliceConnector\Context; use Neos\Flow\Tests\FunctionalTestCase; class CompanyTest extends FunctionalTestCase { /** * @var Context */ protected $fixtureContext; public function setUp(): void { parent::setUp(); $this->fixtureContext = new Context($this->objectManager, $this::$testablePersistenceEnabled); } /** * @test */ public function companyTest() { $fixtures = $this->fixtureContext->loadFixture('Company'); $company = $fixtures['company1']; self::assertSame('Swisscom', $company->getName()); } }
If you have persistence enabled, you could also query the fixture through your repository:
$companyRepository = $this->objectManager->get(CompanyRepository::class); $company = $companyRepository->findOneByName('Swisscom');
This example loads the fixture defined in %FLOW_PATH_PACKAGES%/Application/Your.Package/Tests/Fixtures/Company.yaml'
What does Alice?
Alice allows you to define expressive fixtures based on YAML, JSON or PHP files. Alice again is relying on Faker to create fake data for your fixtures.
The following sample shows you the real gain of Alice creating 10 random Person entities with account and related entities:
Neos\Flow\Security\Account: account{1..10}: accountIdentifier: 'user<current()>' credentialsSource: <passwordHash('12345678')> authenticationProviderName: UsernamePasswordTestingProvider roles: - <role('Your.Package:User')> Neos\Party\Domain\Model\PersonName: personName{1..10}: firstName: '<firstName()>' lastName: '<lastName()>' Neos\Party\Domain\Model\ElectronicAddress: electronicAddress{1..10}: identifier (unique): '<email()>' type: Email Neos\Party\Domain\Model\Person: person{1..10}: name: '@personName<current()>' primaryElectronicAddress: '@electronicAddress<current()>' accounts: - '@account<current()>'
We use fixture ranges {1..10} to create the 10 objects each, fixture references (e.g. @personName) as well as
faked data through faker formatters (e.g. firstName()).
See the complete Alice reference for detailed information and more features.
What does Faker?
Faker simply provides random dummy data for your fixtures by providing formatters which can be used in Alice. See the available Faker formatters for complete reference.
The faker formatters are directly called in the fixture definition file.
Additionally, the Context exposes the faker generator through getFaker(), so that formatters can be used even directly in your code.
Custom Flow formatters
The package provides the following custom formatters for your Flow application.
Collection
A doctrine array collection:
$collection = $faker->arrayCollection([$item1, $item2]);
Resource
A persistent resource:
$resource = $faker->persistentResource('Dummy.txt');
Image asset with reference to a persistent resource:
$image = $faker->persistentResourceImage('Dummy.png');
Document asset with reference to a persistent resource:
$document = $faker->persistentResourceDocument('Dummy.pdf');
Content string from a resourcee:
$string = $faker->fileContent('Dummy.txt');
Security
Password hash for the given password:
$image = $faker->hashPassword('12345678');
Role object for the identifier:
$image = $faker->role('Your.Package:User');
Notes
- Context and providers are all stored inside the
Classesfolder to make them available not only for test cases. Possible use cases are fixture generation on demo environments or even master data imports on prod environments. - For reference data import see the Swisscom.ReferenceDataImport implementation which is based on this package.
swisscom/aliceconnector 适用场景与选型建议
swisscom/aliceconnector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.06k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 swisscom/aliceconnector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 swisscom/aliceconnector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 14
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-12