nunomaduro/laravel-mojito
Composer 安装命令:
composer require --dev nunomaduro/laravel-mojito
包简介
A lightweight package for testing Laravel views.
README 文档
README
About Mojito
Mojito was created by, and is maintained by Nuno Maduro, and is a lightweight package for testing Laravel views in isolation.
Installation & Usage
Requires PHP 8.0+
Require Mojito using Composer:
composer require nunomaduro/laravel-mojito --dev
How to use:
class WelcomeTest extends TestCase { // First, add the `InteractsWithViews` trait to your test case class. use InteractsWithViews; public function testDisplaysLaravel() { // Then, get started with Mojito using the `assertView` method. $this->assertView('welcome')->contains('Laravel'); } }
Optionally, you can also perform view testing from your HTTP Tests:
class WelcomeTest extends TestCase { public function testDisplaysLaravel() { $response = $this->get('/'); $response->assertStatus(200); $response->assertView()->contains('Laravel'); } }
contains
Asserts that the view contains the given text.
$this->assertView('button')->contains('Click me'); $this->assertView('button', ['submitText' => 'Cancel'])->contains('Cancel'); $this->assertView('welcome')->in('title')->contains('Laravel'); $this->assertView('welcome')->in('.content')->contains('Nova');
empty
Asserts that the view has no text content.
Note: empty html nodes are not considered in this check.
$this->assertView('empty')->in('.empty-div')->empty();
first
Filters the view and returns only the first element matching the selector.
$this->assertView('welcome')->first('.links a')->contains('Docs');
has
Asserts that the view has the given selector.
$this->assertView('button')->has('button'); $this->assertView('welcome')->has('head'); $this->assertView('welcome')->in('body')->has('.content');
hasAttribute
Asserts that the view root element has the given attribute value.
$this->assertView('button')->hasAttribute('attribute', 'value'); $this->assertView('button')->hasAttribute('data-attribute', 'value'); $this->assertView('welcome')->hasAttribute('lang', 'en'); $this->assertView('welcome')->in('head')->first('meta')->hasAttribute('charset','utf-8');
hasClass
Asserts that the view has an element with the given class.
$this->assertView('button')->hasClass('btn'); $this->assertView('welcome')->in('.content')->at('div > p', 0)->hasClass('title');
hasLink
Asserts that the view has an element with the given link.
$this->assertView('button')->hasLink(route('welcome')); $this->assertView('welcome')->in('.links')->first('a')->hasLink('https://laravel.com/docs'); $this->assertView('welcome')->in('.links')->at('a', 6)->hasLink('https://vapor.laravel.com'); $this->assertView('welcome')->in('.links')->last('a')->hasLink('https://github.com/laravel/laravel');
in
Filters the view and returns only the elements matching the selector.
$this->assertView('welcome')->in('.links a')->contains('Laracast');
last
Filters the view and returns only the last element matching the selector.
$this->assertView('welcome')->last('.links a')->contains('GitHub');
hasMeta
Asserts that the view has a given metatag in the head section.
$response->assertView()->hasMeta(['property' => 'og:title']); $response->assertView()->hasMeta(['property' => 'og:title', 'content' => 'Laravel']);
Macroable
Feel free to add your own macros to the ViewAssertion::class.
use NunoMaduro\LaravelMojito\ViewAssertion; // Within a service provider: ViewAssertion::macro('hasCharset', function (string $charset) { return $this->in('head')->first('meta')->hasAttribute('charset', $charset); }); // In your tests: $this->assertView('welcome')->hasCharset('utf-8');
Contributing
Thank you for considering to contribute to Mojito. All the contribution guidelines are mentioned here.
You can have a look at the CHANGELOG for constant updates & detailed information about the changes. You can also follow the twitter account for latest announcements or just come say hi!: @enunomaduro
Support the development
Do you like this project? Support it by donating
License
Mojito is an open-sourced software licensed under the MIT license.
nunomaduro/laravel-mojito 适用场景与选型建议
nunomaduro/laravel-mojito 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 459.82k 次下载、GitHub Stars 达 369, 最近一次更新时间为 2020 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「php」 「testing」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nunomaduro/laravel-mojito 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nunomaduro/laravel-mojito 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nunomaduro/laravel-mojito 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
The PHP SDK for Checkmango
Simple ASCII output of array data
Alfabank REST API integration
The testing extension of TYPO3voilà.
统计信息
- 总下载量: 459.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 370
- 点击次数: 17
- 依赖项目数: 13
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-16
