Php 在Laravel Webhook中为条带运行测试时出错-无法解析主机
我正在测试Stripe用来与我的Laravel应用程序通信的webhook。 我正在使用它,并且我正在跟随他们 下面是我的测试用例:Php 在Laravel Webhook中为条带运行测试时出错-无法解析主机,php,laravel,testing,phpunit,webhooks,Php,Laravel,Testing,Phpunit,Webhooks,我正在测试Stripe用来与我的Laravel应用程序通信的webhook。 我正在使用它,并且我正在跟随他们 下面是我的测试用例: use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use TeamTNT\Stripe;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use TeamTNT\Stripe;
class WebhooksControllerTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testWhenCustomerSubscriptionDeleted()
{
$tester = new TeamTNT\Stripe\WebhookTester('http:/localhost/stripe/webhook');
$response = $tester->triggerEvent('customer.subscription.deleted');
$this->assertEquals(200,$response->getStatusCode());
//$this->assertTrue(true);
}
}
当我运行phpunit
时,我得到以下错误:
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 4.57 seconds, Memory: 10.00MB
There was 1 error:
1) WebhooksControllerTest::testWhenCustomerSubscriptionDeleted
GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: http (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:186
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:150
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:103
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php:43
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php:28
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Handler/Proxy.php:51
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php:72
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Middleware.php:30
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php:68
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Middleware.php:59
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/HandlerStack.php:67
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Client.php:275
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Client.php:123
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Client.php:129
/home/levi/SIGadmin/vendor/guzzlehttp/guzzle/src/Client.php:87
/home/levi/SIGadmin/vendor/teamtnt/php-stripe-webhook-tester/src/Stripe/WebhookTester.php:85
/home/levi/SIGadmin/tests/WebhooksControllerTest.php:18
/usr/share/php/PHPUnit/TextUI/Command.php:155
/usr/share/php/PHPUnit/TextUI/Command.php:106
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
我查找了错误代码,发现如下:
无法解析主机。未解析给定的远程主机。
以下是我的webhook路线:
Route::post('stripe/webhook', 'WebhooksController@handle');
这是我真正的网络钩子:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
class WebhooksController extends Controller
{
public function handle()
{
$payload = request()->all();
$method = $this->eventToMethod($payload['type']);
if(method_exists($this, $method))
{
$this->$method($payload);
}
return response('Webhook Received');
//return redirect('myaccount')->with('success', 'Account deactivated');
}
public function whenCustomerSubscriptionDeleted($payload)
{
User::byStripeId(
$payload['data']['object']['customer']
)->deactivate();
}
public function whenCustomerSubscriptionCreated($payload)
{
User::byStripeId(
$payload['data']['object']['customer']
)->addSubscriptionId($payload['data']['object']['id']);
}
public function eventToMethod($event)
{
return 'when' . studly_case(str_replace('.', '_', $event));
}
}
您可以在http://localhost
在浏览器中?http:/localhost/stripe/webhook
应该是http://localhost/stripe/webhook
@jszobody是的,我的应用程序运行正常。这两个URL之间有什么区别?lol@jszobody哦,我明白了。刚刚更新了我的问题您是否可以在http://localhost
在浏览器中?http:/localhost/stripe/webhook
应该是http://localhost/stripe/webhook
@jszobody是的,我的应用程序运行正常。这两个URL之间有什么区别?lol@jszobody哦,我明白了。刚刚更新了我的问题