【问题标题】:PHPSpec - checking that a method has been called with a class instance argumentPHPSpec - 检查方法是否已使用类实例参数调用
【发布时间】:2018-06-20 13:14:58
【问题描述】:

我在 RSpec 中有以下测试:

it { is_expected.to respond_to(:dock).with(1).argument }

我需要使用 PHPSpec 来复制这个测试。我的代码如下:

function it_should_dock_a_bike()
{
    $bike = new \Bike();
    $this->dock($bike)->shouldReturnAnInstanceOf('Bike');
}

此代码有效,当我排除 $bike 参数时它确实会失败,但有没有更好的方法来显式编写类似于 RSpec 中的示例的测试?

【问题讨论】:

  • 不知道 RSpec,with(1).argument 是什么意思?有什么论据吗?
  • 我想说唯一的改进是:function it_should_dock_a_bike() { $bike = new \Bike(); $this->dock($bike)->shouldReturnAnInstanceOf(Bike::class); }
  • @DonCallisto 是的,任何论点。

标签: php rspec phpspec


【解决方案1】:
$this->dock(Argument::any())->shouldReturnAnInstanceOf(Bike::class);

就是你要找的东西

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-24
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2016-08-19
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    相关资源
    最近更新 更多