承接 tiny/symfony-testing 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

tiny/symfony-testing

Composer 安装命令:

composer require --dev tiny/symfony-testing

包简介

Tools to facilitate testing Symfony web applications.

README 文档

README

Assistive package for doing functional testing on web applications built with Symfony framework.

Contains two major components:

  • TinyTestingBundle. Aims to deal with displaying exceptions while running functional tests.
  • WebTestCase. Built on top of Symfony's WebTestCase to provide more testing-friendly interface.

Currently only Symfony 3.4 is supported.

TinyTestingBundle

Bundle enables displaying actual exceptions thrown when running functional tests on Symfony application. It allows all Symfony\Component\HttpKernel\Exception\HttpException-s to be processed in a normal way (e.g. for twig can render a 404 page), and will rethrow any other exception so it can be caught by PHPUnit and reported.

If you make html web app, then while browsing it in dev mode and when something bad happens, you see a nice page with all the information about the exception (its class, code, message, stack trace, etc.). When runnning tests it is more valueable to have this exception actually thrown, so it can be reported to the console (or whatever output you or your IDE use).

Of course, there is an option to do

$client->catchExceptions(false);

in the test case. This will force HttpKernel throw exception instead of dispatching kernel.exception event.

The problem is that using this option requires some manual work (not much but on a regular basis). We have to either turn catching off each time we want to see an exception (and rerun the tests) or take care of creating (or configuring) different clients to support both cases.

Most likely, bundle should be registered only for test environment:

// AppKernel.php
if ($this->getEnvironment() === 'test') {
    $bundles[] = new Tiny\SymfonyTesting\TinyTestingBundle\TinyTestingBundle();
}

WebTestCase

Provides some assistive interface for functional testing. Extends Symfony's native Symfony\Bundle\FrameworkBundle\Test\WebTestCase.

Its setUp() creates instance of a client (can be access directly via $this->client, it is a protected). So if you have your own setUp() make sure to call parent::setUp().

Some configurative (i.e. to be used before request) methods, they have impact on all subsequent requests.

protected function setHost($host)

sets the host, useful when request routing involves host requirements (like api.example.com/users)

protected function setHeader($name, $value)

so stuff like $this->setHeader('Authoriation', 'Bearer wh.at.ever'); can be done

protected function setCookie($name, $value, $expires = null, $path = null, $domain = '', $secure = false, $httponly = false)

Provided request methods:

protected request($uri, $method = 'GET', $parameters = [], $files = [], $server = [], $content = '', $changeHistory = true)

pretty much the same as in Symfony\Bundle\FrameworkBundle\Client::request except for $method and $uri parameters are swapped.

Some shortcut request methods:

protected function get($uri, $parameters = [])

protected function post($uri, $content = '', $parameters = [])

protected function put($uri, $content = '')

protected function patch($uri, $content = '')

protected function delete($uri, $content = '')

Before request it's possible to set some parameters using

protected function setParameters(array $parameters)

Request parameters set with this method are sent only with next single subsequent request.

Response and assertions

After request is made, it's possible to reach the response via $this->response (instance of Symfony\Component\HttpFoundation\Response).

Currently only single assertion implemented for response status code, accessible as $this->assertStatusCode($expectedCode).

tiny/symfony-testing 适用场景与选型建议

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

它主要适用于以下技术方向: 「symfony」 「testing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-16