thecrypticace / suitey
Artisan 命令,用于在 phpunit 测试期间运行类似中间件的钩子
dev-master
2017-08-19 01:40 UTC
Requires
- php: >=7.0.0
- illuminate/console: ^5.4
- illuminate/container: ^5.4
- illuminate/pipeline: ^5.4
- illuminate/support: ^5.4
- symfony/process: ^3.3
Requires (Dev)
- orchestra/testbench: ^3.4
- phpunit/phpunit: ^6.0
- symfony/var-dumper: ^3.2
This package is not auto-updated.
Last update: 2024-09-29 02:29:03 UTC
README
设置世界。在 PHPUnit 前后运行代码。
安装
composer require thecrypticace/suiteyphp artisan vendor:publish --tag=suitey- 更新
steps列表以配置和运行测试之前你想运行的步骤。
用法
使用 test artisan 命令运行你的测试
php artisan test
这也接受 PHPUnit 所有的参数
php artisan test --filter=my_test_method_name
想在 PHPUnit 之前传递参数给 artisan?使用 -- 来分隔两个列表
php artisan test -vvv -- --filter=my_test_method_name
添加步骤
当你运行 php artisan test 时,你将运行一个步骤:PHPUnit。你将可以看到这,因为你将得到如下输出的结果
[1/1] Run PHPUnit
… test details here …
让我们来修复它。
发布配置
运行 php artisan vendor:publish --tag=suitey 来发布配置文件。这个文件是你可以详细说明运行哪些步骤以及如何为测试加载测试环境变量的地方。
添加步骤
在 Suitey 的配置中,你会看到一个如下所示的 steps 数组
"steps" => [ // \TheCrypticAce\Suitey\MigrateDatabase::class, // \TheCrypticAce\Suitey\RefreshDatabase::class, // [ // "class" => \TheCrypticAce\Suitey\SeedDatabase::class, // "options" => ["class" => "ExampleSeeder"], // ] ],
取消注释 MigrateDatabase 步骤,你的数据库迁移将在测试之前运行。
"steps" => [ \TheCrypticAce\Suitey\MigrateDatabase::class, // \TheCrypticAce\Suitey\RefreshDatabase::class, // [ // "class" => \TheCrypticAce\Suitey\SeedDatabase::class, // "options" => ["class" => "ExampleSeeder"], // ] ],
注意:如果你愿意,你可以通过容器解析类而不是使用外观。
你的迁移现在将在测试运行之前运行。不要忘记从你的测试中移除 DatabaseMigrations 特性。
如果您的设置不典型,此步骤是可配置的。您可以可选地指定连接名称和/或迁移的路径。
"steps" => [ [ "class" => \TheCrypticAce\Suitey\MigrateDatabase::class, "options" => ["database" => "connection_name", "path" => "path_to_migrations"], ], ],
如果您有多个迁移文件夹
"steps" => [ [ "class" => \TheCrypticAce\Suitey\MigrateDatabase::class, "options" => ["database" => "foo", "path" => "database/migrations/foo"], ], [ "class" => \TheCrypticAce\Suitey\MigrateDatabase::class, "options" => ["database" => "bar", "path" => "database/migrations/bar"], ], [ "class" => \TheCrypticAce\Suitey\MigrateDatabase::class, "options" => ["database" => "baz", "path" => "database/migrations/baz"], ], ],
可用步骤
想看一些元信息吗?
Suitey 可以运行它自己的测试:./tests/Fixture/artisan test