From 6ca2fe17791d723ea0385a429a1df6c35f0b7b85 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Thu, 17 Apr 2025 11:32:43 +0200 Subject: [PATCH] fix: :art: improve methods prototype --- .../Controllers/Api/V4/StatsController.php | 2 +- .../Requests/Api/V2/GetBrandStatsRequest.php | 2 +- .../Api/V2/GetQuestionStatsRequest.php | 2 +- .../Requests/Api/V4/GetBrandStatsRequest.php | 4 +- .../Api/V4/GetQuestionStatsRequest.php | 2 +- app/Http/Resources/Api/V2/ApiResponse.php | 4 +- .../Api/V4/QuestionStatsResource.php | 2 +- app/Models/Question.php | 4 +- composer.json | 2 +- tests/CRM/ApiV2/ApiBase.php | 11 +- tests/CRM/ApiV2/ApiTest.php | 34 ++-- tests/CRM/ApiV2/ArcadiaTest.php | 60 +++---- tests/CRM/ApiV2/CustomerTest.php | 166 +++++++++--------- tests/CRM/ApiV2/QuestionTest.php | 16 +- tests/CRM/ApiV2/SingleOptinTest.php | 48 ++--- tests/CRM/ApiV2/StatsTest.php | 28 +-- tests/CRM/ApiV4/ApiBase.php | 19 +- tests/CRM/ApiV4/ApiTest.php | 38 ++-- tests/CRM/ApiV4/ArcadiaTest.php | 58 +++--- tests/CRM/ApiV4/CustomerTest.php | 158 ++++++++--------- tests/CRM/ApiV4/QuestionTest.php | 16 +- tests/CRM/ApiV4/SingleOptinTest.php | 48 ++--- tests/CRM/ApiV4/StatsTest.php | 30 ++-- tests/CreatesApplication.php | 2 +- tests/StressTest/RunMultipleRequestsTest.php | 12 +- 25 files changed, 388 insertions(+), 380 deletions(-) diff --git a/app/Http/Controllers/Api/V4/StatsController.php b/app/Http/Controllers/Api/V4/StatsController.php index ae36f79..c741c8e 100644 --- a/app/Http/Controllers/Api/V4/StatsController.php +++ b/app/Http/Controllers/Api/V4/StatsController.php @@ -70,7 +70,7 @@ class StatsController extends Controller ->whereIn('answer_id', $answers->pluck('id')) ->get()->map(function ($custAnswer) { return [ - 'answer_id' => $custAnswer->answer_id, + 'answer_id' => $custAnswer->answer_id, 'created_at' => $custAnswer->created_at->isoFormat('YYYY-MM-DD'), ]; })->groupBy(['created_at', 'answer_id'])->map(function ($day) { diff --git a/app/Http/Requests/Api/V2/GetBrandStatsRequest.php b/app/Http/Requests/Api/V2/GetBrandStatsRequest.php index 5f11348..4dcccbf 100644 --- a/app/Http/Requests/Api/V2/GetBrandStatsRequest.php +++ b/app/Http/Requests/Api/V2/GetBrandStatsRequest.php @@ -36,7 +36,7 @@ class GetBrandStatsRequest extends BaseApiRequest throw $e; } return [ - 'start' => 'required|date|date_format:Y-m-d', + 'start' => 'required|date|date_format:Y-m-d|before_or_equal:end', 'end' => 'required|date|date_format:Y-m-d|after_or_equal:start', ]; } diff --git a/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php b/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php index d1764c8..4434152 100644 --- a/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php +++ b/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php @@ -37,7 +37,7 @@ class GetQuestionStatsRequest extends BaseApiRequest throw $e; } return [ - 'start' => 'required|date|date_format:Y-m-d', + 'start' => 'required|date|date_format:Y-m-d|before_or_equal:end', 'end' => 'required|date|date_format:Y-m-d|after_or_equal:start', ]; } diff --git a/app/Http/Requests/Api/V4/GetBrandStatsRequest.php b/app/Http/Requests/Api/V4/GetBrandStatsRequest.php index 72ab257..e69d30b 100644 --- a/app/Http/Requests/Api/V4/GetBrandStatsRequest.php +++ b/app/Http/Requests/Api/V4/GetBrandStatsRequest.php @@ -27,13 +27,13 @@ class GetBrandStatsRequest extends BaseApiRequest } catch (\Exception $e) { if (\get_class($e) !== ValidationException::class) { throw ValidationException::withMessages([ - 'Les dates séléectionnées ne sembles pas être valides' + 'Les dates sélectionnées ne sembles pas être valides' ]); } throw $e; } return [ - 'start' => 'required|date|date_format:Y-m-d', + 'start' => 'required|date|date_format:Y-m-d|before_or_equal:end', 'end' => 'required|date|date_format:Y-m-d|after_or_equal:start', ]; } diff --git a/app/Http/Requests/Api/V4/GetQuestionStatsRequest.php b/app/Http/Requests/Api/V4/GetQuestionStatsRequest.php index d469c21..43b9fd5 100644 --- a/app/Http/Requests/Api/V4/GetQuestionStatsRequest.php +++ b/app/Http/Requests/Api/V4/GetQuestionStatsRequest.php @@ -33,7 +33,7 @@ class GetQuestionStatsRequest extends BaseApiRequest throw $e; } return [ - 'start' => 'required|date|date_format:Y-m-d', + 'start' => 'required|date|date_format:Y-m-d|before_or_equal:end', 'end' => 'required|date|date_format:Y-m-d|after_or_equal:start', ]; } diff --git a/app/Http/Resources/Api/V2/ApiResponse.php b/app/Http/Resources/Api/V2/ApiResponse.php index df4778b..3d60a62 100644 --- a/app/Http/Resources/Api/V2/ApiResponse.php +++ b/app/Http/Resources/Api/V2/ApiResponse.php @@ -36,8 +36,8 @@ class ApiResponse extends JsonResource { //phpcs:enable return [ - 'status' => $this->status->value(), - 'data' => (array)($this->data ?? []), + 'status' => $this->status->value(), + 'data' => (array)($this->data ?? []), 'version' => '3.0.6' ]; } diff --git a/app/Http/Resources/Api/V4/QuestionStatsResource.php b/app/Http/Resources/Api/V4/QuestionStatsResource.php index f210551..b01ead1 100644 --- a/app/Http/Resources/Api/V4/QuestionStatsResource.php +++ b/app/Http/Resources/Api/V4/QuestionStatsResource.php @@ -37,7 +37,7 @@ class QuestionStatsResource extends JsonResourceCollection //phpcs:enable return [ 'answers' => (new AnswersResource($this->question->answers))->toArray($request), - 'stats' => $this->collection->toArray() + 'stats' => $this->collection->toArray() ]; } } diff --git a/app/Models/Question.php b/app/Models/Question.php index 581dc98..c52efad 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -15,8 +15,8 @@ use Illuminate\Database\Eloquent\Model; * @property-read \Illuminate\Support\Carbon $created_at Created date. * @property-read \Illuminate\Support\Carbon $updated_at Updated date. * - * @property-read \App\Models\Answer $answers Answer hasMany relation. - * @property-read \App\Models\Brand $brand Brand BelongsTo relation. + * @property-read \Illuminate\Support\Collection $answers Answer hasMany relation. + * @property-read \App\Models\Brand $brand Brand BelongsTo relation. */ class Question extends Model { diff --git a/composer.json b/composer.json index d5ff9f1..fa60577 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "ldc/ldccrm", - "version": "4.0.8", + "version": "4.0.9", "type": "project", "description": "LDC CRM", "license": "MIT", diff --git a/tests/CRM/ApiV2/ApiBase.php b/tests/CRM/ApiV2/ApiBase.php index 2ce58cd..e11c4fa 100644 --- a/tests/CRM/ApiV2/ApiBase.php +++ b/tests/CRM/ApiV2/ApiBase.php @@ -10,7 +10,6 @@ use App\Models\Service; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Testing\AssertableJsonString; -use Illuminate\Testing\TestResponse; use Tests\CreatesApplication; class ApiBase extends BaseTestCase @@ -39,8 +38,12 @@ class ApiBase extends BaseTestCase * @param array $headers * @return \Illuminate\Testing\TestResponse */ - protected function callApi(string $method, string $uri, array $data = [], array $headers = []): TestResponse - { + protected function callApi( + string $method, + string $uri, + array $data = [], + array $headers = [] + ): \Illuminate\Testing\TestResponse { if (!isset($data['timestamp'])) { $data['timestamp'] = \time(); } @@ -63,7 +66,7 @@ class ApiBase extends BaseTestCase string $uri, array $data = [], array $headers = [] - ): TestResponse { + ): \Illuminate\Testing\TestResponse { $data['bearer_token'] = $service->bearer_token; $data['timestamp'] = \gmdate('Y-m-d H:i:s'); diff --git a/tests/CRM/ApiV2/ApiTest.php b/tests/CRM/ApiV2/ApiTest.php index 751008b..d8a3dfa 100644 --- a/tests/CRM/ApiV2/ApiTest.php +++ b/tests/CRM/ApiV2/ApiTest.php @@ -15,11 +15,11 @@ class ApiTest extends ApiBase use DatabaseTransactions; /** - * Test ApiV2 only handle json calls + * Test ApiV2 only handle json calls. * * @return void */ - public function testOnlyJsonCallsAreHandled() + public function testOnlyJsonCallsAreHandled(): void { $response = $this->call('get', route('apiV2.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s') @@ -32,7 +32,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddleware() + public function testTimestampMiddleware(): void { $response = $this->json('get', route('apiV2.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s') @@ -46,7 +46,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddlewareCheckFailMissing() + public function testTimestampMiddlewareCheckFailMissing(): void { $response = $this->json('get', route('apiV2.ping'), []); $json = $response->decodeResponseJson(); @@ -62,7 +62,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddlewareCheckFailWrongFormat() + public function testTimestampMiddlewareCheckFailWrongFormat(): void { $response = $this->json('get', route('apiV2.ping'), ['timestamp' => \gmdate('Y/m/d')]); $json = $response->decodeResponseJson(); @@ -78,7 +78,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddlewareCheckFailIfTooOld() + public function testTimestampMiddlewareCheckFailIfTooOld(): void { $response = $this->json('get', route('apiV2.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s', \time() - config('api.timestampTimeout', 10)) @@ -98,7 +98,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testApiThrottle() + public function testApiThrottle(): void { for ($i = config('api.apiRequestRatePerMinute', 100); $i >= 0; $i--) { $this->json('get', route('apiV2.ping'), [ @@ -115,11 +115,11 @@ class ApiTest extends ApiBase } /** - * Test wrong http method call + * Test wrong http method call. * * @return void */ - public function testWrongMethodCall() + public function testWrongMethodCall(): void { $response = $this->json('post', route('apiV2.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s', \time()) @@ -130,11 +130,11 @@ class ApiTest extends ApiBase } /** - * Test Auth fail when no token + * Test Auth fail when no token. * * @return void */ - public function testAuthFailNoToken() + public function testAuthFailNoToken(): void { $response = $this->json('get', route('apiV2.customers.show', [ 'serviceCustomer' => Str::uuid() @@ -147,11 +147,11 @@ class ApiTest extends ApiBase } /** - * Test Auth fail when unknown token + * Test Auth fail when unknown token. * * @return void */ - public function testAuthFailUnknownToken() + public function testAuthFailUnknownToken(): void { $response = $this->json('get', route('apiV2.customers.show', [ 'serviceCustomer' => Str::uuid() @@ -165,19 +165,19 @@ class ApiTest extends ApiBase } /** - * Test Auth fail when wrong signature + * Test Auth fail when wrong signature. * * @return void */ - public function testAuthFailWrongSignature() + public function testAuthFailWrongSignature(): void { $service = Service::query()->firstOrFail(); $response = $this->json('get', route('apiV2.customers.show', [ 'serviceCustomer' => Str::uuid() ]), [ 'bearer_token' => $service->bearer_token, - 'timestamp' => \gmdate('Y-m-d H:i:s', \time()), - 'signature' => 'sdqdqsdqd' + 'timestamp' => \gmdate('Y-m-d H:i:s', \time()), + 'signature' => 'sdqdqsdqd' ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::KO); diff --git a/tests/CRM/ApiV2/ArcadiaTest.php b/tests/CRM/ApiV2/ArcadiaTest.php index 28fbf12..d8e530f 100644 --- a/tests/CRM/ApiV2/ArcadiaTest.php +++ b/tests/CRM/ApiV2/ArcadiaTest.php @@ -19,27 +19,27 @@ class ArcadiaTest extends ApiBase * * @return void */ - public function testArcadiaSendOrderDefault() + public function testArcadiaSendOrderDefault(): void { extract($this->getCustomer()); $data = [ - 'deliver' => [ - 'email' => $customer->email, + 'deliver' => [ + 'email' => $customer->email, 'firstname' => $info->firstname, - 'lastname' => $info->lastname, - 'phone' => $info->phone, - 'address' => $info->address, - 'address2' => $info->address2, - 'city' => $info->city, - 'postcode' => $info->postcode, + 'lastname' => $info->lastname, + 'phone' => $info->phone, + 'address' => $info->address, + 'address2' => $info->address2, + 'city' => $info->city, + 'postcode' => $info->postcode, ], - 'operation' => 16, - 'label_type_support' => 'Send Departaimants', - 'order_date' => \date('Y/m/d H:i:s'), - 'state_order' => ArcadiaOrderType::cb->value(), - 'support_code' => 1, - 'label_type_support' => 'Fond carte Aimanté', - 'order_num' => 23, + 'operation' => 16, + 'label_type_support' => 'Send Departaimants', + 'order_date' => \date('Y/m/d H:i:s'), + 'state_order' => ArcadiaOrderType::cb->value(), + 'support_code' => 1, + 'label_type_support' => 'Fond carte Aimanté', + 'order_num' => 23, 'package_unit_weight' => 0, ]; $response = $this->callApiWithToken($service, 'post', route( @@ -56,26 +56,26 @@ class ArcadiaTest extends ApiBase * * @return void */ - public function testArcadiaSendOrderGame() + public function testArcadiaSendOrderGame(): void { extract($this->getCustomer()); $data = [ - 'deliver' => [ - 'email' => $customer->email, + 'deliver' => [ + 'email' => $customer->email, 'firstname' => $info->firstname, - 'lastname' => $info->lastname, - 'phone' => $info->phone, - 'address' => $info->address, - 'address2' => $info->address2, - 'city' => $info->city, - 'postcode' => $info->postcode, + 'lastname' => $info->lastname, + 'phone' => $info->phone, + 'address' => $info->address, + 'address2' => $info->address2, + 'city' => $info->city, + 'postcode' => $info->postcode, ], - 'operation' => 16, - 'order_date' => date('Y/m/d H:i:s'), - 'support_code' => 32, + 'operation' => 16, + 'order_date' => date('Y/m/d H:i:s'), + 'support_code' => 32, 'label_type_support' => 'Jeux Reghalal', - 'code_unique' => \strtoupper(\str_replace('-', '', (string)Str::uuid())), - 'code_on_pack' => '2563547' + 'code_unique' => \strtoupper(\str_replace('-', '', (string)Str::uuid())), + 'code_on_pack' => '2563547' ]; $response = $this->callApiWithToken($service, 'post', route( 'apiV2.arcadia.outgoingMailGame', diff --git a/tests/CRM/ApiV2/CustomerTest.php b/tests/CRM/ApiV2/CustomerTest.php index 8d5825c..c23a006 100644 --- a/tests/CRM/ApiV2/CustomerTest.php +++ b/tests/CRM/ApiV2/CustomerTest.php @@ -21,11 +21,11 @@ class CustomerTest extends ApiBase use DatabaseTransactions; /** - * Test Customer relations to its related models + * Test Customer relations to its related models. * * @return void */ - public function testCustomerRelations() + public function testCustomerRelations(): void { extract($this->getCustomer()); $infos = $customer->infos; @@ -46,7 +46,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldWork() + public function testApiAuthenticateCustomerShouldWork(): void { extract($this->getCustomer(true)); @@ -58,7 +58,7 @@ class CustomerTest extends ApiBase 'post', route('apiV2.customers.authenticate', []), [ - 'email' => $customer->email, + 'email' => $customer->email, 'password' => 'testPassword' ] ); @@ -84,7 +84,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldFailIfWrongPassword() + public function testApiAuthenticateCustomerShouldFailIfWrongPassword(): void { extract($this->getCustomer()); $response = $this->callApiWithToken( @@ -92,7 +92,7 @@ class CustomerTest extends ApiBase 'post', route('apiV2.customers.authenticate', []), [ - 'email' => $customer->email, + 'email' => $customer->email, 'password' => 'azdqdqdazd' ] ); @@ -113,7 +113,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldFailIfWrongEmail() + public function testApiAuthenticateCustomerShouldFailIfWrongEmail(): void { extract($this->getCustomer()); $response = $this->callApiWithToken( @@ -121,7 +121,7 @@ class CustomerTest extends ApiBase 'post', route('apiV2.customers.authenticate', []), [ - 'email' => 'wrongemail@hotmail.fr', + 'email' => 'wrongemail@hotmail.fr', 'password' => 'azdqdqdazd' ] ); @@ -142,7 +142,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldFailIfCustomerNotActivated() + public function testApiAuthenticateCustomerShouldFailIfCustomerNotActivated(): void { $login = CustomerLogin::query()->where('status', false)->firstOrFail(); /** @var \App\Models\Brand $brand */ @@ -156,7 +156,7 @@ class CustomerTest extends ApiBase 'post', route('apiV2.customers.authenticate', []), [ - 'email' => $customer->email, + 'email' => $customer->email, 'password' => 'testPassword' ] ); @@ -172,12 +172,12 @@ class CustomerTest extends ApiBase } /** - * Customer store ok + * Customer store ok. * route: apiV2.customers.store * * @return void */ - public function testApiStoreCustomerOk() + public function testApiStoreCustomerOk(): void { extract($this->getCustomer()); @@ -230,22 +230,22 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiStoreCustomerShouldFailIfCustomerAlreadyExists() + public function testApiStoreCustomerShouldFailIfCustomerAlreadyExists(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean', - 'lastname' => 'Bond', + 'firstname' => 'Jean', + 'lastname' => 'Bond', 'birth_date' => \date('1992-03-08'), - 'address' => '10 rue des toto', - 'email' => 'newcustomer@hotmail.fr', - 'password' => '123.Mot.De.P4sse', - 'phone' => '+33654821562', - 'country' => Country::france->value(), - 'city' => 'Connerré', - 'postcode' => '72160', - 'opt_in' => true + 'address' => '10 rue des toto', + 'email' => 'newcustomer@hotmail.fr', + 'password' => '123.Mot.De.P4sse', + 'phone' => '+33654821562', + 'country' => Country::france->value(), + 'city' => 'Connerré', + 'postcode' => '72160', + 'opt_in' => true ]; $this->createNewCustomer($data, $brand); @@ -259,26 +259,26 @@ class CustomerTest extends ApiBase } /** - * Customer store validationFailures + * Customer store validationFailures. * route: apiV2.customers.store * * @return void */ - public function testApiStoreCustomerValidationFailures() + public function testApiStoreCustomerValidationFailures(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean', - 'lastname' => 'Bond', + 'firstname' => 'Jean', + 'lastname' => 'Bond', 'birth_date' => \date('1992-03-08'), - 'address' => '10 rue des toto', - 'email' => 'newcustomer.failures@hotmail.fr', - 'password' => '123.Mot.De.P4sse', - 'phone' => '+33654821562', - 'country' => Country::france->value(), - 'city' => 'Connerré', - 'postcode' => '72160', - 'opt_in' => true + 'address' => '10 rue des toto', + 'email' => 'newcustomer.failures@hotmail.fr', + 'password' => '123.Mot.De.P4sse', + 'phone' => '+33654821562', + 'country' => Country::france->value(), + 'city' => 'Connerré', + 'postcode' => '72160', + 'opt_in' => true ]; $sendData = $data; @@ -343,12 +343,12 @@ class CustomerTest extends ApiBase } /** - * Test activate customer ok + * Test activate customer ok. * route: apiV2.customers.activate * * @return void */ - public function testActivateCustomerOk() + public function testActivateCustomerOk(): void { extract($this->getCustomer(false)); @@ -364,12 +364,12 @@ class CustomerTest extends ApiBase } /** - * Test activate customer already activated + * Test activate customer already activated. * route: apiV2.customers.activate * * @return void */ - public function testActivateCustomerAlreadyActivated() + public function testActivateCustomerAlreadyActivated(): void { extract($this->getCustomer(true)); @@ -387,40 +387,40 @@ class CustomerTest extends ApiBase } /** - * Test customer update ok + * Test customer update ok. * route: apiV2.customers.update * * @return void */ - public function testApiUpdateCustomerOk() + public function testApiUpdateCustomerOk(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean2', - 'lastname' => 'Bond2', + 'firstname' => 'Jean2', + 'lastname' => 'Bond2', 'birth_date' => \date('1992-03-09'), - 'address' => '10 rue des toto', - 'email' => 'newcustomertoupdate@hotmail.fr', - 'password' => '123.Mot.De.P4sseNew', - 'phone' => '+33654821563', - 'country' => Country::luxembourg->value(), - 'city' => 'Connerré2', - 'postcode' => '72161', - 'opt_in' => 0 + 'address' => '10 rue des toto', + 'email' => 'newcustomertoupdate@hotmail.fr', + 'password' => '123.Mot.De.P4sseNew', + 'phone' => '+33654821563', + 'country' => Country::luxembourg->value(), + 'city' => 'Connerré2', + 'postcode' => '72161', + 'opt_in' => 0 ]; $newdata = [ - 'firstname' => 'Jean3', - 'lastname' => 'Bond3', + 'firstname' => 'Jean3', + 'lastname' => 'Bond3', 'birth_date' => \date('1992-03-07'), - 'address' => '10 rue des toto3', - 'email' => 'newcustomertoupdate3@hotmail.fr', - 'password' => '123.Mot.De.P4sseNew3', - 'phone' => '+33654821564', - 'country' => Country::france->value(), - 'city' => 'Connerré3', - 'postcode' => '72163', - 'opt_in' => 1 + 'address' => '10 rue des toto3', + 'email' => 'newcustomertoupdate3@hotmail.fr', + 'password' => '123.Mot.De.P4sseNew3', + 'phone' => '+33654821564', + 'country' => Country::france->value(), + 'city' => 'Connerré3', + 'postcode' => '72163', + 'opt_in' => 1 ]; $this->createNewCustomer($data, $brand); @@ -460,26 +460,26 @@ class CustomerTest extends ApiBase } /** - * Test customer update should fail if no changes are provided + * Test customer update should fail if no changes are provided. * route: apiV2.customers.update * * @return void */ - public function testApiUpdateCustomerShouldFailWhenNothingChanges() + public function testApiUpdateCustomerShouldFailWhenNothingChanges(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean2', - 'lastname' => 'Bond2', + 'firstname' => 'Jean2', + 'lastname' => 'Bond2', 'birth_date' => \date('1992-03-09'), - 'address' => '10 rue des toto', - 'email' => 'anewcustomertoupdate@hotmail.fr', - 'password' => '123.Mot.De.P4sseNew', - 'phone' => '+33654821563', - 'country' => Country::luxembourg->value(), - 'city' => 'Connerré2', - 'postcode' => '72161', - 'opt_in' => 0 + 'address' => '10 rue des toto', + 'email' => 'anewcustomertoupdate@hotmail.fr', + 'password' => '123.Mot.De.P4sseNew', + 'phone' => '+33654821563', + 'country' => Country::luxembourg->value(), + 'city' => 'Connerré2', + 'postcode' => '72161', + 'opt_in' => 0 ]; $this->createNewCustomer($data, $brand); @@ -494,12 +494,12 @@ class CustomerTest extends ApiBase } /** - * Test customer show ok + * Test customer show ok. * route: apiV2.customers.show * * @return void */ - public function testApiGetCustomerOk() + public function testApiGetCustomerOk(): void { extract($this->getCustomer()); @@ -522,12 +522,12 @@ class CustomerTest extends ApiBase } /** - * Test customer show using email ok + * Test customer show using email ok. * route: apiV2.customers.show * * @return void */ - public function testApiGetCustomerByEmailOk() + public function testApiGetCustomerByEmailOk(): void { extract($this->getCustomer()); @@ -550,12 +550,12 @@ class CustomerTest extends ApiBase } /** - * Test customer show not found + * Test customer show not found. * route: apiV2.customers.show * * @return void */ - public function testApiGetCustomerNotFound() + public function testApiGetCustomerNotFound(): void { extract($this->getCustomer()); $csClassName = \array_slice(explode('\\', get_class($customer)), -1)[0]; @@ -587,7 +587,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiDestroyCustomer() + public function testApiDestroyCustomer(): void { extract($this->getCustomer()); $csClassName = \array_slice(explode('\\', get_class($customer)), -1)[0]; @@ -620,7 +620,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiCompletelyDestroyCustomer() + public function testApiCompletelyDestroyCustomer(): void { $customer = Customer::whereHas('logins', null, '>', 1)->firstOrFail(); @@ -672,13 +672,13 @@ class CustomerTest extends ApiBase } /** - * Make sute a customer exists and contains data + * Make sute a customer exists and contains data. * * @param array $data * @param \App\Models\Brand $brand * @return void */ - private function createNewCustomer(array $data, Brand $brand) + private function createNewCustomer(array $data, Brand $brand): void { $customer = Customer::whereEmail($data['email']) ->whereHas('brands', function ($q) use ($brand) { diff --git a/tests/CRM/ApiV2/QuestionTest.php b/tests/CRM/ApiV2/QuestionTest.php index 85185b7..63930eb 100644 --- a/tests/CRM/ApiV2/QuestionTest.php +++ b/tests/CRM/ApiV2/QuestionTest.php @@ -16,7 +16,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionIndex() + public function testQuestionIndex(): void { extract($this->getCustomer()); @@ -66,7 +66,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionIndexWithAnswers() + public function testQuestionIndexWithAnswers(): void { extract($this->getCustomer(true, false)); @@ -141,7 +141,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionIndexWithAnswersWhenCustomerNotFound() + public function testQuestionIndexWithAnswersWhenCustomerNotFound(): void { extract($this->getCustomer(true, false)); $service = Service::whereHas('brand', function ($q) use ($brand) { @@ -162,7 +162,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testCustomerUnAnsweredIndex() + public function testCustomerUnAnsweredIndex(): void { extract($this->getCustomer(true, false)); @@ -237,7 +237,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testUnAnsweredIndexWhenCustomerNotFound() + public function testUnAnsweredIndexWhenCustomerNotFound(): void { extract($this->getCustomer(true, false)); $service = Service::whereHas('brand', function ($q) use ($brand) { @@ -258,7 +258,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionSetAnswer() + public function testQuestionSetAnswer(): void { extract($this->getCustomer(true, false)); $question = Question::whereHas('brand', function ($q) use ($brand) { @@ -275,7 +275,7 @@ class QuestionTest extends ApiBase ['serviceCustomer' => $info->hashcode] ), [ 'question' => $question->id, - 'answers' => [$answer->id] + 'answers' => [$answer->id] ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK); @@ -293,7 +293,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionSetAnswerWhenCustomerNotFound() + public function testQuestionSetAnswerWhenCustomerNotFound(): void { extract($this->getCustomer(true, false)); $service = Service::whereHas('brand', function ($q) use ($brand) { diff --git a/tests/CRM/ApiV2/SingleOptinTest.php b/tests/CRM/ApiV2/SingleOptinTest.php index 73528a2..5c8517b 100644 --- a/tests/CRM/ApiV2/SingleOptinTest.php +++ b/tests/CRM/ApiV2/SingleOptinTest.php @@ -16,17 +16,17 @@ class SingleOptinTest extends ApiBase use DatabaseTransactions; /** - * Test set single optin on + * Test set single optin on. * route: apiV2.optin * * @return void */ - public function testSetSingleOptinOn() + public function testSetSingleOptinOn(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [ - 'email' => 'singleoptin@hotmail.fr', + 'email' => 'singleoptin@hotmail.fr', 'opt_in' => 1 ]); $json = $response->decodeResponseJson(); @@ -38,17 +38,17 @@ class SingleOptinTest extends ApiBase } /** - * Test set single optin off + * Test set single optin off. * route: apiV2.optin * * @return void */ - public function testSetSingleOptinOff() + public function testSetSingleOptinOff(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [ - 'email' => 'singleoptin@hotmail.fr', + 'email' => 'singleoptin@hotmail.fr', 'opt_in' => 0 ]); $json = $response->decodeResponseJson(); @@ -65,7 +65,7 @@ class SingleOptinTest extends ApiBase * * @return void */ - public function testSingleOptinShouldFailIfCustomerExists() + public function testSingleOptinShouldFailIfCustomerExists(): void { $service = Service::firstOrFail(); $this->storeCustomer($service); @@ -77,7 +77,7 @@ class SingleOptinTest extends ApiBase $singleOptin->saveOrFail(); $response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [ - 'email' => 'singleoptin@hotmail.fr', + 'email' => 'singleoptin@hotmail.fr', 'opt_in' => 1 ]); @@ -88,12 +88,12 @@ class SingleOptinTest extends ApiBase } /** - * Test set single optin off using hashcode + * Test set single optin off using hashcode. * route: apiV2.optout-hashcode * * @return void */ - public function testSetSingleOptoutWithHashcode() + public function testSetSingleOptoutWithHashcode(): void { $service = Service::firstOrFail(); @@ -116,12 +116,12 @@ class SingleOptinTest extends ApiBase } /** - * Test set single optin off using hashcode fails if does not exists + * Test set single optin off using hashcode fails if does not exists. * route: apiV2.optout-hashcode * * @return void */ - public function testSetSingleOptoutWithHashcodeFailsIfDoesNotExists() + public function testSetSingleOptoutWithHashcodeFailsIfDoesNotExists(): void { $service = Service::firstOrFail(); @@ -144,25 +144,25 @@ class SingleOptinTest extends ApiBase } /** - * Store a customer in DB + * Store a customer in DB. * * @param \App\Models\Service $service * @return void */ - private function storeCustomer(Service $service) + private function storeCustomer(Service $service): void { $data = [ - 'firstname' => 'Jean', - 'lastname' => 'Bond', + 'firstname' => 'Jean', + 'lastname' => 'Bond', 'birth_date' => \date('1992-03-08'), - 'address' => '10 rue des totos', - 'email' => 'singleoptin@hotmail.fr', - 'password' => '123.Mot.De.P4sse', - 'phone' => '+33654821562', - 'country' => Country::france->value(), - 'city' => 'Connerré', - 'postcode' => '72160', - 'opt_in' => true + 'address' => '10 rue des totos', + 'email' => 'singleoptin@hotmail.fr', + 'password' => '123.Mot.De.P4sse', + 'phone' => '+33654821562', + 'country' => Country::france->value(), + 'city' => 'Connerré', + 'postcode' => '72160', + 'opt_in' => true ]; $this->callApiWithToken($service, 'post', route('apiV2.customers.store'), $data); } diff --git a/tests/CRM/ApiV2/StatsTest.php b/tests/CRM/ApiV2/StatsTest.php index b40273f..097e1a3 100644 --- a/tests/CRM/ApiV2/StatsTest.php +++ b/tests/CRM/ApiV2/StatsTest.php @@ -23,13 +23,13 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByBrand() + public function testStatsByBrand(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.brandStats'), [ 'start' => Carbon::now()->subMonths(3)->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -57,13 +57,13 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByBrandShouldFailWithInvalidDate() + public function testStatsByBrandShouldFailWithInvalidDate(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.brandStats'), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -77,13 +77,13 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByBrandShouldFailWithInvalidDateFormat() + public function testStatsByBrandShouldFailWithInvalidDateFormat(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.brandStats'), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD HH:mmDD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -97,7 +97,7 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestion() + public function testStatsByQuestion(): void { $service = Service::firstOrFail(); $question = Question::whereBrandId($service->brand->id)->firstOrFail(); @@ -116,7 +116,7 @@ class StatsTest extends ApiBase $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.questionStats', $question), [ 'start' => $start->isoFormat('YYYY-MM-DD'), - 'end' => $end->isoFormat('YYYY-MM-DD') + 'end' => $end->isoFormat('YYYY-MM-DD') ]); $datesIndexes = []; @@ -150,14 +150,14 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestionShouldFailWithInvalidQuestion() + public function testStatsByQuestionShouldFailWithInvalidQuestion(): void { $service = Service::firstOrFail(); $question = Question::where('brand_id', '!=', $service->brand->id)->firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.questionStats', $question), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -171,14 +171,14 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestionShouldFailWithInvalidDate() + public function testStatsByQuestionShouldFailWithInvalidDate(): void { $service = Service::firstOrFail(); $question = Question::whereBrandId($service->brand->id)->firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.questionStats', $question), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -192,14 +192,14 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestionShouldFailWithInvalidDateFormat() + public function testStatsByQuestionShouldFailWithInvalidDateFormat(): void { $service = Service::firstOrFail(); $question = Question::whereBrandId($service->brand->id)->firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV2.stats.questionStats', $question), [ 'start' => Carbon::now()->subMonths(3)->isoFormat('YYYY-MM Ddh'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); diff --git a/tests/CRM/ApiV4/ApiBase.php b/tests/CRM/ApiV4/ApiBase.php index 33fc6eb..b52ce6c 100644 --- a/tests/CRM/ApiV4/ApiBase.php +++ b/tests/CRM/ApiV4/ApiBase.php @@ -10,7 +10,6 @@ use App\Models\Service; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use Illuminate\Testing\AssertableJsonString; -use Illuminate\Testing\TestResponse; use Tests\CreatesApplication; class ApiBase extends BaseTestCase @@ -25,13 +24,13 @@ class ApiBase extends BaseTestCase * @param \App\Enums\ApiStatus $status * @return void */ - protected function assertApiResponseStatusIs(AssertableJsonString $json, ApiStatus $status) + protected function assertApiResponseStatusIs(AssertableJsonString $json, ApiStatus $status): void { $json->assertFragment(['status' => $status->value]); } /** - * Raw Function to call api + * Raw Function to call api. * * @param string $method * @param string $uri @@ -39,8 +38,12 @@ class ApiBase extends BaseTestCase * @param array $headers * @return \Illuminate\Testing\TestResponse */ - protected function callApi(string $method, string $uri, array $data = [], array $headers = []): TestResponse - { + protected function callApi( + string $method, + string $uri, + array $data = [], + array $headers = [] + ): \Illuminate\Testing\TestResponse { if (!isset($data['timestamp'])) { $data['timestamp'] = \time(); } @@ -48,7 +51,7 @@ class ApiBase extends BaseTestCase } /** - * Raw Function to call api with Token + * Raw Function to call api with Token. * * @param \App\Models\Service $service * @param string $method @@ -63,7 +66,7 @@ class ApiBase extends BaseTestCase string $uri, array $data = [], array $headers = [] - ): TestResponse { + ): \Illuminate\Testing\TestResponse { $data['bearer_token'] = $service->bearer_token; $data['timestamp'] = \gmdate('Y-m-d H:i:s'); @@ -78,7 +81,7 @@ class ApiBase extends BaseTestCase } /** - * Get Customer models with given status (active or not) + * Get Customer models with given status (active or not). * * @param boolean $status The customer status for a brand. * @param boolean $random Randomize the customer to get. diff --git a/tests/CRM/ApiV4/ApiTest.php b/tests/CRM/ApiV4/ApiTest.php index 82a5c4c..b7bb989 100644 --- a/tests/CRM/ApiV4/ApiTest.php +++ b/tests/CRM/ApiV4/ApiTest.php @@ -19,7 +19,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testOnlyJsonCallsAreHandled() + public function testOnlyJsonCallsAreHandled(): void { $response = $this->call('get', route('apiV4.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s') @@ -32,7 +32,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddleware() + public function testTimestampMiddleware(): void { $response = $this->json('get', route('apiV4.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s') @@ -46,13 +46,13 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddlewareCheckFailMissing() + public function testTimestampMiddlewareCheckFailMissing(): void { $response = $this->json('get', route('apiV4.ping'), []); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::KO); $json->assertFragment(['data' => [ - 'code' => ApiError::wrongTimeStamp->value(), + 'code' => ApiError::wrongTimeStamp->value(), 'message' => ApiError::wrongTimeStamp->label() ]]); } @@ -62,13 +62,13 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddlewareCheckFailWrongFormat() + public function testTimestampMiddlewareCheckFailWrongFormat(): void { $response = $this->json('get', route('apiV4.ping'), ['timestamp' => \gmdate('Y/m/d')]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::KO); $json->assertFragment(['data' => [ - 'code' => ApiError::wrongTimeStamp->value(), + 'code' => ApiError::wrongTimeStamp->value(), 'message' => ApiError::wrongTimeStamp->label() ]]); } @@ -78,7 +78,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testTimestampMiddlewareCheckFailIfTooOld() + public function testTimestampMiddlewareCheckFailIfTooOld(): void { $response = $this->json('get', route('apiV4.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s', \time() - config('api.timestampTimeout', 10)) @@ -98,7 +98,7 @@ class ApiTest extends ApiBase * * @return void */ - public function testApiThrottle() + public function testApiThrottle(): void { for ($i = config('api.apiRequestRatePerMinute', 100); $i >= 0; $i--) { $this->json('get', route('apiV4.ping'), [ @@ -115,11 +115,11 @@ class ApiTest extends ApiBase } /** - * Test wrong http method call + * Test wrong http method call. * * @return void */ - public function testWrongMethodCall() + public function testWrongMethodCall(): void { $response = $this->json('post', route('apiV4.ping'), [ 'timestamp' => \gmdate('Y-m-d H:i:s', \time()) @@ -130,11 +130,11 @@ class ApiTest extends ApiBase } /** - * Test Auth fail when no token + * Test Auth fail when no token. * * @return void */ - public function testAuthFailNoToken() + public function testAuthFailNoToken(): void { $response = $this->json('get', route('apiV4.customers.show', [ 'serviceCustomer' => Str::uuid() @@ -147,17 +147,17 @@ class ApiTest extends ApiBase } /** - * Test Auth fail when unknown token + * Test Auth fail when unknown token. * * @return void */ - public function testAuthFailUnknownToken() + public function testAuthFailUnknownToken(): void { $response = $this->json('get', route('apiV4.customers.show', [ 'serviceCustomer' => Str::uuid() ]), [ 'bearer_token' => 'qsdqsdqsd', - 'timestamp' => \gmdate('Y-m-d H:i:s', \time()) + 'timestamp' => \gmdate('Y-m-d H:i:s', \time()) ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::KO); @@ -165,19 +165,19 @@ class ApiTest extends ApiBase } /** - * Test Auth fail when wrong signature + * Test Auth fail when wrong signature. * * @return void */ - public function testAuthFailWrongSignature() + public function testAuthFailWrongSignature(): void { $service = Service::query()->firstOrFail(); $response = $this->json('get', route('apiV4.customers.show', [ 'serviceCustomer' => Str::uuid() ]), [ 'bearer_token' => $service->bearer_token, - 'timestamp' => \gmdate('Y-m-d H:i:s', \time()), - 'signature' => 'sdqdqsdqd' + 'timestamp' => \gmdate('Y-m-d H:i:s', \time()), + 'signature' => 'sdqdqsdqd' ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::KO); diff --git a/tests/CRM/ApiV4/ArcadiaTest.php b/tests/CRM/ApiV4/ArcadiaTest.php index 0b9f9c1..c781959 100644 --- a/tests/CRM/ApiV4/ArcadiaTest.php +++ b/tests/CRM/ApiV4/ArcadiaTest.php @@ -19,27 +19,27 @@ class ArcadiaTest extends ApiBase * * @return void */ - public function testArcadiaSendOrderDefault() + public function testArcadiaSendOrderDefault(): void { extract($this->getCustomer()); $data = [ 'deliver' => [ - 'email' => $customer->email, + 'email' => $customer->email, 'firstname' => $info->firstname, - 'lastname' => $info->lastname, - 'phone' => $info->phone, - 'address' => $info->address, - 'address2' => $info->address2, - 'city' => $info->city, - 'postcode' => $info->postcode, + 'lastname' => $info->lastname, + 'phone' => $info->phone, + 'address' => $info->address, + 'address2' => $info->address2, + 'city' => $info->city, + 'postcode' => $info->postcode, ], - 'operation' => 16, - 'label_type_support' => 'Send Departaimants', - 'order_date' => \date('Y/m/d H:i:s'), - 'state_order' => ArcadiaOrderType::cb->value, - 'support_code' => 1, - 'label_type_support' => 'Fond carte Aimanté', - 'order_num' => 23, + 'operation' => 16, + 'label_type_support' => 'Send Departaimants', + 'order_date' => \date('Y/m/d H:i:s'), + 'state_order' => ArcadiaOrderType::cb->value, + 'support_code' => 1, + 'label_type_support' => 'Fond carte Aimanté', + 'order_num' => 23, 'package_unit_weight' => 0, ]; $response = $this->callApiWithToken($service, 'post', route( @@ -56,26 +56,26 @@ class ArcadiaTest extends ApiBase * * @return void */ - public function testArcadiaSendOrderGame() + public function testArcadiaSendOrderGame(): void { extract($this->getCustomer()); $data = [ - 'deliver' => [ - 'email' => $customer->email, + 'deliver' => [ + 'email' => $customer->email, 'firstname' => $info->firstname, - 'lastname' => $info->lastname, - 'phone' => $info->phone, - 'address' => $info->address, - 'address2' => $info->address2, - 'city' => $info->city, - 'postcode' => $info->postcode, + 'lastname' => $info->lastname, + 'phone' => $info->phone, + 'address' => $info->address, + 'address2' => $info->address2, + 'city' => $info->city, + 'postcode' => $info->postcode, ], - 'operation' => 16, - 'order_date' => date('Y/m/d H:i:s'), - 'support_code' => 32, + 'operation' => 16, + 'order_date' => date('Y/m/d H:i:s'), + 'support_code' => 32, 'label_type_support' => 'Jeux Reghalal', - 'code_unique' => \strtoupper(\str_replace('-', '', (string)Str::uuid())), - 'code_on_pack' => '2563547' + 'code_unique' => \strtoupper(\str_replace('-', '', (string)Str::uuid())), + 'code_on_pack' => '2563547' ]; $response = $this->callApiWithToken($service, 'post', route( 'apiV4.arcadia.outgoingMailGame', diff --git a/tests/CRM/ApiV4/CustomerTest.php b/tests/CRM/ApiV4/CustomerTest.php index 0c74a45..6bbe7c6 100644 --- a/tests/CRM/ApiV4/CustomerTest.php +++ b/tests/CRM/ApiV4/CustomerTest.php @@ -25,7 +25,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testCustomerRelations() + public function testCustomerRelations(): void { extract($this->getCustomer()); $infos = $customer->infos; @@ -46,7 +46,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldWork() + public function testApiAuthenticateCustomerShouldWork(): void { extract($this->getCustomer(true)); @@ -58,7 +58,7 @@ class CustomerTest extends ApiBase 'post', route('apiV4.customers.authenticate', []), [ - 'email' => $customer->email, + 'email' => $customer->email, 'password' => 'testPassword' ] ); @@ -84,7 +84,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldFailIfWrongPassword() + public function testApiAuthenticateCustomerShouldFailIfWrongPassword(): void { extract($this->getCustomer()); $response = $this->callApiWithToken( @@ -92,7 +92,7 @@ class CustomerTest extends ApiBase 'post', route('apiV4.customers.authenticate', []), [ - 'email' => $customer->email, + 'email' => $customer->email, 'password' => 'azdqdqdazd' ] ); @@ -113,7 +113,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldFailIfWrongEmail() + public function testApiAuthenticateCustomerShouldFailIfWrongEmail(): void { extract($this->getCustomer()); $response = $this->callApiWithToken( @@ -121,7 +121,7 @@ class CustomerTest extends ApiBase 'post', route('apiV4.customers.authenticate', []), [ - 'email' => 'wrongemail@hotmail.fr', + 'email' => 'wrongemail@hotmail.fr', 'password' => 'azdqdqdazd' ] ); @@ -142,7 +142,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiAuthenticateCustomerShouldFailIfCustomerNotActivated() + public function testApiAuthenticateCustomerShouldFailIfCustomerNotActivated(): void { $login = CustomerLogin::query()->where('status', false)->firstOrFail(); /** @var \App\Models\Brand $brand */ @@ -177,7 +177,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiStoreCustomerOk() + public function testApiStoreCustomerOk(): void { extract($this->getCustomer()); @@ -230,22 +230,22 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiStoreCustomerShouldFailIfCustomerAlreadyExists() + public function testApiStoreCustomerShouldFailIfCustomerAlreadyExists(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean', - 'lastname' => 'Bond', + 'firstname' => 'Jean', + 'lastname' => 'Bond', 'birth_date' => \date('1992-03-08'), - 'address' => '10 rue des toto', - 'email' => 'newcustomer@hotmail.fr', - 'password' => '123.Mot.De.P4sse', - 'phone' => '+33654821562', - 'country' => Country::france->value(), - 'city' => 'Connerré', - 'postcode' => '72160', - 'opt_in' => true + 'address' => '10 rue des toto', + 'email' => 'newcustomer@hotmail.fr', + 'password' => '123.Mot.De.P4sse', + 'phone' => '+33654821562', + 'country' => Country::france->value(), + 'city' => 'Connerré', + 'postcode' => '72160', + 'opt_in' => true ]; $this->createNewCustomer($data, $brand); @@ -264,21 +264,21 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiStoreCustomerValidationFailures() + public function testApiStoreCustomerValidationFailures(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean', - 'lastname' => 'Bond', + 'firstname' => 'Jean', + 'lastname' => 'Bond', 'birth_date' => \date('1992-03-08'), - 'address' => '10 rue des toto', - 'email' => 'newcustomer.failures@hotmail.fr', - 'password' => '123.Mot.De.P4sse', - 'phone' => '+33654821562', - 'country' => Country::france->value(), - 'city' => 'Connerré', - 'postcode' => '72160', - 'opt_in' => true + 'address' => '10 rue des toto', + 'email' => 'newcustomer.failures@hotmail.fr', + 'password' => '123.Mot.De.P4sse', + 'phone' => '+33654821562', + 'country' => Country::france->value(), + 'city' => 'Connerré', + 'postcode' => '72160', + 'opt_in' => true ]; $sendData = $data; @@ -343,12 +343,12 @@ class CustomerTest extends ApiBase } /** - * Test activate customer ok + * Test activate customer ok. * route: apiV4.customers.activate * * @return void */ - public function testActivateCustomerOk() + public function testActivateCustomerOk(): void { extract($this->getCustomer(false)); @@ -364,12 +364,12 @@ class CustomerTest extends ApiBase } /** - * Test activate customer already activated + * Test activate customer already activated. * route: apiV4.customers.activate * * @return void */ - public function testActivateCustomerAlreadyActivated() + public function testActivateCustomerAlreadyActivated(): void { extract($this->getCustomer(true)); @@ -387,40 +387,40 @@ class CustomerTest extends ApiBase } /** - * Test customer update ok + * Test customer update ok. * route: apiV4.customers.update * * @return void */ - public function testApiUpdateCustomerOk() + public function testApiUpdateCustomerOk(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean2', - 'lastname' => 'Bond2', + 'firstname' => 'Jean2', + 'lastname' => 'Bond2', 'birth_date' => \date('1992-03-09'), - 'address' => '10 rue des toto', - 'email' => 'newcustomertoupdate@hotmail.fr', - 'password' => '123.Mot.De.P4sseNew', - 'phone' => '+33654821563', - 'country' => Country::luxembourg->value(), - 'city' => 'Connerré2', - 'postcode' => '72161', - 'opt_in' => 0 + 'address' => '10 rue des toto', + 'email' => 'newcustomertoupdate@hotmail.fr', + 'password' => '123.Mot.De.P4sseNew', + 'phone' => '+33654821563', + 'country' => Country::luxembourg->value(), + 'city' => 'Connerré2', + 'postcode' => '72161', + 'opt_in' => 0 ]; $newdata = [ - 'firstname' => 'Jean3', - 'lastname' => 'Bond3', + 'firstname' => 'Jean3', + 'lastname' => 'Bond3', 'birth_date' => \date('1992-03-07'), - 'address' => '10 rue des toto3', - 'email' => 'newcustomertoupdate3@hotmail.fr', - 'password' => '123.Mot.De.P4sseNew3', - 'phone' => '+33654821564', - 'country' => Country::france->value(), - 'city' => 'Connerré3', - 'postcode' => '72163', - 'opt_in' => 1 + 'address' => '10 rue des toto3', + 'email' => 'newcustomertoupdate3@hotmail.fr', + 'password' => '123.Mot.De.P4sseNew3', + 'phone' => '+33654821564', + 'country' => Country::france->value(), + 'city' => 'Connerré3', + 'postcode' => '72163', + 'opt_in' => 1 ]; $this->createNewCustomer($data, $brand); @@ -460,26 +460,26 @@ class CustomerTest extends ApiBase } /** - * Test customer update should fail if no changes are provided + * Test customer update should fail if no changes are provided. * route: apiV4.customers.update * * @return void */ - public function testApiUpdateCustomerShouldFailWhenNothingChanges() + public function testApiUpdateCustomerShouldFailWhenNothingChanges(): void { extract($this->getCustomer()); $data = [ - 'firstname' => 'Jean2', - 'lastname' => 'Bond2', + 'firstname' => 'Jean2', + 'lastname' => 'Bond2', 'birth_date' => \date('1992-03-09'), - 'address' => '10 rue des toto', - 'email' => 'anewcustomertoupdate@hotmail.fr', - 'password' => '123.Mot.De.P4sseNew', - 'phone' => '+33654821563', - 'country' => Country::luxembourg->value(), - 'city' => 'Connerré2', - 'postcode' => '72161', - 'opt_in' => 0 + 'address' => '10 rue des toto', + 'email' => 'anewcustomertoupdate@hotmail.fr', + 'password' => '123.Mot.De.P4sseNew', + 'phone' => '+33654821563', + 'country' => Country::luxembourg->value(), + 'city' => 'Connerré2', + 'postcode' => '72161', + 'opt_in' => 0 ]; $this->createNewCustomer($data, $brand); @@ -494,12 +494,12 @@ class CustomerTest extends ApiBase } /** - * Test customer show ok + * Test customer show ok. * route: apiV4.customers.show * * @return void */ - public function testApiGetCustomerOk() + public function testApiGetCustomerOk(): void { extract($this->getCustomer()); @@ -522,12 +522,12 @@ class CustomerTest extends ApiBase } /** - * Test customer show using email ok + * Test customer show using email ok. * route: apiV4.customers.show * * @return void */ - public function testApiGetCustomerByEmailOk() + public function testApiGetCustomerByEmailOk(): void { extract($this->getCustomer()); @@ -550,12 +550,12 @@ class CustomerTest extends ApiBase } /** - * Test customer show not found + * Test customer show not found. * route: apiV4.customers.show * * @return void */ - public function testApiGetCustomerNotFound() + public function testApiGetCustomerNotFound(): void { extract($this->getCustomer()); $csClassName = \array_slice(explode('\\', get_class($customer)), -1)[0]; @@ -587,7 +587,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiDestroyCustomer() + public function testApiDestroyCustomer(): void { extract($this->getCustomer()); $csClassName = \array_slice(explode('\\', get_class($customer)), -1)[0]; @@ -620,7 +620,7 @@ class CustomerTest extends ApiBase * * @return void */ - public function testApiCompletelyDestroyCustomer() + public function testApiCompletelyDestroyCustomer(): void { $customer = Customer::whereHas('logins', null, '>', 1)->firstOrFail(); @@ -672,13 +672,13 @@ class CustomerTest extends ApiBase } /** - * Make sute a customer exists and contains data + * Make sute a customer exists and contains data. * * @param array $data * @param \App\Models\Brand $brand * @return void */ - private function createNewCustomer(array $data, Brand $brand) + private function createNewCustomer(array $data, Brand $brand): void { $customer = Customer::whereEmail($data['email']) ->whereHas('brands', function ($q) use ($brand) { diff --git a/tests/CRM/ApiV4/QuestionTest.php b/tests/CRM/ApiV4/QuestionTest.php index 85c54e7..3106502 100644 --- a/tests/CRM/ApiV4/QuestionTest.php +++ b/tests/CRM/ApiV4/QuestionTest.php @@ -16,7 +16,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionIndex() + public function testQuestionIndex(): void { extract($this->getCustomer()); @@ -66,7 +66,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionIndexWithAnswers() + public function testQuestionIndexWithAnswers(): void { extract($this->getCustomer(true, false)); @@ -141,7 +141,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionIndexWithAnswersWhenCustomerNotFound() + public function testQuestionIndexWithAnswersWhenCustomerNotFound(): void { extract($this->getCustomer(true, false)); $service = Service::whereHas('brand', function ($q) use ($brand) { @@ -162,7 +162,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testCustomerUnAnsweredIndex() + public function testCustomerUnAnsweredIndex(): void { extract($this->getCustomer(true, false)); @@ -237,7 +237,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testUnAnsweredIndexWhenCustomerNotFound() + public function testUnAnsweredIndexWhenCustomerNotFound(): void { extract($this->getCustomer(true, false)); $service = Service::whereHas('brand', function ($q) use ($brand) { @@ -258,7 +258,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionSetAnswer() + public function testQuestionSetAnswer(): void { extract($this->getCustomer(true, false)); $question = Question::whereHas('brand', function ($q) use ($brand) { @@ -275,7 +275,7 @@ class QuestionTest extends ApiBase ['serviceCustomer' => $info->hashcode] ), [ 'question' => $question->id, - 'answers' => [$answer->id] + 'answers' => [$answer->id] ]); $json = $response->decodeResponseJson(); $this->assertApiResponseStatusIs($json, ApiStatus::OK); @@ -293,7 +293,7 @@ class QuestionTest extends ApiBase * * @return void */ - public function testQuestionSetAnswerWhenCustomerNotFound() + public function testQuestionSetAnswerWhenCustomerNotFound(): void { extract($this->getCustomer(true, false)); $service = Service::whereHas('brand', function ($q) use ($brand) { diff --git a/tests/CRM/ApiV4/SingleOptinTest.php b/tests/CRM/ApiV4/SingleOptinTest.php index e1ef010..b466bda 100644 --- a/tests/CRM/ApiV4/SingleOptinTest.php +++ b/tests/CRM/ApiV4/SingleOptinTest.php @@ -16,17 +16,17 @@ class SingleOptinTest extends ApiBase use DatabaseTransactions; /** - * Test set single optin on + * Test set single optin on. * route: apiV4.optin * * @return void */ - public function testSetSingleOptinOn() + public function testSetSingleOptinOn(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'post', route('apiV4.optin'), [ - 'email' => 'singleoptin@hotmail.fr', + 'email' => 'singleoptin@hotmail.fr', 'opt_in' => 1 ]); $json = $response->decodeResponseJson(); @@ -38,17 +38,17 @@ class SingleOptinTest extends ApiBase } /** - * Test set single optin off + * Test set single optin off. * route: apiV4.optin * * @return void */ - public function testSetSingleOptinOff() + public function testSetSingleOptinOff(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'post', route('apiV4.optin'), [ - 'email' => 'singleoptin@hotmail.fr', + 'email' => 'singleoptin@hotmail.fr', 'opt_in' => 0 ]); $json = $response->decodeResponseJson(); @@ -65,7 +65,7 @@ class SingleOptinTest extends ApiBase * * @return void */ - public function testSingleOptinShouldFailIfCustomerExists() + public function testSingleOptinShouldFailIfCustomerExists(): void { $service = Service::firstOrFail(); $this->storeCustomer($service); @@ -77,7 +77,7 @@ class SingleOptinTest extends ApiBase $singleOptin->saveOrFail(); $response = $this->callApiWithToken($service, 'post', route('apiV4.optin'), [ - 'email' => 'singleoptin@hotmail.fr', + 'email' => 'singleoptin@hotmail.fr', 'opt_in' => 1 ]); @@ -88,12 +88,12 @@ class SingleOptinTest extends ApiBase } /** - * Test set single optin off using hashcode + * Test set single optin off using hashcode. * route: apiV4.optout-hashcode * * @return void */ - public function testSetSingleOptoutWithHashcode() + public function testSetSingleOptoutWithHashcode(): void { $service = Service::firstOrFail(); @@ -116,12 +116,12 @@ class SingleOptinTest extends ApiBase } /** - * Test set single optin off using hashcode fails if does not exists + * Test set single optin off using hashcode fails if does not exists. * route: apiV4.optout-hashcode * * @return void */ - public function testSetSingleOptoutWithHashcodeFailsIfDoesNotExists() + public function testSetSingleOptoutWithHashcodeFailsIfDoesNotExists(): void { $service = Service::firstOrFail(); @@ -144,25 +144,25 @@ class SingleOptinTest extends ApiBase } /** - * Store a customer in DB + * Store a customer in DB. * * @param \App\Models\Service $service * @return void */ - private function storeCustomer(Service $service) + private function storeCustomer(Service $service): void { $data = [ - 'firstname' => 'Jean', - 'lastname' => 'Bond', + 'firstname' => 'Jean', + 'lastname' => 'Bond', 'birth_date' => \date('1992-03-08'), - 'address' => '10 rue des totos', - 'email' => 'singleoptin@hotmail.fr', - 'password' => '123.Mot.De.P4sse', - 'phone' => '+33654821562', - 'country' => Country::france->value, - 'city' => 'Connerré', - 'postcode' => '72160', - 'opt_in' => true + 'address' => '10 rue des totos', + 'email' => 'singleoptin@hotmail.fr', + 'password' => '123.Mot.De.P4sse', + 'phone' => '+33654821562', + 'country' => Country::france->value, + 'city' => 'Connerré', + 'postcode' => '72160', + 'opt_in' => true ]; $this->callApiWithToken($service, 'post', route('apiV4.customers.store'), $data); } diff --git a/tests/CRM/ApiV4/StatsTest.php b/tests/CRM/ApiV4/StatsTest.php index bc2ef0b..d2f5c3a 100644 --- a/tests/CRM/ApiV4/StatsTest.php +++ b/tests/CRM/ApiV4/StatsTest.php @@ -23,13 +23,13 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByBrand() + public function testStatsByBrand(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV4.stats.brandStats'), [ 'start' => Carbon::now()->subMonths(3)->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -57,13 +57,13 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByBrandShouldFailWithInvalidDate() + public function testStatsByBrandShouldFailWithInvalidDate(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV4.stats.brandStats'), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -77,13 +77,13 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByBrandShouldFailWithInvalidDateFormat() + public function testStatsByBrandShouldFailWithInvalidDateFormat(): void { $service = Service::firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV4.stats.brandStats'), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD HH:mmDD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -97,7 +97,7 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestion() + public function testStatsByQuestion(): void { $service = Service::firstOrFail(); $question = Question::whereBrandId($service->brand->id)->firstOrFail(); @@ -116,7 +116,7 @@ class StatsTest extends ApiBase $response = $this->callApiWithToken($service, 'get', route('apiV4.stats.questionStats', $question), [ 'start' => $start->isoFormat('YYYY-MM-DD'), - 'end' => $end->isoFormat('YYYY-MM-DD') + 'end' => $end->isoFormat('YYYY-MM-DD') ]); $datesIndexes = []; @@ -139,7 +139,7 @@ class StatsTest extends ApiBase 'answer' ] ], - 'stats' => $datesIndexes + 'stats' => $datesIndexes ] ]); } @@ -150,14 +150,14 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestionShouldFailWithInvalidQuestion() + public function testStatsByQuestionShouldFailWithInvalidQuestion(): void { $service = Service::firstOrFail(); $question = Question::where('brand_id', '!=', $service->brand->id)->firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV4.stats.questionStats', $question), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -171,14 +171,14 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestionShouldFailWithInvalidDate() + public function testStatsByQuestionShouldFailWithInvalidDate(): void { $service = Service::firstOrFail(); $question = Question::whereBrandId($service->brand->id)->firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV4.stats.questionStats', $question), [ 'start' => Carbon::now()->subMonths(3)->subDay()->isoFormat('YYYY-MM-DD'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); @@ -192,14 +192,14 @@ class StatsTest extends ApiBase * * @return void */ - public function testStatsByQuestionShouldFailWithInvalidDateFormat() + public function testStatsByQuestionShouldFailWithInvalidDateFormat(): void { $service = Service::firstOrFail(); $question = Question::whereBrandId($service->brand->id)->firstOrFail(); $response = $this->callApiWithToken($service, 'get', route('apiV4.stats.questionStats', $question), [ 'start' => Carbon::now()->subMonths(3)->isoFormat('YYYY-MM Ddh'), - 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') + 'end' => Carbon::now()->isoFormat('YYYY-MM-DD') ]); $json = $response->decodeResponseJson(); diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index ab92402..e4c5d32 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -11,7 +11,7 @@ trait CreatesApplication * * @return \Illuminate\Foundation\Application */ - public function createApplication() + public function createApplication(): \Illuminate\Foundation\Application { $app = require __DIR__ . '/../bootstrap/app.php'; diff --git a/tests/StressTest/RunMultipleRequestsTest.php b/tests/StressTest/RunMultipleRequestsTest.php index 52de2ac..b72077c 100644 --- a/tests/StressTest/RunMultipleRequestsTest.php +++ b/tests/StressTest/RunMultipleRequestsTest.php @@ -54,7 +54,7 @@ class RunMultipleRequestsTest extends TestCase * * @return void */ - public function testSpamSingleOptin() + public function testSpamSingleOptin(): void { for ($i = 35; $i >= 0; $i--) { $this->assertTrue(SingleOptin::setStatus('singleoptinteststress@gmail.com', (bool)rand(0, 1))); @@ -66,7 +66,7 @@ class RunMultipleRequestsTest extends TestCase * * @return void */ - public function testSpamCustomerGet() + public function testSpamCustomerGet(): void { for ($i = 35; $i >= 0; $i--) { $this->assertIsObject(Customer::find(self::$info->hashcode)); @@ -78,7 +78,7 @@ class RunMultipleRequestsTest extends TestCase * * @return void */ - public function testSpamQuestionsGet() + public function testSpamQuestionsGet(): void { for ($i = 35; $i >= 0; $i--) { $this->assertIsArray(Question::all()); @@ -90,7 +90,7 @@ class RunMultipleRequestsTest extends TestCase * * @return void */ - public function testSpamCustomerGets() + public function testSpamCustomerGets(): void { for ($i = 35; $i >= 0; $i--) { $this->assertIsObject(Customer::findWithEmail(self::$customer->email)); @@ -98,10 +98,12 @@ class RunMultipleRequestsTest extends TestCase } /** + * Get a customer. + * * @param boolean $status * @return array */ - protected static function getCustomer(bool $status = true) + protected static function getCustomer(bool $status = true): array { /** @var \App\Models\Costumer $customer */ $customer = ModelsCustomer::whereHas('logins', function ($q) use ($status) {