定制 mano/autotest-bundle 二次开发

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

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

mano/autotest-bundle

最新稳定版本:v1.1.2

Composer 安装命令:

composer require --dev mano/autotest-bundle

包简介

Symfony bundle for automatic routes testing.

关键字:

README 文档

README

Symfony bundle for automatic routes testing - check the response code of all static routes defined in the framework. It supports both PHPUnit and Codeception testing. The module lists all the available routes with GET method, add default values and filter just those that does not contain wildcards. The routes that were not matched can be added manually though - see config. Then the response is checked just for the successful code.

In order to access authorised routes, set admin email in the config (or any user that has super privilege). There must be 'email' property on the user entity (or at least getter). Some routes might need to be excluded though (ex. '/logout','/login') as they are redirected.

Installation

composer require mano/autotest-bundle --dev
  • enable the bundle in config/test/bundles.php by pasting new array item
[   
    ...
    Mano\AutotestBundle\AutotestBundle::class => ['dev' => true, 'test' => true],
]

Config

create file config/packages/test/autotest.yaml and override the defaults if necessary.

# Default configuration for extension with alias: "autotest"
autotest:

    # Paths that will be excluded from the test. Exclusion is made before resolving paths therefore the regex may include curly braces (if the route to be excluded contains them).
    exclude: []
    
    # Paths that will be included into the test as they could not be resolved automatically. Array of object in format name:{nameOfRoute}, path:{manuallyAddedPath}'
    include: []

    # Custom resolver to be used - must implement PathResolverInterface
    resolver: null

    # Email of admin that can access all the routes - if authorisation needed.
    admin_email: null

    # User repository to be used - must have email property defined.
    user_repository: App\Repository\UserRepository

exclude paths

Some routes might need to be excluded though (ex. '/logout','/login') as they are redirected. It is advisable to declare allowed methods in the route annotation, so that you do not need to exclude POST only routes here. Regex can be used here to match multiple routes at once.

exclude: 
   - '/logout'
   - '/login'
   - '/foo/{name}' # if the route had default name (and therefore resolved)
   - '/foo/.*' # pattern will be wrapped by ~^regex$~i

include paths

All the routes that could not be automatically resolved (contain wildcard that can not be filled from defaults) can be listed here to be included in the test.

The full list of unresolved paths is outputted at the beginning of the test. A route listed in included paths is removed from the output.

include:
  - name: route_name
    path: '/foo/bar'
]

Usage

Cache needs to be cleared after modifications in the project before running the test.

PHPUnit

Add entry to phpunit.xml(.dist)

<testsuites>
    <testsuite name="Project Test Suite">
        <directory>tests</directory> -->
        <directory>vendor/mano/autotest-bundle/src/Test/</directory>
    </testsuite> 
</testsuites>

run

php bin/phpunit

Alternatively you can skip editing phpunit.xml and just extend any test.

class someTest extends \Mano\AutotestBundle\Test\PhpUnitWebTest

If you come across the exception "User repository 'App\Repository\UserRepository' not found" and you are sure it exists, register the service as public.

# config/services.yaml
services:
    ...
    App\Repository\UserRepository:
      public: true

Codeception

  • add the module to a suite (functional.suite.yml)
- \Mano\AutotestBundle\Test\CodeceptionAutotestModule
  • add module method autotest to any cest
class fooCest
{
    public function testStaticPages(FunctionalTester $I)
    {
        $I->autotest();
    }
}

Codeception is stricter with login - different authenticators (api keys) will not work out of the box.

Extension

The used path resolver is simple - it just adds defaults to the path and takes only GET method that does not contain wildcards (after completing defaults).

Custom resolver can be used and referenced from config. The resolver must implement Mano\AutotestBundle\PathResolverInterface.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固