定制 bricre/symfony-bundle-test 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bricre/symfony-bundle-test

Composer 安装命令:

composer require bricre/symfony-bundle-test

包简介

Supportive classes for testing Symfony private services

README 文档

README

Inspired by https://github.com/SymfonyTest/symfony-bundle-test

Test Symfony Private Services easily

Symfony has already provided a way to test private services since 4.1, it only allows non-removed private services. This is not enough, especially when we develop a Symfony Bunddle. By default, we can create a lot of private services in a bundle, but when writing tests dedicated for the bundle theses services would not be testable because they were not used in any actual codes yet hence would be removed by Symfony.

The solution would be deliberately marking these services as public, so we can fetch them to do integration test.

Installation

Via composer

composer require --dev bricre/symfony-bundle-test

Write a test

<?php
use Bricre\SymfonyTest\BaseBundleTestCase;
use Acme\AcmeFooBundle;
use Acme\Service\Foo;

class BundleInitializationTest extends BaseBundleTestCase
{
    protected function getBundleClass():string
    {
        return AcmeFooBundle::class;
    }

    public function testInitBundle()
    {
        // Boot the kernel.
        $this->bootKernel();

        // Get the container
        $container = $this->getContainer();

        // Test if you services exists
        $this->assertTrue($container->has('acme.foo'));
        $service = $container->get('acme.foo');
        $this->assertInstanceOf(Foo::class, $service);
    }

    public function testBundleWithDifferentConfiguration()
    {
        // Create a new Kernel
        $kernel = $this->createKernel();

        // Add some configuration
        $kernel->addConfigFile(__DIR__.'/config.yml');

        // Add some other bundles we depend on
        $kernel->addBundle(OtherBundle::class);

        // Boot the kernel as normal ...
        $this->bootKernel();

        // ...
    }
}

MicroBundleTestCase vs FrameworkedBundleTestCase

The MicroBundleTestCase is a minimal bundle test case with the least overhead to bootstrap a bundle test. It will not include any bundles by default.

In real life environment your bundle would often depend on the FrameworkBundle, so a FrameworkedBundleTestCase is created for you with some default configuration ready.

<?php
use Bricre\SymfonyTest\FrameworkedBundleTestCase;

class BundleInitializationTest extends FrameworkedBundleTestCase
{
}

The default configurations is loaded from

|/vendor/
|----/bricre/
|--------/symfony-bundle-test/
|------------/src/
|----------------/config/
|--------------------framework.yml
|--------------------routing.yml
|--------------------...

If you want to customise the config, just create a config folder in your own bundle as if it was in a Symfony project

|/config/
|----framework.yml
|----routing.yml
|----...
|/src/
|/vendor/

bricre/symfony-bundle-test 适用场景与选型建议

bricre/symfony-bundle-test 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 120 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bricre/symfony-bundle-test 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bricre/symfony-bundle-test 我们能提供哪些服务?
定制开发 / 二次开发

基于 bricre/symfony-bundle-test 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 120
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2020-12-04