【发布时间】:2015-12-18 09:20:35
【问题描述】:
我使用 codeception 测试我的 laravel5 应用程序,因为我的大多数单元测试都需要一个用户,所以我尝试在我的 unit/_bootstrap.php 文件中创建一个用户:
$user = \App\User::register($credentials);
但由于我无法访问 $user 变量,因此该文件似乎没有加载到我的测试中。测试总是失败并出现以下错误:
[PHPUnit_Framework_Exception] 未定义变量:用户
我使用默认的 codeception 配置,只是添加了 laravel5 模块。我也确信引导文件会被执行,因为我可以通过在其中抛出异常来中断测试。
unit.suit.yml:
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
- Laravel5:
enviroment_file: .env.testing
codeception.yml
actor: Tester
coverage:
enabled: true
include:
- app/Services/*
- app/Http/*
- app/Token.php
- app/User.php
exclude:
- app/Http/routes.php
- app/Http/Kernel.php
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
【问题讨论】:
-
你能分享你的套件的 Codeception 配置文件吗?如
unit.suite.yml -
我觉得不错。它是否正在执行
register()方法的任何内容? -
是的,我也可以打印返回值,看看一切正常
标签: php unit-testing laravel testing codeception