Skip to content

Commit

Permalink
feat: make nullable for alla attributes in CmsInfo and CmsFeatures
Browse files Browse the repository at this point in the history
  • Loading branch information
joyet-simon committed Oct 25, 2024
1 parent 8ed5363 commit cddd6d8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 50 deletions.
28 changes: 12 additions & 16 deletions src/Entities/MerchantData/CmsFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CmsFeatures
private $widgetProductActivated;

/**
* @var array
* @var array|null
*/
private $usedFeePlans;

Expand All @@ -40,22 +40,17 @@ class CmsFeatures
private $logActivated;

/**
* @var string[]
* @var string[]|null
*/
private $excludedCategories;

/**
* @var bool | null
*/
private $excludedCategoriesActivated;

/**
* @var array<array{name: string}>
* @var array<array{name: string}>|null
*/
private $specificFeatures;

/**
* @var string[]
* @var string[]|null
*/
private $countryRestriction;

Expand All @@ -79,15 +74,17 @@ public function __construct($cmsFeaturesDataArray)
$this->almaEnabled = isset($cmsFeaturesDataArray['alma_enabled']) ? $cmsFeaturesDataArray['alma_enabled'] : null;
$this->widgetCartActivated = isset($cmsFeaturesDataArray['widget_cart_activated']) ? $cmsFeaturesDataArray['widget_cart_activated'] : null;
$this->widgetProductActivated = isset($cmsFeaturesDataArray['widget_product_activated']) ? $cmsFeaturesDataArray['widget_product_activated'] : null;
$this->usedFeePlans = isset($cmsFeaturesDataArray['used_fee_plans']) ? $cmsFeaturesDataArray['used_fee_plans'] : [];
$this->usedFeePlans = isset($cmsFeaturesDataArray['used_fee_plans']) ? $cmsFeaturesDataArray['used_fee_plans'] : null;
$this->inPageActivated = isset($cmsFeaturesDataArray['in_page_activated']) ? $cmsFeaturesDataArray['in_page_activated'] : null;
$this->logActivated = isset($cmsFeaturesDataArray['log_activated']) ? $cmsFeaturesDataArray['log_activated'] : null;
$this->excludedCategories = isset($cmsFeaturesDataArray['excluded_categories']) ? $cmsFeaturesDataArray['excluded_categories'] : [];
$this->excludedCategoriesActivated = isset($cmsFeaturesDataArray['excluded_categories_activated']) ?
$cmsFeaturesDataArray['excluded_categories_activated'] : null;
if (isset($cmsFeaturesDataArray['excluded_categories_activated']) && $cmsFeaturesDataArray['excluded_categories_activated']) {
$this->excludedCategories = isset($cmsFeaturesDataArray['excluded_categories']) ? $cmsFeaturesDataArray['excluded_categories'] : null;
} else {
$this->excludedCategories = null;
}
$this->paymentMethodPosition = isset($cmsFeaturesDataArray['payment_method_position']) ? $cmsFeaturesDataArray['payment_method_position'] : null;
$this->specificFeatures = isset($cmsFeaturesDataArray['specific_features']) ? $cmsFeaturesDataArray['specific_features'] : [];
$this->countryRestriction = isset($cmsFeaturesDataArray['country_restriction']) ? $cmsFeaturesDataArray['country_restriction'] : [];
$this->specificFeatures = isset($cmsFeaturesDataArray['specific_features']) ? $cmsFeaturesDataArray['specific_features'] : null;
$this->countryRestriction = isset($cmsFeaturesDataArray['country_restriction']) ? $cmsFeaturesDataArray['country_restriction'] : null;
$this->isMultisite = isset($cmsFeaturesDataArray['is_multisite']) ? $cmsFeaturesDataArray['is_multisite'] : null;
$this->customWidgetCss = isset($cmsFeaturesDataArray['custom_widget_css']) ? $cmsFeaturesDataArray['custom_widget_css'] : null;
}
Expand All @@ -106,7 +103,6 @@ public function getProperties()
'in_page_activated' => $this->inPageActivated,
'log_activated' => $this->logActivated,
'excluded_categories' => $this->excludedCategories,
'excluded_categories_activated' => $this->excludedCategoriesActivated,
'payment_method_position' => $this->paymentMethodPosition,
'specific_features' => $this->specificFeatures,
'country_restriction' => $this->countryRestriction,
Expand Down
8 changes: 4 additions & 4 deletions src/Entities/MerchantData/CmsInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class CmsInfo
private $cmsVersion;

/**
* @var array<array{name: string, version: string}>
* @var array<array{name: string, version: string}>|null
*/
private $thirdPartiesPlugins;

/**
* @var array<array{name: string, version: string}>
* @var array<array{name: string, version: string}>|null
*/
private $themes;

Expand Down Expand Up @@ -58,8 +58,8 @@ public function __construct($cmsInfoDataArray)
// Initialize values or set them to null if not available
$this->cmsName = isset($cmsInfoDataArray['cms_name']) ? $cmsInfoDataArray['cms_name'] : '';
$this->cmsVersion = isset($cmsInfoDataArray['cms_version']) ? $cmsInfoDataArray['cms_version'] : '';
$this->thirdPartiesPlugins = isset($cmsInfoDataArray['third_parties_plugins']) ? $cmsInfoDataArray['third_parties_plugins'] : [];
$this->themes = isset($cmsInfoDataArray['themes']) ? $cmsInfoDataArray['themes'] : [];
$this->thirdPartiesPlugins = isset($cmsInfoDataArray['third_parties_plugins']) ? $cmsInfoDataArray['third_parties_plugins'] : null;
$this->themes = isset($cmsInfoDataArray['themes']) ? $cmsInfoDataArray['themes'] : null;
$this->languageName = isset($cmsInfoDataArray['language_name']) ? $cmsInfoDataArray['language_name'] : '';
$this->languageVersion = isset($cmsInfoDataArray['language_version']) ? $cmsInfoDataArray['language_version'] : '';
$this->almaPluginVersion = isset($cmsInfoDataArray['alma_plugin_version']) ? $cmsInfoDataArray['alma_plugin_version'] : '';
Expand Down
45 changes: 21 additions & 24 deletions tests/Unit/Entities/CmsFeaturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function testConstructorSetsValuesCorrectly()
$this->assertTrue($cmsFeatures->getProperties()['in_page_activated']);
$this->assertFalse($cmsFeatures->getProperties()['log_activated']);
$this->assertEquals(['category1', 'category2'], $cmsFeatures->getProperties()['excluded_categories']);
$this->assertTrue($cmsFeatures->getProperties()['excluded_categories_activated']);
$this->assertEquals(['feature1', 'feature2'], $cmsFeatures->getProperties()['specific_features']);
$this->assertEquals(['FR', 'US'], $cmsFeatures->getProperties()['country_restriction']);
$this->assertFalse($cmsFeatures->getProperties()['is_multisite']);
Expand All @@ -48,34 +47,33 @@ public function testConstructorHandlesNullValuesCorrectly()
'alma_enabled' => null,
'widget_cart_activated' => null,
'widget_product_activated' => null,
'used_fee_plans' => [],
'used_fee_plans' => null,
'payment_method_position' => null,
'in_page_activated' => null,
'log_activated' => null,
'excluded_categories' => [],
'excluded_categories' => null,
'excluded_categories_activated' => null,
'specific_features' => [],
'country_restriction' => [],
'specific_features' => null,
'country_restriction' => null,
'is_multisite' => null,
'custom_widget_css' => null,
];

$cmsFeatures = new CmsFeatures($data);
$properties = $cmsFeatures->getProperties();

$this->assertArrayNotHasKey('alma_enabled', $properties);
$this->assertArrayNotHasKey('widget_cart_activated', $properties);
$this->assertArrayNotHasKey('widget_product_activated', $properties);
$this->assertEquals([], $properties['used_fee_plans']);
$this->assertArrayNotHasKey('payment_method_position', $properties);
$this->assertArrayNotHasKey('in_page_activated', $properties);
$this->assertArrayNotHasKey('log_activated', $properties);
$this->assertEquals([], $properties['excluded_categories']); // Should be an empty array
$this->assertArrayNotHasKey('excluded_categories_activated', $properties);
$this->assertEquals([], $properties['specific_features']); // Should be an empty array
$this->assertEquals([], $properties['country_restriction']); // Should be an empty array
$this->assertArrayNotHasKey('is_multisite', $properties);
$this->assertArrayNotHasKey('custom_widget_css', $properties);
$this->assertArrayNotHasKey('alma_enabled', $properties);
$this->assertArrayNotHasKey('widget_cart_activated', $properties);
$this->assertArrayNotHasKey('widget_product_activated', $properties);
$this->assertArrayNotHasKey('used_fee_plans', $properties);
$this->assertArrayNotHasKey('payment_method_position', $properties);
$this->assertArrayNotHasKey('in_page_activated', $properties);
$this->assertArrayNotHasKey('excluded_categories', $properties);
$this->assertArrayNotHasKey('excluded_categories_activated', $properties);
$this->assertArrayNotHasKey('specific_features', $properties);
$this->assertArrayNotHasKey('country_restriction', $properties);
$this->assertArrayNotHasKey('is_multisite', $properties);
$this->assertArrayNotHasKey('custom_widget_css', $properties);
}

public function testGetPropertiesFiltersOutNullAndEmptyValues()
Expand All @@ -89,7 +87,7 @@ public function testGetPropertiesFiltersOutNullAndEmptyValues()
'in_page_activated' => false,
'log_activated' => null,
'excluded_categories' => ['category3'],
'excluded_categories_activated' => null,
'excluded_categories_activated' => true,
'specific_features' => [],
'country_restriction' => [],
'is_multisite' => false,
Expand All @@ -106,7 +104,6 @@ public function testGetPropertiesFiltersOutNullAndEmptyValues()
$this->assertArrayNotHasKey('payment_method_position', $properties); // Should be filtered out (null)
$this->assertArrayHasKey('in_page_activated', $properties);
$this->assertArrayHasKey('excluded_categories', $properties);
$this->assertArrayNotHasKey('excluded_categories_activated', $properties); // Should be filtered out (null)
$this->assertArrayHasKey('specific_features', $properties);
$this->assertArrayHasKey('country_restriction', $properties);
$this->assertArrayHasKey('is_multisite', $properties);
Expand All @@ -123,13 +120,13 @@ public function testGetPropertiesFiltersOutWithEmptyData()
$this->assertArrayNotHasKey('alma_enabled', $properties);
$this->assertArrayNotHasKey('widget_cart_activated', $properties);
$this->assertArrayNotHasKey('widget_product_activated', $properties);
$this->assertEquals([], $properties['used_fee_plans']);
$this->assertArrayNotHasKey('used_fee_plans', $properties);
$this->assertArrayNotHasKey('payment_method_position', $properties);
$this->assertArrayNotHasKey('in_page_activated', $properties);
$this->assertEquals([], $properties['excluded_categories']);
$this->assertArrayNotHasKey('excluded_categories', $properties);
$this->assertArrayNotHasKey('excluded_categories_activated', $properties);
$this->assertEquals([], $properties['specific_features']);
$this->assertEquals([], $properties['country_restriction']);
$this->assertArrayNotHasKey('specific_features', $properties);
$this->assertArrayNotHasKey('country_restriction', $properties);
$this->assertArrayNotHasKey('is_multisite', $properties);
$this->assertArrayNotHasKey('custom_widget_css', $properties);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Entities/CmsInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function testConstructorHandlesNullValuesCorrectly()
$data = [
'cms_name' => null,
'cms_version' => null,
'third_parties_plugins' => [],
'themes' => [],
'third_parties_plugins' => null,
'themes' => null,
'language_name' => null,
'language_version' => null,
'alma_plugin_version' => null,
Expand All @@ -60,8 +60,8 @@ public function testConstructorHandlesNullValuesCorrectly()
$this->assertArrayNotHasKey('alma_plugin_version', $cmsInfo->getProperties());
$this->assertArrayNotHasKey('alma_sdk_version', $cmsInfo->getProperties());
$this->assertArrayNotHasKey('alma_sdk_name', $cmsInfo->getProperties());
$this->assertEquals([], $cmsInfo->getProperties()['third_parties_plugins']);
$this->assertEquals([], $cmsInfo->getProperties()['themes']);
$this->assertArrayNotHasKey('third_parties_plugins', $cmsInfo->getProperties());
$this->assertArrayNotHasKey('themes', $cmsInfo->getProperties());
}

public function testGetPropertiesFiltersOutNullAndEmptyValues()
Expand Down Expand Up @@ -99,8 +99,8 @@ public function testGetPropertiesFiltersOutWithEmptyData()

$this->assertArrayNotHasKey('cms_name', $properties);
$this->assertArrayNotHasKey('cms_version', $properties); // Should be filtered out (empty string)
$this->assertEquals([], $cmsInfo->getProperties()['third_parties_plugins']);
$this->assertEquals([], $cmsInfo->getProperties()['themes']);
$this->assertArrayNotHasKey('third_parties_plugins', $properties);
$this->assertArrayNotHasKey('themes', $properties);
$this->assertArrayNotHasKey('language_name', $properties); // Should be filtered out (null)
$this->assertArrayNotHasKey('language_version', $properties); // Should be filtered out (empty string)
$this->assertArrayNotHasKey('alma_sdk_version', $properties);
Expand Down

0 comments on commit cddd6d8

Please sign in to comment.