divineomega / phantomjs-laravel-testing
PhantomJS Laravel 测试
v1.0
2017-02-16 17:23 UTC
Requires
- facebook/webdriver: ^1.2
- jakoch/phantomjs-installer: 2.1.1-p08
- laravel/framework: 5.1.*
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2024-09-06 08:59:11 UTC
README
PhantomJS Laravel 测试包允许您轻松测试 Laravel 应用的 JavaScript 功能。它利用 PhantomJS 无头浏览器来模拟真实用户与您页面交互的方式。如果您已经习惯了常规的 Laravel 测试,那么您会高兴地知道,这个包尽可能地与它的语法相匹配。
💡 注意:如果您正在启动一个新项目,我建议使用 Laravel Dusk。因为 PhantomJS 开发已被暂停,并且可能不会收到任何未来的更新。
特性
- 尽可能使用与标准 Laravel 测试代码相同的语法
- 由 PhantomJS 提供动力的无头浏览器允许进行全面的功能测试,包括 JavaScript 和 AJAX
- 使用数据库事务来防止测试对数据库产生永久性影响
- 自动设置和安装所有依赖项,包括 phantomjs 二进制文件
要求
- 目前仅支持 Laravel 5.1
安装
- 将 composer 脚本
"PhantomInstaller\\Installer::installPhantomJS"
添加到composer.json
的post-install-cmd
和post-update-cmd
数组。 - 使用
composer require divineomega/phantomjs-laravel-testing
安装。 - 将服务提供者
DivineOmega\PhantomJSLaravelTesting\ServiceProvider::class
添加到config/app.php
的providers
数组。 - 将全局中间件
\DivineOmega\PhantomJSLaravelTesting\Http\Middleware\GlobalMiddleware::class
添加到app/Http/Kernel.php
的middleware
数组。
用法
只需将您的测试类更改为扩展 PhantomJSTestCase
而不是 TestCase
,然后像平常一样运行您的单元测试。当需要时,PhantomJS 将自动启动。
以下是一个示例测试用例。
<?php use DivineOmega\PhantomJSLaravelTesting\Objects\PhantomJSTestCase; class ExampleTestCase extends PhantomJSTestCase { public function testGoogleShowsImFeelingLucky() { $this->visit('https://google.co.uk/'); $this->see('I\'m Feeling Lucky'); } public function testGoogleShowsImFeelingDucky() { $this->visit('https://google.co.uk/'); $this->see('I\'m Feeling Ducky'); } }