Php 嘲弄:检查参数是否至少传递了一次?
我想做一些看起来很平常的事情,但却找不到一个内置的解决方案 示例测试如下所示:Php 嘲弄:检查参数是否至少传递了一次?,php,testing,mockery,Php,Testing,Mockery,我想做一些看起来很平常的事情,但却找不到一个内置的解决方案 示例测试如下所示: <?php $user = factory(App\User::class)->create(['birthday' => Carbon::now()->subYear(20)]); $this->mailer->shouldReceive('sendBirthdayEvent') ->with(hasEntry("id", $user->id
<?php
$user = factory(App\User::class)->create(['birthday' => Carbon::now()->subYear(20)]);
$this->mailer->shouldReceive('sendBirthdayEvent')
->with(hasEntry("id", $user->id)); // Will fail if DB is seeded
$this->command->sendBirthdayEventToAllUSers();
<?php
$success = false;
$this->mailer->shouldReceive('sendBirthdayEvent')
->with(function($user_id) use($success) {
if($user_id) === $user->id {
$success = true:
}
return true;
});
assert($success,true);
但我觉得我真的错过了一些东西。试试这个:
$this->mailer->shouldReceive('sendBirthdayEvent')->with($user->id)->once();