romegasoftware/nova-test-suite
Composer 安装命令:
composer require romegasoftware/nova-test-suite
包简介
Library to help testing laravel nova resources faster
关键字:
README 文档
README
Install
composer require romegasoftware/nova-test-suite --dev
Usage
Generate Resource Test Cases
To get you started run php artisan nova:test resource_name. This will generate a Resource test and publish the NovaResourceTestCase if it was not already published.
First thing you will need to do after creating a resource tests is filling the remapResource() method. This method must map the nova fields names to
the resource properties. It's also not needed to map each property of the resource, just the ones that change or are required to be diferent.
protected function remapResource($resource): array { return [ 'location' => $resource->location_id, 'theme' => $resource->theme_id, ]; }
The $resource parameter is a fresh generated model instance via factory() and therefore should hold any necessary values you need. The $data parameter is only filled if you call a nova request method with any data like $this->storeResource(['name' => 'test']).
requests
get resources
// retrieve all available resources = viewing the index page $this->getResources(); // retrieve a single resource = viewing a single resource in detail view $resource = Resource::factory()->create(); $this->getResources($resource);
store resources
// resource data is generated behind the scenes with factory()->make() $this->storeResource(); // also accepts model classes or arrays $resource = Resource::factory()->make(); $this->storeResource($resource); $this->storeResource(['name' => 'Vader']);
If a resource is stored successfully the returned status code of the response is 201.
update resources
// resource data is generated behind the scenes with factory()->create() $this->updateResource(['name' => 'Vader']); // accepts model classes $resource = Resource::factory()->create(); $resource->name = 'Vader'; $this->updateResource($resource);
delete resources
// resource data is generated behind the scenes with factory()->create() $this->deleteResource(); // also accepts model classes, arrays or integers (ids) $resource = Resource::factory()->create(); $this->deleteResource($resource); $this->deleteResource(['id' => 12]); $this->deleteResource(12);
relationships
$this->assertHasManyRelationships([ 'product', ]); $this->assertBelongsToRelationships([ 'user', ]);
assertHasOneRelationships(array)
assertHasManyRelationships(array)
assertBelongsToRelationships(array)
assertBelongsToManyRelationships(array)
assertMorphToRelationships(array)
assertMorphOneRelationships(array)
assertMorphManyRelationships(array)
actions
Use assertHasActions()
lenses
use assertHasLenses()
filters
use assertHasFilters()
Asserting a request has failed
Since failed nova request return a redirect with status code 301 we introduced a new method assertNovaFailed() which checks for this without having to think about what status code a failed nova response returns.
$this->storeResource() ->assertNovaFailed();
Testing required fields
To test if your Nova resource is setup correctly and check if all required fields are set as expected you can use the setNullValuesOn([..]) method, which assignes every key you enter a null value for the next request.
$this->setNullValuesOn(['customer', 'number_of_participants']) ->storeResource() ->assertRequiredFields(['customer', 'number_of_participants']);
Using the default user
By default each nova request method checks whether a request was already authenticated through actingAs($user, 'api'). If no user was provided to authenticate the request we will use the getDefaultUser() method to authenticate your request. If you want to be explicit about using the default user for a request you can use $this->beDefaultUser() which will return the current class, therefore it will also work with chaining e.g. $this->beDefaultUser()->storeResource().
If you want to use your own user for every request you can override the getDefaultUser() method.
protected function getDefaultUser() { return $this->yourOwnUser; }
Debugging failing requests
To debug more easily why your nova request is failing you can chain assertSessionDoesntHaveErrors() before you make any assertions about the status. This method will dump all session errors and the json response of the request.
$this->storeResource() ->assertSessionDoesntHaveErrors();
If you still can't figure out why you are receiving the status code of the response, try to get behind the reason of the response with withoutNovaExceptionHandling(). This method call will create a callback which calls the underlying withoutExceptionHandling() as soon as the Nova middleware runs. You can also chain the calls:
$this->withoutNovaExceptionHandling() ->storeResource();
Testing
Run the tests with:
vendor/bin/phpunit
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
Security
If you discover any security-related issues, please email bkeith@romegasoftware.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
romegasoftware/nova-test-suite 适用场景与选型建议
romegasoftware/nova-test-suite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.34k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 romegasoftware/nova-test-suite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 romegasoftware/nova-test-suite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 romegasoftware/nova-test-suite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Laravel package for Accurate Online API integration.
Shared RCX Laravel DataTables UI and configuration helpers.
Boot a Laravel project on any machine with one command: app:serve installs missing tools (PHP, Node, Composer, Herd, Docker), creates .env, sets up the database, runs migrations, builds assets, starts a queue worker and serves via Herd, Sail or artisan serve; app:down cleanly stops everything it sta
Branded, diagnostic error pages (500, 403, 404, 419, 503) for Filament — native Filament UI, dark mode and translations out of the box.
Turn any PDF into a Pingen-ready A4 letter (generated address cover page + A4 normalisation + safe margins) and send it through the Pingen print & mail API. Laravel-first.
统计信息
- 总下载量: 4.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-08