lag/colonel-smoker-bundle

Colonel 帮助您检查应用中的烟雾

安装量: 4,276

依赖: 0

建议者: 0

安全: 0

星标: 3

关注者: 1

分支: 0

开放问题: 6

类型:symfony-bundle

v1.0 2019-11-15 23:11 UTC

README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License

logo

Colonel Smoker 是烟雾专家。甚至可以在将应用部署到生产环境之前,告诉您应用是否在冒烟。

Colonel Smoker 会查找您的 Symfony 应用程序的 URL(目前仅支持 Symfony),并查找 500 错误。

主要功能

  • 帮助提供动态 URL 的需求参数
  • 默认使用 Symfony 路由中声明的路由
  • 检查响应代码
  • 检查结果 HTML 是否包含您的实体中的动态数据

目标是确保您的应用程序中的每个 URL 都不包含关键错误。它特别适合具有复杂和动态数据的页面。

此包依赖于 Symfony 服务注入。如果您不熟悉此内容,可以在此处阅读文档 https://symfony.ac.cn/doc/current/service_container.html

安装

composer require --dev lag/colonel-smoker-bundle

配置

# config/packages/test/lag_smoker.yaml
lag_smoker:
    host: 'http://127.0.0.1:8000/' # This is the default configuration
    # This route will be used to generated urls to test against
    routes:
        # The homepage route has no parameters and expect a 200 OK response code
        app.homepage: ~
        # The show article requires parameters. They will be provided by the mapping "article"
        app.show_article:
            mapping: article
    # The mapping will be used to generated urls with dynamic parameters
    mapping:
        # This name can be anything, but it has to be unique
        article:
            # This mapping will be used with the Article entity of your application
            entity: App\JK\CmsBundle\Entity\Article
            # The property id in the route parameters (/articles/{id} for example) will be mapped with id property of your entity
            requirements:
                id: id

使用

  1. 首先生成 URL 缓存
bin/console smoker:generate-cache
  1. 然后运行烟雾测试
bin/console smoker:smoke

如果您使用 Symfony WebServer 包,不要忘记运行 bin/console server:start --env=test

工作原理

Colonel Smoker 将读取配置并使用 Symfony 路由构建应用程序的 URL。URL 存储在缓存中。然后它调用每个 URL 并分析响应以查找 500 错误。但它还可以测试 HTML 是否包含某些静态或动态值。

例如,如果您的应用程序处理文章,Colonel Smoker 可以检查显示文章的页面是否包含文章标题。

文档

  1. 入门
  2. 构建 URL
  3. 响应处理器

配置参考

lag_smoker:
    routes:
        app.homepage:
            mapping: null
            provider: symfony
            handlers:
                response_code: 200
        app.show_articles_redirection:
            mapping: article
            provider: my_custom_requirements_provider
            handlers:
                response_code: 302
     mapping:
        article:
            entity: App\JK\CmsBundle\Entity\Article
            provider: symfony
            pattern: 'app.article_'
            excludes:
                - app.article.excluded_routes
            requirements:
                id: id
                categorySlug: category.slug
        

Colonel 依赖于 Symfony 的 DomCrawler 组件和 Goutte 客户端。

已知问题

在开发环境中,当服务器在同一台机器上(例如使用 Symfony Web 服务器时),我们多次调用 Symfony 客户端,缓存未命中以检索值并引发异常,导致一些构建失败。正在进行的补丁以避免这种情况。

## 路线图

  • 添加选项以在测试中设置超时,以避免与缓存的错误
  • 添加检查以查看 Web 服务器是否正在运行