gpt4 book ai didi

laravel - 如何在测试完成后修复 "Can' t 关闭模拟,它在另一个测试中可见”

转载 作者:行者123 更新时间:2023-11-28 21:37:55 24 4
gpt4 key购买 nike

我创建了简单的模拟。但它在所有测试执行期间都是可见的。在 laravel 和 Mockery::close 中尝试了 tearDown,但没有帮助。感谢您的帮助

查找有关此问题的信息,但一无所获。

    $mock = Mockery::mock("App\Repository\MainCity\Interfaces\GetMainCitiesInterface");
$mock->shouldReceive('getMainCities')->once()->with("ru")->andreturn($return);
app()->instance("App\Repository\MainCity\Interfaces\GetMainCitiesInterface", $mock);

$gmcci = app()->make("App\Repository\MainCity\Caching\Interfaces\GetMainCitiesCacheInterface");
$gmci = app()->make("App\Repository\MainCity\Interfaces\GetMainCitiesInterface");

$res = $gmcci->getMainCitiesCache(
"ru",
$gmci
);

$this->assertTrue( $res == $return );

\Mockery::close();

我希望在某些请求中获得真实的城市,但得到的是模拟结果

最佳答案

在我清理了 laravel 中的所有缓存(如 View 、配置等)后,一切都开始工作了。我不知道为什么它在这种情况下有帮助...

关于laravel - 如何在测试完成后修复 "Can' t 关闭模拟,它在另一个测试中可见”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56172159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com