承接 srlabs/laravel-testing-utilities 相关项目开发

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

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

srlabs/laravel-testing-utilities

Composer 安装命令:

composer require --dev srlabs/laravel-testing-utilities

包简介

Helper utilities for testing Laravel Applications

README 文档

README

This package is intended to be a collection of helpful utilities to assist with the development and maintenance of Laravel Applications.

Laravel Version Package Version Packagist Branch
7.* 10.* "srlabs/laravel-testing-utilities": "~10"
8.* 11.* "srlabs/laravel-testing-utilities": "~11"
9.* 12.* "srlabs/laravel-testing-utilities": "~12"

To install this package, run

$ composer require srlabs/laravel-testing-utilities

and then add the service provider to your service providers listing in app/config/app.php

'providers' => [
    // ...
    'SRLabs\Utilities\UtilitiesServiceProvider'
    // ...
],

Testing Assistant

This utility makes it easy to implement the testing stratgey described by Chris Duell in his blog post Speeding up PHP unit tests 15 times. When running tests that require the use of a database persistence layer, running migrations and seeding the database for each test can take a very long time. Chris instead suggests creating a sqlite database file ahead of time, and making a new copy of that file for each test instead.

This package provides an artisan command ('utility:testdb') that will run your migrations and seeds and save them to a pre-defined sqlite file. Once that is complete, there is a companion trait that you add to your tests which will copy the staging database file to the testing database location when running tests.

You need to define a sqlite database connection in your config/database.php file. The connection name can be whatever you would like, but the package will assume a name of 'staging' if you don't provide one.

Default 'staging' connection:

$ php artisan utility:testdb

Custom 'sqlite_testing' connection:

$ php artisan utility:testdb sqlite_testing

You can also specify a Database Seeder class:

$ php artisan utility:testdb sqlite_testing --class="SentinelDatabaseSeeder"

This command will migrate and seed the sqlite database you have specified.

When you are ready to use this new sqlite file in your tests, add the TestingDatabase trait to your test class, and use it as such:

use SRLabs\Utilities\Traits\TestingDatabaseTrait;

class FooTest extends TestCase {

    use TestingDatabaseTrait;

    public function setUp()
    {
      parent::setUp();

      $this->prepareDatabase('staging', 'testing');
    }

    public function testSomethingIsTrue()
    {
        $this->assertTrue(true);
    }

}

In this example "staging" is the Database connection that represents the pre-compiled sqlite file, and "testing" is a separate connection that represents the database that will be used by the tests. Each time the setUp() method is called, the testing sqlite file will be replaced by the staging sqlite file, effectively resetting your database to a clean starting point. You may need to do some extra configuration to have phpunit use your "testing" database.

(Optional) Run Automatically When Running PHPUnit

Using this method will have artisan utility:testdb execute before any tests are ran only if there are new migration changes.

1. Create file bootstrap/testing.php:

<?php

define('ARTISAN_PATH', realpath(__DIR__ . '/../artisan'));

/*
|--------------------------------------------------------------------------
| Check for new migrations and reseed if necessary
|--------------------------------------------------------------------------
|
*/

passthru('(php '.ARTISAN_PATH.' migrate:status --database='.(getenv('DB_CONNECTION') ?: 'testing').' | grep -q "| N    |") && php '.ARTISAN_PATH.' utility:testdb');

/*
|--------------------------------------------------------------------------
| Include Standard Autoload File
|--------------------------------------------------------------------------
|
*/

require __DIR__ . '/autoload.php';

2. Update phpunit.xml

<phpunit ...
         bootstrap="bootstrap/testing.php"
         ...
>
...
    <php>
        ...
        <!-- Change this to your connection name (if customized) -->
        <env name="DB_CONNECTION" value="testing"/>
    </php>
</phpunit>

srlabs/laravel-testing-utilities 适用场景与选型建议

srlabs/laravel-testing-utilities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.92k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2015 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-01-11