【问题标题】:Laravel Stripe MockingLaravel 条纹模拟
【发布时间】:2018-10-03 17:41:29
【问题描述】:

我们如何在 Laravel 单元测试中模拟 Stripe,而不使用像 stripe-mock 等任何外部包?

工作是测试控制器功能,其中密码是硬编码的,并且由于哪个测试失败。

【问题讨论】:

    标签: laravel mocking stripe-payments


    【解决方案1】:

    嘿,我遇到了同样的问题,
    我正在使用来自codeception的aspectmock。设置它让我有些悲伤,但我现在能够用 json 响应模拟所有响应。这样,json 数据通过条带类并抛出正确的错误并返回相同的对象。
    希望对您有所帮助
    https://github.com/Codeception/AspectMock

    public function testAll()
    {
        $customerClass = new StripeCustomers();
        test::double('Stripe\HttpClient\CurlClient', ['request' => [json_encode($this->allJsonData), 200, []]]);
        $customer = $customerClass->all();
        $this->assertArrayHasKey('data', $customer);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-08-26
      • 2015-07-04
      • 2022-11-18
      • 1970-01-01
      • 2015-09-25
      • 2021-02-21
      • 2014-07-09
      • 2021-08-03
      • 2018-07-26
      相关资源
      最近更新 更多