Laravel 测试迁移污染断言
Laravel testing migrating pollutes assertions
在为我的 Laravel 包编写测试时,我遇到了一些奇怪的事情。我的空测试通过了,而不是标记为 "Risky".
进一步调查使我找到 PendingCommand
class,它在 运行 命令之前有一个 run()
method which makes an assertion on the exit code of the command. This PendingCommand
was instantiated by calling $this->astisan('migrate:fresh')->run()
. I was able to skip this assertion by calling assertExitCode(null)
。它有效,但仍有断言发生。
在 and/or 能够防止在执行实际测试之前发生断言之前有人遇到过这个问题吗?
很高兴看到正在进行哪些断言,但我无法找到它。我唯一能找到的是 Assert
class 保留所有已完成断言的 $count
,而不是哪一个。
我将继续寻找解决方案和post我对这个问题的发现。
发现 InteractsWithConsole
有一个带有断言的 withoutMockingConsoleOutput
method that will prevent a mock to be created。
最终代码:
$this->withoutMockingConsoleOutput()
->artisan('migrate:fresh');
在为我的 Laravel 包编写测试时,我遇到了一些奇怪的事情。我的空测试通过了,而不是标记为 "Risky".
进一步调查使我找到 PendingCommand
class,它在 运行 命令之前有一个 run()
method which makes an assertion on the exit code of the command. This PendingCommand
was instantiated by calling $this->astisan('migrate:fresh')->run()
. I was able to skip this assertion by calling assertExitCode(null)
。它有效,但仍有断言发生。
在 and/or 能够防止在执行实际测试之前发生断言之前有人遇到过这个问题吗?
很高兴看到正在进行哪些断言,但我无法找到它。我唯一能找到的是 Assert
class 保留所有已完成断言的 $count
,而不是哪一个。
我将继续寻找解决方案和post我对这个问题的发现。
发现 InteractsWithConsole
有一个带有断言的 withoutMockingConsoleOutput
method that will prevent a mock to be created。
最终代码:
$this->withoutMockingConsoleOutput()
->artisan('migrate:fresh');