定制 umanit/dev-bundle 二次开发

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

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

umanit/dev-bundle

Composer 安装命令:

composer require --dev umanit/dev-bundle

包简介

Helper classes and dependencies for usual dev environment

README 文档

README

This bundle is used for development at UmanIT.

It provides multiple tools and rules to ease development.

PHP Arkitect

Rules for PHP Arkitect:

  • NotAbuseFinalUsage: Disallow to use final classes if at least one public method of your class is called in another public method of the same class.
  • NotUseConcreteWhenInterfaceExists: Disallow the use of a concrete class inside typehint if an interface exists for tha class.
  • NotUseGenericException: Disallow the use of generic \Exception class.

Usage

Edit your arkitect.php file to include the following:

use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Umanit\DevBundle\Arkitect\Expression\ForClasses\NotAbuseFinalUsage;
use Umanit\DevBundle\Arkitect\Expression\ForClasses\NotUseGenericException;

// [...]

$rules[] = Rule
    ::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App'))
    ->should(new NotUseGenericException())
    ->because('we want to force usage of SPL exceptions or custom ones')
;

$rules[] = Rule
    ::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App'))
    ->should(new NotUseConcreteWhenInterfaceExists())
    ->because('we want to depend on interfaces, not concrete implementations')
;

$rules[] = Rule
    ::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App'))
    ->should(new NotAbuseFinalUsage())
    ->because('we want avoid final classes which reduce extensibility')
;

Foundry

Various tools to ease tests creation:

  • A database reseter usable as a Symfony command.
  • Some utilities function to ease the creation of entities.
  • Possibility to use aliases on Doctrine entities within factories.
  • A per-class key/value store accessible via addToStore/getListFromStore (lists) and setInStore/getFromStore (scalars), so child factories can accumulate state between persists without declaring static properties (which PHPStan flags on @immutable Foundry factories). The store is reset automatically via ResetInterface.

PHPStan

Rules for PHPStan:

  • EnsureFunctionBackslashRule: Ensure that some optimizable functions are called with backslash.
  • MonologExceptionContextKey: Ensure that an exception inside a Monolog context use the exception key.
  • NoWhereOnQueryBuilderRule: Disallow to use where method on QueryBuilder in favor of andWhere.

Usage

Edit your phpstan.neon file to include the following:

rules:
    - Umanit\DevBundle\PHPStan\Rules\EnsureFunctionBackslashRule
    - Umanit\DevBundle\PHPStan\Rules\NoWhereOnQueryBuilderRule

TestEventDispatcher

A test double for Symfony's EventDispatcher that records all dispatched events so they can be inspected and asserted on in tests without triggering real listeners.

Usage

Bind TestEventDispatcher as the EventDispatcherInterface service in your test environment, then assert on the events after the action under test:

$event = $dispatcher->getLastDispatchedEvent(MyEvent::class);
$this->assertInstanceOf(MyEvent::class, $event);

// All events dispatched under a given name
$events = $dispatcher->getDispatchedEvents(MyEvent::class);

// Full map of every dispatched event
$all = $dispatcher->getAllDispatchedEvents();

TestUtils

One static method TestUtils::setId to set the id of an entity by reflection. Useful for tests when your entities do not expose a setId method.

Usage

In your test:

TestUtils::setId($entity, 42);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固