【问题标题】:Stripe webhook test returns empty table on execution, but works on stripe's webhook testerStripe webhook 测试在执行时返回空表,但适用于 stripe 的 webhook 测试器
【发布时间】:2020-06-10 10:14:15
【问题描述】:

我们的测试套件有问题。 当我们使用测试套件运行它时,我们会从 PHPUnit 得到一个“表为空...”的响应。

我们知道它有效,因为我们还使用 Stripe 的“发送网络挂钩”测试功能进行了测试,该功能有效,并且响应按预期存储。

我们的代码在这里:

public function test_webhook_received()
{
    $this->expectsJobs([StoreStripeWebHookJob::class]);
    $this->postJson('/stripeHook', [
        'created' => 1326853478,
        'livemode' => false,
        'id' => 'evt_00000000000000',
        'type' => 'account.external_account.created',
        'object' => 'event',
        'request' => NULL,
        'pending_webhooks' => 1,
        'api_version' => '2019-12-03',
        'data' => [
            'object' => [
                'id' => 'ba_00000000000000',
                'object' => 'bank_account',
                'account' => 'acct_00000000000000',
                'account_holder_name' => 'Jane Austin',
                'account_holder_type' => 'individual',
                'bank_name' => 'STRIPE TEST BANK',
                'country' => 'US',
                'currency' => 'gbp',
                'fingerprint' => '8JXtPxqbdX5GnmYz',
                'last4' => '6789',
                'metadata' => [],
                'routing_number' => '110000000',
                'status' => 'new',
            ],
            ],
        ]);

        $this->assertDatabaseHas('stripe_webhooks', [
            'stripe_created_at' => 1326853478,
            'type' => 'account.external_account.created',
        ]);
}

收到的响应是:

断言表 [stripe_webhooks] 中的行与 属性 { “stripe_created_at”:1326853478, “类型”:“account.external_account.created”}。

桌子是空的..

如果我们删除

$this->expectsJobs([StoreStripeWebHookJob::class]);

测试成功。显然,expectsJob() 调用应该在它所在的位置。

【问题讨论】:

    标签: laravel testing phpunit stripe-payments tdd


    【解决方案1】:

    ExpectsJob 也会拦截作业。很像expectsException。从您干净的命名约定“StoreStripe ...”来看 - 我会说在这些测试环境下它真的没有存储。

    您需要单独测试您的端点/控制器是否正在排队作业......并且该作业正在存储数据。 2 次测试。

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 2020-08-03
      • 2021-04-03
      • 2020-11-18
      • 2016-11-10
      • 2015-04-15
      • 2016-03-09
      • 2017-01-30
      • 2014-07-05
      相关资源
      最近更新 更多