Тестовый пример в моем приложении PHP / Laravel случайно не проходит. Похоже, у него своя жизнь.
Сбой теста со следующими ошибками:
Undefined index: impressions
*
и * 1006
Trying to get property 'ad' of non-object
Файл проверен:
class AdReportController extends Controller
{
/** @var CampaignGroupRepository */
private $campaignGroupRepo;
/** @var AdWordsAccountRepository */
private $adWordsAccountRepo;
/** @var AdReportRepository */
private $adReportRepo;
public function __construct(
CampaignGroupRepository $campaignGroupRepo,
AdWordsAccountRepository $adWordsAccountRepo,
AdReportRepository $adReportRepo
) {
$this->campaignGroupRepo = $campaignGroupRepo;
$this->adReportRepo = $adReportRepo;
$this->adWordsAccountRepo = $adWordsAccountRepo;
$this->setTransformer(new AdReportTransformer());
}
public function top(AdReportsRequest $request, int $accountId): JsonResponse
{
$campaignGroup = $request->input('campaign_group');
$dateFrom = $request->input('from');
$dateTo = $request->input('to');
$adWordsAccount = $this->adWordsAccountRepo->findOrFailByGoogleId($accountId);
$campaignGroup = $this->campaignGroupRepo->findOrFail($campaignGroup, $adWordsAccount);
$report = $this->adReportRepo->top($campaignGroup, $dateFrom, $dateTo);
return $this->response($report);
}
}
Контрольный пример для ошибки показа:
public function testIgnoreReportsFromOtherCampaignGroups(): void
{
[$account, $campaignGroup, $ad] = $this->createEverything();
$top = $this->createAdReport([
'date' => '2019-01-01',
'ad' => $ad,
'impressions' => 100,
'clickThroughRate' => 100,
]);
[, , $ad2] = $this->createEverything($account);
$this->createAdReport([
'date' => '2019-01-01',
'ad' => $ad2,
'impressions' => 300,
'clickThroughRate' => 150,
]);
$params = http_build_query([
'campaign_group' => $campaignGroup->id,
'from' => '2018-12-30',
'to' => '2019-01-06',
]);
$remote = $this->callIt($account, $params)->json();
$this->assertSame($remote['impressions'], $top->impressions);
}
Контрольный пример для другой ошибки:
public function testIgnoreReportsFromOtherAccounts(): void
{
[$account, $campaignGroup, $ad] = $this->createEverything();
$top = $this->createAdReport([
'date' => '2019-01-01',
'ad' => $ad,
'impressions' => 100,
'clickThroughRate' => 100,
]);
[, , $ad2] = $this->createEverything();
$this->createAdReport([
'date' => '2019-01-01',
'ad' => $ad2,
'impressions' => 300,
'clickThroughRate' => 150,
]);
$params = http_build_query([
'campaign_group' => $campaignGroup->id,
'from' => '2018-12-30',
'to' => '2019-01-06',
]);
$remote = $this->callIt($account, $params)->json();
$this->assertSame($remote['impressions'], $top->impressions);
}
Невозможно выяснить, почему эти тесты дают сбой и случайным образом. Я могу запускаться 20 раз без сбоев, затем сбоев.