我正在使用Codeception做WebServices测试,这是我的代码:
//Making first query for getting needed parameter
$I->wantTo('Make something');
$I->sendPOST($this->route, [
'token' => Fixtures::get('token'),
'id' => Fixtures::get('some_id')
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('"error_message"');
//Then I get what I need with regexp
if (preg_match('/^.*\s(?<value_i_need>\d+)\.$/', $I->grabDataFromResponseByJsonPath('$.status.error_message')[0], $matches)) {
$I->sendPOST($this->route, [
'token' => Fixtures::get('token'),
'id' => Fixtures::get('some_id')
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('"something"');
$I->seeResponseContains('"something_else"');
} else {
//And if I don't get needed parameter with regular expression, here I have to force test fail
}
Run Code Online (Sandbox Code Playgroud)
有人知道如何强制测试失败吗?
提前致谢!
我正在为Laravel移动应用程序开发API.
方法将向其他API发出请求,组合和过滤数据,更改其结构等.
应用程序的要求之一是响应时间不超过30秒,或者根本不响应.所以,我必须尽可能多地重复请求.我试图通过Laravel Queues实现这一点,并且目前在我的Job类中有类似的东西:
private $apiActionName;
public function __construct($apiActionName)
{
$this->apiActionName = $apiActionName;
}
public function handle(SomeService $someService)
{
return $someService->{$this->apiActionName}();
}
Run Code Online (Sandbox Code Playgroud)
而这个动作代码在控制器中:
public function someAction()
{
$data = $this->dispatch(new MyJob($apiActionName));
return response()->json($data);
}
Run Code Online (Sandbox Code Playgroud)
是的,我知道从工作中返回价值是不错的主意,但我希望这是可能的.但是$ this-> dispatch()只返回排队的作业ID,而不是handle方法的结果.
TL; DR:如何从排队的作业中返回数据,而不将其保存在任何地方,即使它在队列中有多次尝试?如果乔布斯不适合这个,也许有人知道其他方法.任何建议将被认真考虑.
提前致谢!
我有中间件将任务放入队列,将$ actionName和GET/POST参数传递给Job构造函数.这段代码:
$actionName = last(explode('@', $request->route()->getActionName()));
$arguments = $request->query->all();
$job = new HandleApiRequest($actionName, $arguments);
dispatch($job);
Run Code Online (Sandbox Code Playgroud)
然后,在Job处理程序中,我想用传递的参数调用Controller方法(在Job构造函数中初始化的参数,不要担心).这是一个代码:
$data = app()->call(ApiController::class . '@' . $this->method, $this->arguments);
Run Code Online (Sandbox Code Playgroud)
问题是,我不能在被叫Controller和它的服务中使用Request对象(Illuminate\Http\Request).看起来像控制器进入无限循环,在它服务它只是空.然后我在worker中看到这个登录控制台:
[Illuminate\Contracts\Container\BindingResolutionException]
Target [App\Http\Requests\Request] is not instantiable while building [App\Http\Controllers\Api\ApiController].
Run Code Online (Sandbox Code Playgroud)
问题是,如何在Job处理程序中正确初始化Request对象?
谢谢!