From 3d18ab2819b24bbe379378a2cce3a9b8bd922a1a Mon Sep 17 00:00:00 2001 From: Peter Csajtai Date: Mon, 24 Feb 2025 10:58:17 +0100 Subject: [PATCH] Fix PHP CS Fixer errors (#50) --- src/ConfigCatClient.php | 26 +-- src/ConfigFetcher.php | 16 +- src/RolloutEvaluator.php | 34 ++-- tests/ConfigCatClientTest.php | 36 ++-- tests/ConfigV2EvaluationTests.php | 284 +++++++++++++++--------------- tests/EvaluationLogTest.php | 70 ++++---- tests/OverrideTest.php | 118 ++++++------- tests/RolloutIntegrationsTest.php | 20 +-- tests/UserTest.php | 44 ++--- tests/UtilsTest.php | 16 +- 10 files changed, 332 insertions(+), 332 deletions(-) diff --git a/src/ConfigCatClient.php b/src/ConfigCatClient.php index 7e6f262..32225ee 100644 --- a/src/ConfigCatClient.php +++ b/src/ConfigCatClient.php @@ -181,9 +181,9 @@ public function getValue(string $key, mixed $defaultValue, ?User $user = null): $settingsResult->fetchTime )->getValue(); } catch (Throwable $exception) { - $message = "Error occurred in the `getValue` method while evaluating setting '".$key."'. ". - 'Returning the `defaultValue` parameter that you specified '. - "in your application: '".Utils::getStringRepresentation($defaultValue)."'."; + $message = "Error occurred in the `getValue` method while evaluating setting '".$key."'. " + .'Returning the `defaultValue` parameter that you specified ' + ."in your application: '".Utils::getStringRepresentation($defaultValue)."'."; $messageCtx = [ 'event_id' => 1002, 'exception' => $exception, ]; @@ -228,9 +228,9 @@ public function getValueDetails(string $key, mixed $defaultValue, ?User $user = return $this->evaluate($key, $settingsResult->settings, $defaultValue, $user, $settingsResult->fetchTime); } catch (Throwable $exception) { - $message = "Error occurred in the `getValueDetails` method while evaluating setting '".$key."'. ". - 'Returning the `defaultValue` parameter that you specified in '. - "your application: '".Utils::getStringRepresentation($defaultValue)."'."; + $message = "Error occurred in the `getValueDetails` method while evaluating setting '".$key."'. " + .'Returning the `defaultValue` parameter that you specified in ' + ."your application: '".Utils::getStringRepresentation($defaultValue)."'."; $messageCtx = [ 'event_id' => 1002, 'exception' => $exception, ]; @@ -461,9 +461,9 @@ private function checkSettingsAvailable(SettingsResult $settingsResult, string $ private function checkSettingAvailable(SettingsResult $settingsResult, string $key, mixed $defaultValue): ?string { if (!$settingsResult->hasConfigJson) { - $message = "Config JSON is not present when evaluating setting '".$key."'. ". - 'Returning the `defaultValue` parameter that you specified in '. - "your application: '".Utils::getStringRepresentation($defaultValue)."'."; + $message = "Config JSON is not present when evaluating setting '".$key."'. " + .'Returning the `defaultValue` parameter that you specified in ' + ."your application: '".Utils::getStringRepresentation($defaultValue)."'."; $messageCtx = [ 'event_id' => 1000, ]; @@ -473,10 +473,10 @@ private function checkSettingAvailable(SettingsResult $settingsResult, string $k } if (!array_key_exists($key, $settingsResult->settings)) { - $message = "Failed to evaluate setting '".$key."' (the key was not found in config JSON). ". - 'Returning the `defaultValue` parameter that you specified in your '. - "application: '".Utils::getStringRepresentation($defaultValue)."'. ". - 'Available keys: ['.(!empty($settingsResult->settings) ? "'".implode("', '", array_keys($settingsResult->settings))."'" : '').'].'; + $message = "Failed to evaluate setting '".$key."' (the key was not found in config JSON). " + .'Returning the `defaultValue` parameter that you specified in your ' + ."application: '".Utils::getStringRepresentation($defaultValue)."'. " + .'Available keys: ['.(!empty($settingsResult->settings) ? "'".implode("', '", array_keys($settingsResult->settings))."'" : '').'].'; $messageCtx = [ 'event_id' => 1001, ]; diff --git a/src/ConfigFetcher.php b/src/ConfigFetcher.php index 7138395..76a088b 100644 --- a/src/ConfigFetcher.php +++ b/src/ConfigFetcher.php @@ -114,9 +114,9 @@ private function executeFetch(?string $etag, string $url, int $executionCount): if (RedirectMode::SHOULD == $redirect) { $this->logger->warning( - 'The `dataGovernance` parameter specified at the client initialization is '. - 'not in sync with the preferences on the ConfigCat Dashboard. '. - 'Read more: https://configcat.com/docs/advanced/data-governance/', + 'The `dataGovernance` parameter specified at the client initialization is ' + .'not in sync with the preferences on the ConfigCat Dashboard. ' + .'Read more: https://configcat.com/docs/advanced/data-governance/', [ 'event_id' => 3002, ] @@ -178,8 +178,8 @@ private function sendConfigFetchRequest(?string $etag, string $url): FetchRespon return FetchResponse::notModified(); } - $message = 'Your SDK Key seems to be wrong. You can find the valid SDK Key at https://app.configcat.com/sdkkey. '. - "Received unexpected response: {$statusCode}"; + $message = 'Your SDK Key seems to be wrong. You can find the valid SDK Key at https://app.configcat.com/sdkkey. ' + ."Received unexpected response: {$statusCode}"; $messageCtx = [ 'event_id' => 1100, ]; @@ -187,9 +187,9 @@ private function sendConfigFetchRequest(?string $etag, string $url): FetchRespon return FetchResponse::failure(InternalLogger::format($message, $messageCtx)); } catch (ClientExceptionInterface $exception) { - $message = 'Unexpected error occurred while trying to fetch config JSON. '. - 'It is most likely due to a local network issue. '. - 'Please make sure your application can reach the ConfigCat CDN servers (or your proxy server) over HTTP.'; + $message = 'Unexpected error occurred while trying to fetch config JSON. ' + .'It is most likely due to a local network issue. ' + .'Please make sure your application can reach the ConfigCat CDN servers (or your proxy server) over HTTP.'; $messageCtx = ['event_id' => 1103, 'exception' => $exception]; $this->logger->error($message, $messageCtx); diff --git a/src/RolloutEvaluator.php b/src/RolloutEvaluator.php index e156e8f..a37d591 100644 --- a/src/RolloutEvaluator.php +++ b/src/RolloutEvaluator.php @@ -1181,44 +1181,44 @@ private function getUserAttributeValueAsStringArray(string $attributeName, mixed private function logUserObjectIsMissing(string $key): void { - $this->logger->warning("Cannot evaluate targeting rules and % options for setting '{$key}' (User Object is missing). ". - 'You should pass a User Object to the evaluation methods like `getValue()` in order to make targeting work properly. '. - 'Read more: https://configcat.com/docs/advanced/user-object/', [ + $this->logger->warning("Cannot evaluate targeting rules and % options for setting '{$key}' (User Object is missing). " + .'You should pass a User Object to the evaluation methods like `getValue()` in order to make targeting work properly. ' + .'Read more: https://configcat.com/docs/advanced/user-object/', [ 'event_id' => 3001, ]); } private function logUserObjectAttributeIsMissingPercentage(string $key, string $attributeName): void { - $this->logger->warning("Cannot evaluate % options for setting '{$key}' (the User.{$attributeName} attribute is missing). ". - "You should set the User.{$attributeName} attribute in order to make targeting work properly. ". - 'Read more: https://configcat.com/docs/advanced/user-object/', [ + $this->logger->warning("Cannot evaluate % options for setting '{$key}' (the User.{$attributeName} attribute is missing). " + ."You should set the User.{$attributeName} attribute in order to make targeting work properly. " + .'Read more: https://configcat.com/docs/advanced/user-object/', [ 'event_id' => 3003, ]); } private function logUserObjectAttributeIsMissingCondition(string $condition, string $key, string $attributeName): void { - $this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' (the User.{$attributeName} attribute is missing). ". - "You should set the User.{$attributeName} attribute in order to make targeting work properly. ". - 'Read more: https://configcat.com/docs/advanced/user-object/', [ + $this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' (the User.{$attributeName} attribute is missing). " + ."You should set the User.{$attributeName} attribute in order to make targeting work properly. " + .'Read more: https://configcat.com/docs/advanced/user-object/', [ 'event_id' => 3003, ]); } private function logUserObjectAttributeIsInvalid(string $condition, string $key, string $reason, string $attributeName): void { - $this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' ({$reason}). ". - "Please check the User.{$attributeName} attribute and make sure that its value corresponds to the comparison operator.", [ + $this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' ({$reason}). " + ."Please check the User.{$attributeName} attribute and make sure that its value corresponds to the comparison operator.", [ 'event_id' => 3004, ]); } private function logUserObjectAttributeIsAutoConverted(string $condition, string $key, string $attributeName, string $attributeValue): void { - $this->logger->warning("Evaluation of condition ({$condition}) for setting '{$key}' may not produce the expected result ". - "(the User.{$attributeName} attribute is not a string value, thus it was automatically converted to the string value '{$attributeValue}'). ". - 'Please make sure that using a non-string value was intended.', [ + $this->logger->warning("Evaluation of condition ({$condition}) for setting '{$key}' may not produce the expected result " + ."(the User.{$attributeName} attribute is not a string value, thus it was automatically converted to the string value '{$attributeValue}'). " + .'Please make sure that using a non-string value was intended.', [ 'event_id' => 3005, ]); } @@ -1255,9 +1255,9 @@ private function checkDefaultValueTypeMismatch(mixed $returnValue, mixed $defaul $settingTypeName = $settingType->name; $defaultValueType = gettype($defaultValue); - $this->logger->warning("The type of a setting does not match the type of the specified default value ({$defaultValue}). ". - "Setting's type was {$settingTypeName} but the default value's type was {$defaultValueType}. ". - "Please make sure that using a default value not matching the setting's type was intended.", [ + $this->logger->warning("The type of a setting does not match the type of the specified default value ({$defaultValue}). " + ."Setting's type was {$settingTypeName} but the default value's type was {$defaultValueType}. " + ."Please make sure that using a default value not matching the setting's type was intended.", [ 'event_id' => 4002, ]); } diff --git a/tests/ConfigCatClientTest.php b/tests/ConfigCatClientTest.php index 4a380ca..8d2de0d 100644 --- a/tests/ConfigCatClientTest.php +++ b/tests/ConfigCatClientTest.php @@ -94,6 +94,24 @@ public function testConstructCacheRefreshIntervalOption() $this->assertSame(20, $propInterval); } + /** + * @dataProvider provideTestDataForSdkKeyFormat_ShouldBeValidated + */ + public function testSdkKeyFormatShouldBeValidated(string $sdkKey, bool $customBaseUrl, bool $isValid) + { + $clientOptions = $customBaseUrl + ? [ClientOptions::BASE_URL => 'https://my-configcat-proxy'] + : []; + + if (!$isValid) { + $this->expectException(InvalidArgumentException::class); + } else { + $this->expectNotToPerformAssertions(); + } + + $client = new ConfigCatClient($sdkKey, $clientOptions); + } + public function provideTestDataForSdkKeyFormat_ShouldBeValidated() { return Utils::withDescription([ @@ -119,24 +137,6 @@ public function provideTestDataForSdkKeyFormat_ShouldBeValidated() }); } - /** - * @dataProvider provideTestDataForSdkKeyFormat_ShouldBeValidated - */ - public function testSdkKeyFormatShouldBeValidated(string $sdkKey, bool $customBaseUrl, bool $isValid) - { - $clientOptions = $customBaseUrl - ? [ClientOptions::BASE_URL => 'https://my-configcat-proxy'] - : []; - - if (!$isValid) { - $this->expectException(InvalidArgumentException::class); - } else { - $this->expectNotToPerformAssertions(); - } - - $client = new ConfigCatClient($sdkKey, $clientOptions); - } - public function testGetValueFailedFetch() { $client = new ConfigCatClient('testGetValueFailedFetc/h-34567890123456789012', [ClientOptions::FETCH_CLIENT => GuzzleFetchClient::create([ diff --git a/tests/ConfigV2EvaluationTests.php b/tests/ConfigV2EvaluationTests.php index ad9352e..e98eb08 100644 --- a/tests/ConfigV2EvaluationTests.php +++ b/tests/ConfigV2EvaluationTests.php @@ -19,6 +19,30 @@ class ConfigV2EvaluationTests extends TestCase { private const TEST_DATA_ROOT_PATH = 'tests/data'; + /** + * @dataProvider provideTestDataForComparisonAttributeConversionToCanonicalStringRepresentation + */ + public function testComparisonAttributeConversionToCanonicalStringRepresentation(string $key, mixed $customAttributeValue, string $expectedReturnValue) + { + $clientOptions = [ + ClientOptions::FLAG_OVERRIDES => new FlagOverrides( + OverrideDataSource::localFile(self::TEST_DATA_ROOT_PATH.'/comparison_attribute_conversion.json'), + OverrideBehaviour::LOCAL_ONLY + ), + ]; + + $client = new ConfigCatClient('local-only', $clientOptions); + + $user = new User('12345', null, null, [ + 'Custom1' => $customAttributeValue, + ]); + + $defaultValue = 'default'; + $actualReturnValue = $client->getValue($key, $defaultValue, $user); + + $this->assertSame($expectedReturnValue, $actualReturnValue); + } + public function provideTestDataForComparisonAttributeConversionToCanonicalStringRepresentation(): array { return Utils::withDescription([ @@ -47,21 +71,23 @@ public function provideTestDataForComparisonAttributeConversionToCanonicalString } /** - * @dataProvider provideTestDataForComparisonAttributeConversionToCanonicalStringRepresentation + * @dataProvider provideTestDataForComparisonAttributeTrimming */ - public function testComparisonAttributeConversionToCanonicalStringRepresentation(string $key, mixed $customAttributeValue, string $expectedReturnValue) + public function testComparisonAttributeTrimming(string $key, string $expectedReturnValue) { $clientOptions = [ ClientOptions::FLAG_OVERRIDES => new FlagOverrides( - OverrideDataSource::localFile(self::TEST_DATA_ROOT_PATH.'/comparison_attribute_conversion.json'), + OverrideDataSource::localFile(self::TEST_DATA_ROOT_PATH.'/comparison_attribute_trimming.json'), OverrideBehaviour::LOCAL_ONLY ), ]; $client = new ConfigCatClient('local-only', $clientOptions); - $user = new User('12345', null, null, [ - 'Custom1' => $customAttributeValue, + $user = new User(' 12345 ', null, '[" USA "]', [ + 'Version' => ' 1.0.0 ', + 'Number' => ' 3 ', + 'Date' => ' 1705253400 ', ]); $defaultValue = 'default'; @@ -118,23 +144,23 @@ public function provideTestDataForComparisonAttributeTrimming(): array } /** - * @dataProvider provideTestDataForComparisonAttributeTrimming + * @dataProvider provideTestDataForComparisonValueTrimming */ - public function testComparisonAttributeTrimming(string $key, string $expectedReturnValue) + public function testComparisonValueTrimming(string $key, string $expectedReturnValue) { $clientOptions = [ ClientOptions::FLAG_OVERRIDES => new FlagOverrides( - OverrideDataSource::localFile(self::TEST_DATA_ROOT_PATH.'/comparison_attribute_trimming.json'), + OverrideDataSource::localFile(self::TEST_DATA_ROOT_PATH.'/comparison_value_trimming.json'), OverrideBehaviour::LOCAL_ONLY ), ]; $client = new ConfigCatClient('local-only', $clientOptions); - $user = new User(' 12345 ', null, '[" USA "]', [ - 'Version' => ' 1.0.0 ', - 'Number' => ' 3 ', - 'Date' => ' 1705253400 ', + $user = new User('12345', null, '["USA"]', [ + 'Version' => '1.0.0', + 'Number' => '3', + 'Date' => '1705253400', ]); $defaultValue = 'default'; @@ -180,32 +206,6 @@ public function provideTestDataForComparisonValueTrimming() }); } - /** - * @dataProvider provideTestDataForComparisonValueTrimming - */ - public function testComparisonValueTrimming(string $key, string $expectedReturnValue) - { - $clientOptions = [ - ClientOptions::FLAG_OVERRIDES => new FlagOverrides( - OverrideDataSource::localFile(self::TEST_DATA_ROOT_PATH.'/comparison_value_trimming.json'), - OverrideBehaviour::LOCAL_ONLY - ), - ]; - - $client = new ConfigCatClient('local-only', $clientOptions); - - $user = new User('12345', null, '["USA"]', [ - 'Version' => '1.0.0', - 'Number' => '3', - 'Date' => '1705253400', - ]); - - $defaultValue = 'default'; - $actualReturnValue = $client->getValue($key, $defaultValue, $user); - - $this->assertSame($expectedReturnValue, $actualReturnValue); - } - public function testUserObjectAttributeValueConversionTextComparisons() { $fakeLogger = new FakeLogger(); @@ -236,6 +236,30 @@ public function testUserObjectAttributeValueConversionTextComparisons() $this->assertSame("WARNING [3005] Evaluation of condition (User.{$customAttributeName} EQUALS '{$expectedAttributeValueText}') for setting '{$key}' may not produce the expected result (the User.{$customAttributeName} attribute is not a string value, thus it was automatically converted to the string value '{$expectedAttributeValueText}'). Please make sure that using a non-string value was intended.", $message); } + /** + * @dataProvider provideTestDataForUserObjectAttributeValueConversion_NonTextComparisons + */ + public function testUserObjectAttributeValueConversionNonTextComparisons( + string $sdkKey, + string $key, + ?string $userId, + string $customAttributeName, + mixed $customAttributeValue, + mixed $expectedReturnValue + ) { + $client = new ConfigCatClient($sdkKey); + + $user = isset($userId) + ? new User($userId, null, null, [ + $customAttributeName => $customAttributeValue, + ]) + : null; + + $evaluationDetails = $client->getValueDetails($key, null, $user); + + $this->assertSame($expectedReturnValue, $evaluationDetails->getValue()); + } + public function provideTestDataForUserObjectAttributeValueConversion_NonTextComparisons() { return Utils::withDescription([ @@ -328,41 +352,6 @@ public function provideTestDataForUserObjectAttributeValueConversion_NonTextComp }); } - /** - * @dataProvider provideTestDataForUserObjectAttributeValueConversion_NonTextComparisons - */ - public function testUserObjectAttributeValueConversionNonTextComparisons( - string $sdkKey, - string $key, - ?string $userId, - string $customAttributeName, - mixed $customAttributeValue, - mixed $expectedReturnValue - ) { - $client = new ConfigCatClient($sdkKey); - - $user = isset($userId) - ? new User($userId, null, null, [ - $customAttributeName => $customAttributeValue, - ]) - : null; - - $evaluationDetails = $client->getValueDetails($key, null, $user); - - $this->assertSame($expectedReturnValue, $evaluationDetails->getValue()); - } - - public function provideTestDataForPrerequisiteFlagCircularDependency() - { - return Utils::withDescription([ - ['key1', "'key1' -> 'key1'"], - ['key2', "'key2' -> 'key3' -> 'key2'"], - ['key4', "'key4' -> 'key3' -> 'key2' -> 'key3'"], - ], function ($testCase) { - return "key: {$testCase[0]} | dependencyCycle: {$testCase[1]}"; - }); - } - /** * @dataProvider provideTestDataForPrerequisiteFlagCircularDependency */ @@ -387,40 +376,14 @@ public function testPrerequisiteFlagCircularDependency(string $key, string $depe $this->assertStringContainsString($dependencyCycle, $exception->getMessage()); } - public function provideTestDataForPrerequisiteFlagComparisonValueTypeMismatch() + public function provideTestDataForPrerequisiteFlagCircularDependency() { - // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9e4e-4f59-86b2-5da50924b6ca/08dbc325-9ebd-4587-8171-88f76a3004cb return Utils::withDescription([ - ['stringDependsOnBool', 'mainBoolFlag', true, 'Dog'], - ['stringDependsOnBool', 'mainBoolFlag', false, 'Cat'], - ['stringDependsOnBool', 'mainBoolFlag', '1', null], - ['stringDependsOnBool', 'mainBoolFlag', 1, null], - ['stringDependsOnBool', 'mainBoolFlag', 1.0, null], - ['stringDependsOnBool', 'mainBoolFlag', [true], null], - ['stringDependsOnBool', 'mainBoolFlag', null, null], - ['stringDependsOnString', 'mainStringFlag', 'private', 'Dog'], - ['stringDependsOnString', 'mainStringFlag', 'Private', 'Cat'], - ['stringDependsOnString', 'mainStringFlag', true, null], - ['stringDependsOnString', 'mainStringFlag', 1, null], - ['stringDependsOnString', 'mainStringFlag', 1.0, null], - ['stringDependsOnString', 'mainStringFlag', ['private'], null], - ['stringDependsOnString', 'mainStringFlag', null, null], - ['stringDependsOnInt', 'mainIntFlag', 2, 'Dog'], - ['stringDependsOnInt', 'mainIntFlag', 1, 'Cat'], - ['stringDependsOnInt', 'mainIntFlag', '2', null], - ['stringDependsOnInt', 'mainIntFlag', true, null], - ['stringDependsOnInt', 'mainIntFlag', 2.0, null], - ['stringDependsOnInt', 'mainIntFlag', [2], null], - ['stringDependsOnInt', 'mainIntFlag', null, null], - ['stringDependsOnDouble', 'mainDoubleFlag', 0.1, 'Dog'], - ['stringDependsOnDouble', 'mainDoubleFlag', 0.11, 'Cat'], - ['stringDependsOnDouble', 'mainDoubleFlag', '0.1', null], - ['stringDependsOnDouble', 'mainDoubleFlag', true, null], - ['stringDependsOnDouble', 'mainDoubleFlag', 1, null], - ['stringDependsOnDouble', 'mainDoubleFlag', [0.1], null], - ['stringDependsOnDouble', 'mainDoubleFlag', null, null], + ['key1', "'key1' -> 'key1'"], + ['key2', "'key2' -> 'key3' -> 'key2'"], + ['key4', "'key4' -> 'key3' -> 'key2' -> 'key3'"], ], function ($testCase) { - return "key: {$testCase[0]} | prerequisiteFlagKey: {$testCase[1]} | prerequisiteFlagValue: {$testCase[2]}"; + return "key: {$testCase[0]} | dependencyCycle: {$testCase[1]}"; }); } @@ -462,28 +425,40 @@ public function testPrerequisiteFlagComparisonValueTypeMismatch(string $key, str } } - public function provideTestDataForPrerequisiteFlagOverride() + public function provideTestDataForPrerequisiteFlagComparisonValueTypeMismatch() { // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9e4e-4f59-86b2-5da50924b6ca/08dbc325-9ebd-4587-8171-88f76a3004cb return Utils::withDescription([ - ['stringDependsOnString', '1', 'john@sensitivecompany.com', null, 'Dog'], - ['stringDependsOnString', '1', 'john@sensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Dog'], - ['stringDependsOnString', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Dog'], - ['stringDependsOnString', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], - ['stringDependsOnString', '2', 'john@notsensitivecompany.com', null, 'Cat'], - ['stringDependsOnString', '2', 'john@notsensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Cat'], - ['stringDependsOnString', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Dog'], - ['stringDependsOnString', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], - ['stringDependsOnInt', '1', 'john@sensitivecompany.com', null, 'Dog'], - ['stringDependsOnInt', '1', 'john@sensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Dog'], - ['stringDependsOnInt', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Cat'], - ['stringDependsOnInt', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], - ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', null, 'Cat'], - ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Cat'], - ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Dog'], - ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], + ['stringDependsOnBool', 'mainBoolFlag', true, 'Dog'], + ['stringDependsOnBool', 'mainBoolFlag', false, 'Cat'], + ['stringDependsOnBool', 'mainBoolFlag', '1', null], + ['stringDependsOnBool', 'mainBoolFlag', 1, null], + ['stringDependsOnBool', 'mainBoolFlag', 1.0, null], + ['stringDependsOnBool', 'mainBoolFlag', [true], null], + ['stringDependsOnBool', 'mainBoolFlag', null, null], + ['stringDependsOnString', 'mainStringFlag', 'private', 'Dog'], + ['stringDependsOnString', 'mainStringFlag', 'Private', 'Cat'], + ['stringDependsOnString', 'mainStringFlag', true, null], + ['stringDependsOnString', 'mainStringFlag', 1, null], + ['stringDependsOnString', 'mainStringFlag', 1.0, null], + ['stringDependsOnString', 'mainStringFlag', ['private'], null], + ['stringDependsOnString', 'mainStringFlag', null, null], + ['stringDependsOnInt', 'mainIntFlag', 2, 'Dog'], + ['stringDependsOnInt', 'mainIntFlag', 1, 'Cat'], + ['stringDependsOnInt', 'mainIntFlag', '2', null], + ['stringDependsOnInt', 'mainIntFlag', true, null], + ['stringDependsOnInt', 'mainIntFlag', 2.0, null], + ['stringDependsOnInt', 'mainIntFlag', [2], null], + ['stringDependsOnInt', 'mainIntFlag', null, null], + ['stringDependsOnDouble', 'mainDoubleFlag', 0.1, 'Dog'], + ['stringDependsOnDouble', 'mainDoubleFlag', 0.11, 'Cat'], + ['stringDependsOnDouble', 'mainDoubleFlag', '0.1', null], + ['stringDependsOnDouble', 'mainDoubleFlag', true, null], + ['stringDependsOnDouble', 'mainDoubleFlag', 1, null], + ['stringDependsOnDouble', 'mainDoubleFlag', [0.1], null], + ['stringDependsOnDouble', 'mainDoubleFlag', null, null], ], function ($testCase) { - return "key: {$testCase[0]} | userId: {$testCase[1]} | email: {$testCase[2]} | overrideBehaviour: {$testCase[3]}"; + return "key: {$testCase[0]} | prerequisiteFlagKey: {$testCase[1]} | prerequisiteFlagValue: {$testCase[2]}"; }); } @@ -522,18 +497,26 @@ public function testPrerequisiteFlagOverride(string $key, string $userId, string } } - public function provideTestDataForConfigSaltAndSegmentsOverride() + public function provideTestDataForPrerequisiteFlagOverride() { // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9e4e-4f59-86b2-5da50924b6ca/08dbc325-9ebd-4587-8171-88f76a3004cb return Utils::withDescription([ - ['developerAndBetaUserSegment', '1', 'john@example.com', null, false], - ['developerAndBetaUserSegment', '1', 'john@example.com', OverrideBehaviour::REMOTE_OVER_LOCAL, false], - ['developerAndBetaUserSegment', '1', 'john@example.com', OverrideBehaviour::LOCAL_OVER_REMOTE, true], - ['developerAndBetaUserSegment', '1', 'john@example.com', OverrideBehaviour::LOCAL_ONLY, true], - ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', null, true], - ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', OverrideBehaviour::REMOTE_OVER_LOCAL, true], - ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', OverrideBehaviour::LOCAL_OVER_REMOTE, true], - ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', OverrideBehaviour::LOCAL_ONLY, null], + ['stringDependsOnString', '1', 'john@sensitivecompany.com', null, 'Dog'], + ['stringDependsOnString', '1', 'john@sensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Dog'], + ['stringDependsOnString', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Dog'], + ['stringDependsOnString', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], + ['stringDependsOnString', '2', 'john@notsensitivecompany.com', null, 'Cat'], + ['stringDependsOnString', '2', 'john@notsensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Cat'], + ['stringDependsOnString', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Dog'], + ['stringDependsOnString', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], + ['stringDependsOnInt', '1', 'john@sensitivecompany.com', null, 'Dog'], + ['stringDependsOnInt', '1', 'john@sensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Dog'], + ['stringDependsOnInt', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Cat'], + ['stringDependsOnInt', '1', 'john@sensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], + ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', null, 'Cat'], + ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', OverrideBehaviour::REMOTE_OVER_LOCAL, 'Cat'], + ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_OVER_REMOTE, 'Dog'], + ['stringDependsOnInt', '2', 'john@notsensitivecompany.com', OverrideBehaviour::LOCAL_ONLY, null], ], function ($testCase) { return "key: {$testCase[0]} | userId: {$testCase[1]} | email: {$testCase[2]} | overrideBehaviour: {$testCase[3]}"; }); @@ -574,21 +557,20 @@ public function testConfigSaltAndSegmentsOverride(string $key, string $userId, s } } - public function provideTestDataForEvaluationDetailsMatchedEvaluationRuleAndPercantageOption() + public function provideTestDataForConfigSaltAndSegmentsOverride() { // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9e4e-4f59-86b2-5da50924b6ca/08dbc325-9ebd-4587-8171-88f76a3004cb return Utils::withDescription([ - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', null, null, null, 'Cat', false, false], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', null, null, 'Cat', false, false], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@example.com', null, 'Dog', true, false], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@configcat.com', null, 'Cat', false, false], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@configcat.com', '', 'Frog', true, true], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@configcat.com', 'US', 'Fish', true, true], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'b@configcat.com', null, 'Cat', false, false], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'b@configcat.com', '', 'Falcon', false, true], - ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'b@configcat.com', 'US', 'Spider', false, true], + ['developerAndBetaUserSegment', '1', 'john@example.com', null, false], + ['developerAndBetaUserSegment', '1', 'john@example.com', OverrideBehaviour::REMOTE_OVER_LOCAL, false], + ['developerAndBetaUserSegment', '1', 'john@example.com', OverrideBehaviour::LOCAL_OVER_REMOTE, true], + ['developerAndBetaUserSegment', '1', 'john@example.com', OverrideBehaviour::LOCAL_ONLY, true], + ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', null, true], + ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', OverrideBehaviour::REMOTE_OVER_LOCAL, true], + ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', OverrideBehaviour::LOCAL_OVER_REMOTE, true], + ['notDeveloperAndNotBetaUserSegment', '2', 'kate@example.com', OverrideBehaviour::LOCAL_ONLY, null], ], function ($testCase) { - return "sdkKey: {$testCase[0]} | key: {$testCase[1]} | userId: {$testCase[2]} | email: {$testCase[3]} | percentageBase: {$testCase[4]}"; + return "key: {$testCase[0]} | userId: {$testCase[1]} | email: {$testCase[2]} | overrideBehaviour: {$testCase[3]}"; }); } @@ -619,4 +601,22 @@ public function testEvaluationDetailsMatchedEvaluationRuleAndPercantageOption( $this->assertSame($expectedIsExpectedMatchedTargetingRuleSet, null != $evaluationDetails->getMatchedTargetingRule()); $this->assertSame($expectedIsExpectedMatchedPercentageOptionSet, null != $evaluationDetails->getMatchedPercentageOption()); } + + public function provideTestDataForEvaluationDetailsMatchedEvaluationRuleAndPercantageOption() + { + // https://app.configcat.com/v2/e7a75611-4256-49a5-9320-ce158755e3ba/08dbc325-7f69-4fd4-8af4-cf9f24ec8ac9/08dbc325-9e4e-4f59-86b2-5da50924b6ca/08dbc325-9ebd-4587-8171-88f76a3004cb + return Utils::withDescription([ + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', null, null, null, 'Cat', false, false], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', null, null, 'Cat', false, false], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@example.com', null, 'Dog', true, false], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@configcat.com', null, 'Cat', false, false], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@configcat.com', '', 'Frog', true, true], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'a@configcat.com', 'US', 'Fish', true, true], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'b@configcat.com', null, 'Cat', false, false], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'b@configcat.com', '', 'Falcon', false, true], + ['configcat-sdk-1/JcPbCGl_1E-K9M-fJOyKyQ/P4e3fAz_1ky2-Zg2e4cbkw', 'stringMatchedTargetingRuleAndOrPercentageOption', '12345', 'b@configcat.com', 'US', 'Spider', false, true], + ], function ($testCase) { + return "sdkKey: {$testCase[0]} | key: {$testCase[1]} | userId: {$testCase[2]} | email: {$testCase[3]} | percentageBase: {$testCase[4]}"; + }); + } } diff --git a/tests/EvaluationLogTest.php b/tests/EvaluationLogTest.php index ba046aa..e9dee0e 100644 --- a/tests/EvaluationLogTest.php +++ b/tests/EvaluationLogTest.php @@ -34,41 +34,6 @@ class EvaluationLogTest extends TestCase 'list_truncation', ]; - public function provideTestData(): array - { - $testCaseDataArray = []; - - foreach (self::TEST_SETS as $testSetName) { - $filePath = self::TEST_DATA_ROOT_PATH.'/'.$testSetName.'.json'; - $fileContent = file_get_contents($filePath); - $testSet = json_decode($fileContent, true); - - $sdkKey = $testSet['sdkKey']; - $baseUrlOrOverrideFileName = is_string($sdkKey) && '' !== $sdkKey - ? $testSet['baseUrl'] ?? null - : $testSet['jsonOverride']; - - $testCases = $testSet['tests'] ?? []; - - foreach ($testCases as $i => $testCase) { - $expectedLogFileName = $testCase['expectedLog']; - $testName = $testSetName.'['.$i.'] - '.$expectedLogFileName; - $testCaseDataArray[$testName] = [ - $testSetName, - $sdkKey, - $baseUrlOrOverrideFileName, - $testCase['key'], - $testCase['defaultValue'] ?? null, - $testCase['user'] ?? null, - $testCase['returnValue'] ?? null, - $expectedLogFileName, - ]; - } - } - - return $testCaseDataArray; - } - /** * @dataProvider provideTestData */ @@ -134,4 +99,39 @@ public function testEvaluationLog( $this->assertEquals($expectedLogText, $actualLogText); } + + public function provideTestData(): array + { + $testCaseDataArray = []; + + foreach (self::TEST_SETS as $testSetName) { + $filePath = self::TEST_DATA_ROOT_PATH.'/'.$testSetName.'.json'; + $fileContent = file_get_contents($filePath); + $testSet = json_decode($fileContent, true); + + $sdkKey = $testSet['sdkKey']; + $baseUrlOrOverrideFileName = is_string($sdkKey) && '' !== $sdkKey + ? $testSet['baseUrl'] ?? null + : $testSet['jsonOverride']; + + $testCases = $testSet['tests'] ?? []; + + foreach ($testCases as $i => $testCase) { + $expectedLogFileName = $testCase['expectedLog']; + $testName = $testSetName.'['.$i.'] - '.$expectedLogFileName; + $testCaseDataArray[$testName] = [ + $testSetName, + $sdkKey, + $baseUrlOrOverrideFileName, + $testCase['key'], + $testCase['defaultValue'] ?? null, + $testCase['user'] ?? null, + $testCase['returnValue'] ?? null, + $expectedLogFileName, + ]; + } + } + + return $testCaseDataArray; + } } diff --git a/tests/OverrideTest.php b/tests/OverrideTest.php index 23f3597..e480129 100644 --- a/tests/OverrideTest.php +++ b/tests/OverrideTest.php @@ -16,40 +16,6 @@ class OverrideTest extends TestCase { - public function provideOverrideValueTypeMismatchShouldBeHandledCorrectly_Dictionary(): array - { - return Utils::withDescription([ - [true, false, true], - [true, '', true], - [true, 0, true], - [true, 0.0, true], - ['text', false, 'text'], - ['text', '', 'text'], - ['text', 0, 'text'], - ['text', 0.0, 'text'], - [42, false, 42], - [42, '', 42], - [42, 0, 42], - [42, 0.0, 42], - [42.0, false, 42.0], - [42.0, '', 42.0], - [42.0, 0, 42.0], - [42.0, 0.0, 42.0], - [3.14, false, 3.14], - [3.14, '', 3.14], - [3.14, 0, 3.14], - [3.14, 0.0, 3.14], - [null, false, false], - [[], false, false], - [new stdClass(), false, false], - [new DateTimeImmutable(), false, false], - ], function ($testCase) { - $overrideValue = \ConfigCat\Utils::getStringRepresentation($testCase[0]); - - return "overrideValue: {$overrideValue} | defaultValue: {$testCase[1]}"; - }); - } - /** * @dataProvider provideOverrideValueTypeMismatchShouldBeHandledCorrectly_Dictionary */ @@ -98,34 +64,37 @@ public function testOverrideValueTypeMismatchShouldBeHandledCorrectlyDictionary( } } - public function provideOverrideValueTypeMismatchShouldBeHandledCorrectly_SimplifiedConfig(): array + public function provideOverrideValueTypeMismatchShouldBeHandledCorrectly_Dictionary(): array { return Utils::withDescription([ - ['true', false, true], - ['true', '', true], - ['true', 0, true], - ['true', 0.0, true], - ['"text"', false, 'text'], - ['"text"', '', 'text'], - ['"text"', 0, 'text'], - ['"text"', 0.0, 'text'], - ['42', false, 42], - ['42', '', 42], - ['42', 0, 42], - ['42', 0.0, 42], - ['42.0', false, 42.0], - ['42.0', '', 42.0], - ['42.0', 0, 42.0], - ['42.0', 0.0, 42.0], - ['3.14', false, 3.14], - ['3.14', '', 3.14], - ['3.14', 0, 3.14], - ['3.14', 0.0, 3.14], - ['null', false, false], - ['[]', false, false], - ['{}', false, false], + [true, false, true], + [true, '', true], + [true, 0, true], + [true, 0.0, true], + ['text', false, 'text'], + ['text', '', 'text'], + ['text', 0, 'text'], + ['text', 0.0, 'text'], + [42, false, 42], + [42, '', 42], + [42, 0, 42], + [42, 0.0, 42], + [42.0, false, 42.0], + [42.0, '', 42.0], + [42.0, 0, 42.0], + [42.0, 0.0, 42.0], + [3.14, false, 3.14], + [3.14, '', 3.14], + [3.14, 0, 3.14], + [3.14, 0.0, 3.14], + [null, false, false], + [[], false, false], + [new stdClass(), false, false], + [new DateTimeImmutable(), false, false], ], function ($testCase) { - return "overrideValueJson: {$testCase[0]} | defaultValue: {$testCase[1]}"; + $overrideValue = \ConfigCat\Utils::getStringRepresentation($testCase[0]); + + return "overrideValue: {$overrideValue} | defaultValue: {$testCase[1]}"; }); } @@ -185,4 +154,35 @@ public function testOverrideValueTypeMismatchShouldBeHandledCorrectlySimplifiedC fclose($tempFile); } } + + public function provideOverrideValueTypeMismatchShouldBeHandledCorrectly_SimplifiedConfig(): array + { + return Utils::withDescription([ + ['true', false, true], + ['true', '', true], + ['true', 0, true], + ['true', 0.0, true], + ['"text"', false, 'text'], + ['"text"', '', 'text'], + ['"text"', 0, 'text'], + ['"text"', 0.0, 'text'], + ['42', false, 42], + ['42', '', 42], + ['42', 0, 42], + ['42', 0.0, 42], + ['42.0', false, 42.0], + ['42.0', '', 42.0], + ['42.0', 0, 42.0], + ['42.0', 0.0, 42.0], + ['3.14', false, 3.14], + ['3.14', '', 3.14], + ['3.14', 0, 3.14], + ['3.14', 0.0, 3.14], + ['null', false, false], + ['[]', false, false], + ['{}', false, false], + ], function ($testCase) { + return "overrideValueJson: {$testCase[0]} | defaultValue: {$testCase[1]}"; + }); + } } diff --git a/tests/RolloutIntegrationsTest.php b/tests/RolloutIntegrationsTest.php index 691c4c0..6c6d423 100644 --- a/tests/RolloutIntegrationsTest.php +++ b/tests/RolloutIntegrationsTest.php @@ -137,16 +137,6 @@ public function rolloutTestData(): array ]; } - public function provideTestDataForSpecialCharactersWorks(): array - { - return Utils::withDescription([ - ['specialCharacters', 'äöüÄÖÜçéèñışğ⢙✓😀', 'äöüÄÖÜçéèñışğ⢙✓😀'], - ['specialCharactersHashed', 'äöüÄÖÜçéèñışğ⢙✓😀', 'äöüÄÖÜçéèñışğ⢙✓😀'], - ], function ($testCase) { - return "settingKey: {$testCase[0]} | userId: {$testCase[1]}"; - }); - } - /** * @dataProvider provideTestDataForSpecialCharactersWorks */ @@ -164,6 +154,16 @@ public function testSpecialCharactersWorks( $this->assertSame($expectedReturnValue, $actualReturnValue); } + public function provideTestDataForSpecialCharactersWorks(): array + { + return Utils::withDescription([ + ['specialCharacters', 'äöüÄÖÜçéèñışğ⢙✓😀', 'äöüÄÖÜçéèñışğ⢙✓😀'], + ['specialCharactersHashed', 'äöüÄÖÜçéèñışğ⢙✓😀', 'äöüÄÖÜçéèñışğ⢙✓😀'], + ], function ($testCase) { + return "settingKey: {$testCase[0]} | userId: {$testCase[1]}"; + }); + } + private static function readCsv($file): array { $rows = []; diff --git a/tests/UserTest.php b/tests/UserTest.php index cb0211f..9ff40fb 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -87,21 +87,6 @@ public function testUseWellKnownAttributesAsCustomPropertiesShouldNotAppendAllAt $this->assertSame('myCustomAttributeValue', $user->getAttribute('myCustomAttribute')); } - public function provideTestDataForUseWellKnownAttributesAsCustomPropertiesWithDifferentNames_ShouldAppendAllAttributes(): array - { - return Utils::withDescription([ - ['identifier', 'myId'], - ['IDENTIFIER', 'myId'], - ['email', 'theBoss@example.com'], - ['EMAIL', 'theBoss@example.com'], - ['eMail', 'theBoss@example.com'], - ['country', 'myHome'], - ['COUNTRY', 'myHome'], - ], function ($testCase) { - return "attributeName: {$testCase[0]} | attributeValue: {$testCase[1]}"; - }); - } - /** * @dataProvider provideTestDataForUseWellKnownAttributesAsCustomPropertiesWithDifferentNames_ShouldAppendAllAttributes */ @@ -127,16 +112,18 @@ public function testUseWellKnownAttributesAsCustomPropertiesWithDifferentNamesSh $this->assertSame($attributeValue, $user->getAttribute($attributeName)); } - public function provideTestDataForCreateUser_ShouldSetIdentifier() + public function provideTestDataForUseWellKnownAttributesAsCustomPropertiesWithDifferentNames_ShouldAppendAllAttributes(): array { return Utils::withDescription([ - [null, ''], - ['', ''], - ['id', 'id'], - ["\t", "\t"], - ["\u{1F60}0", "\u{1F60}0"], + ['identifier', 'myId'], + ['IDENTIFIER', 'myId'], + ['email', 'theBoss@example.com'], + ['EMAIL', 'theBoss@example.com'], + ['eMail', 'theBoss@example.com'], + ['country', 'myHome'], + ['COUNTRY', 'myHome'], ], function ($testCase) { - return "identifier: {$testCase[0]}"; + return "attributeName: {$testCase[0]} | attributeValue: {$testCase[1]}"; }); } @@ -160,4 +147,17 @@ public function testCreateUserShouldSetIdentifier(string $identifier, string $ex $this->assertSame($expectedValue, $user->getAttribute(User::IDENTIFIER_ATTRIBUTE)); $this->assertSame($expectedValue, $user->getIdentifier()); } + + public function provideTestDataForCreateUser_ShouldSetIdentifier() + { + return Utils::withDescription([ + [null, ''], + ['', ''], + ['id', 'id'], + ["\t", "\t"], + ["\u{1F60}0", "\u{1F60}0"], + ], function ($testCase) { + return "identifier: {$testCase[0]}"; + }); + } } diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 0207ff3..b405ad1 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -7,6 +7,14 @@ class UtilsTest extends TestCase { + /** + * @dataProvider provideTestDataForNumberToString + */ + public function testNumberToString(float|int $number, string $expectedReturnValue) + { + $this->assertSame($expectedReturnValue, \ConfigCat\Utils::numberToString($number)); + } + public function provideTestDataForNumberToString(): array { return Utils::withDescription([ @@ -46,12 +54,4 @@ public function provideTestDataForNumberToString(): array return "number: {$testCase[0]}"; }); } - - /** - * @dataProvider provideTestDataForNumberToString - */ - public function testNumberToString(float|int $number, string $expectedReturnValue) - { - $this->assertSame($expectedReturnValue, \ConfigCat\Utils::numberToString($number)); - } }