93 lines
2.4 KiB
PHP
93 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Client;
|
|
|
|
use App\Models\Service;
|
|
use App\Models\XmlInco;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
use Tests\CreatesApplication;
|
|
use UWIL\Flucollector\FlucollectorApi;
|
|
|
|
abstract class ClientTester extends BaseTestCase
|
|
{
|
|
use CreatesApplication;
|
|
|
|
/** @var \App\Models\ArcadiaBrand */
|
|
protected static $brand;
|
|
|
|
/** @var \App\Models\Service */
|
|
protected static $service;
|
|
|
|
/** @var \App\Models\XmlInco */
|
|
protected static $xml_inco;
|
|
|
|
/**
|
|
* Setup the test environment.
|
|
*
|
|
* @return void
|
|
* @throws \ErrorException If env is not testing.
|
|
*/
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
if (!self::$xml_inco) {
|
|
\extract($this->getXmlInco());
|
|
/** @var \App\Models\Service $service */
|
|
/** @var \App\Models\ArcadiaBrand $brand */
|
|
/** @var \App\Models\XmlInco $xml_inco */
|
|
self::$service = $service;
|
|
self::$brand = $brand;
|
|
self::$xml_inco = $xml_inco;
|
|
}
|
|
new FlucollectorApi(
|
|
config('app.url'),
|
|
self::$service->bearer_token,
|
|
Crypt::decryptString(self::$service->bearer_pwd)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get a Service
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getService(): array
|
|
{
|
|
/** @var \App\Models\Service */
|
|
$service = Service::query()->whereHas('arcadiaBrand.xmlIncos')
|
|
->with('arcadiaBrand')->firstOrFail();
|
|
/** @var \App\Models\ArcadiaBrand */
|
|
$brand = $service->arcadiaBrand;
|
|
|
|
return compact('service', 'brand');
|
|
}
|
|
|
|
/**
|
|
* Get a Service
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getXmlInco(): array
|
|
{
|
|
/** @var \App\Models\XmlInco */
|
|
$xml_inco = XmlInco::query()->whereHas('arcadiaBrand.services')->inRandomOrder()->firstOrFail();
|
|
/** @var \App\Models\ArcadiaBrand */
|
|
$brand = $xml_inco->arcadiaBrand;
|
|
/** @var \App\Models\Service */
|
|
$service = $brand->services()->firstOrFail();
|
|
|
|
return compact('service', 'brand', 'xml_inco');
|
|
}
|
|
|
|
/**
|
|
* Parse routes.json and return routes list
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getClientRoutes(): array
|
|
{
|
|
return \json_decode(\file_get_contents(__DIR__ . '/../../../client/src/routes.json'), true);
|
|
}
|
|
}
|