diff --git a/Model/Carrier/AdditionalInfo.php b/Model/Carrier/AdditionalInfo.php index 2c82b4fbfbdb018d64aaca300e5e129b01dd83cd..215dc086b87335f05ad724bcc51fc4b730f7476a 100644 --- a/Model/Carrier/AdditionalInfo.php +++ b/Model/Carrier/AdditionalInfo.php @@ -57,8 +57,7 @@ class AdditionalInfo { $data = $this->getRequestBody(); - if ( - isset($data['address']) && is_array($data['address']) && + if (isset($data['address']) && is_array($data['address']) && isset($data['address']['custom_attributes'][0]) && is_array($data['address']['custom_attributes'][0]) && isset($data['address']['custom_attributes'][0]['value']) ) { diff --git a/Model/Carrier/BobGo.php b/Model/Carrier/BobGo.php index 345327a3a12a7480111a0fd7fdffa3ffacf6e658..386e4cbc07cd86549a73eaed2cfa25fa22a35185 100644 --- a/Model/Carrier/BobGo.php +++ b/Model/Carrier/BobGo.php @@ -145,7 +145,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car * @param JsonFactory $jsonFactory * @param CurlFactory $curlFactory * @param MagentoHttp $request - * @param array<string, mixed> $data + * @param array<string,mixed> $data */ public function __construct( ScopeConfigInterface $scopeConfig, @@ -230,7 +230,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car /** * Makes a request to the Bob Go API to get shipping rates for the cart. * - * @param array<string, mixed> $payload + * @param array<string,mixed> $payload * @return array<int|string, mixed> */ public function getRates(array $payload): array @@ -587,7 +587,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car /** * Parse tracking response * - * @param string|array<int, string> $trackingValue + * @param string|array<int,string> $trackingValue * @return void */ protected function _parseTrackingResponse($trackingValue) @@ -867,7 +867,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car /** * Perform API Request to Bob Go API and return response. * - * @param array<string, mixed> $payload The payload for the API request. + * @param array<string,mixed> $payload The payload for the API request. * @param Result $result The result object to append the rates. * @return void */ @@ -879,8 +879,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car if (is_array($rates)) { $this->_formatRates($rates, $result); } else { - $this->_logger->error('Bob Go API returned an invalid response: - expected an array but received ' . gettype($rates)); + $this->_logger->error('Bob Go API returned an invalid response'); } } @@ -888,7 +887,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car * Perform API Request for Shipment Tracking to Bob Go API and return response. * * @param string $trackInfo The tracking information or tracking ID. - * @param array<string, array<int, array<string, string>>> $result The result array to be + * @param array<string,array<int,array<string,string>>> $result The result array to be * populated with tracking details. * @return array<string, array<int, array<string, string>>> The updated result array with tracking details. */ @@ -907,7 +906,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car /** * Format rates from Bob Go API response and append to rate result instance of carrier. * - * @param array<int|string, mixed> $rates The rates data from the API. + * @param array<int|string,mixed> $rates The rates data from the API. * @param Result $result The result object to append the rates. * @return void */ @@ -980,8 +979,8 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car /** * Prepare received checkpoints and activity from Bob Go Shipment Tracking API. * - * @param array<string, mixed> $response The API response containing tracking checkpoints. - * @param array<string, array<int, array<string, string>>> $result The result array to be + * @param array<string,mixed> $response The API response containing tracking checkpoints. + * @param array<string,array<int,array<string,string>>> $result The result array to be * populated with activity details. * @return array<string, array<int, array<string, string>>> The updated result array with activity details. */ @@ -1056,7 +1055,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car /** * Build the payload for Bob Go API request and return the response. * - * @param array<string, mixed> $payload The payload for the API request. + * @param array<string,mixed> $payload The payload for the API request. * @return array<int|string, mixed>|null The decoded response, or null if the response could not be decoded * or is not an array. */ @@ -1177,7 +1176,7 @@ class BobGo extends AbstractCarrierOnline implements \Magento\Shipping\Model\Car * * @param \Magento\Quote\Model\Quote\Item[] $items The items in the cart. * @param string $weightUnit The unit of weight used for the items. - * @param array<int, array<string, mixed>> $itemsArray The array to store the processed item details. + * @param array<int,array<string,mixed>> $itemsArray The array to store the processed item details. * @return array<int, array<string, mixed>> The array containing details of each item, * including SKU, quantity, price, and weight. */ diff --git a/Plugin/Checkout/Block/LayoutProcessorPlugin.php b/Plugin/Checkout/Block/LayoutProcessorPlugin.php index e3e4a0e0680bfd9390388156832a761c9a6893e3..d5d302a7f298e317302e50b96b1932e0ccfe7736 100644 --- a/Plugin/Checkout/Block/LayoutProcessorPlugin.php +++ b/Plugin/Checkout/Block/LayoutProcessorPlugin.php @@ -18,8 +18,8 @@ class LayoutProcessorPlugin /** * Modify checkout layout to add suburb field. * - * @param LayoutProcessor $subject - * @param array<string, mixed> $jsLayout The JS layout array to be modified. + * @param LayoutProcessor $subject The subject being processed. + * @param array<string,mixed> $jsLayout The JS layout array to be modified. * @return array<string, mixed> The modified JS layout array. */ public function afterProcess( diff --git a/Test/Unit/Block/System/Config/Form/Field/VersionTest.php b/Test/Unit/Block/System/Config/Form/Field/VersionTest.php index b031749a3d0f7cc0d59d4d0ecf46fff1b149fcae..ad57e650ae7aa8d077d0755982bb19e8291f4317 100644 --- a/Test/Unit/Block/System/Config/Form/Field/VersionTest.php +++ b/Test/Unit/Block/System/Config/Form/Field/VersionTest.php @@ -34,7 +34,13 @@ class VersionTest extends TestCase $this->versionBlock = new Version($this->contextMock, $this->helperMock); } - private function callProtectedMethod($object, $methodName, array $parameters = []) + /** + * @param object $object + * @param string $methodName + * @param array<int, mixed> $parameters + * @return mixed + */ + private function callProtectedMethod(object $object, string $methodName, array $parameters = []) { $reflection = new \ReflectionClass($object); $method = $reflection->getMethod($methodName); @@ -43,7 +49,7 @@ class VersionTest extends TestCase return $method->invokeArgs($object, $parameters); } - public function testGetElementHtml() + public function testGetElementHtml(): void { // Mock the AbstractElement $elementMock = $this->createMock(AbstractElement::class); @@ -69,7 +75,7 @@ class VersionTest extends TestCase $this->assertEquals($expectedHtml, $result); } - public function testGetElementHtmlWithNonStringValue() + public function testGetElementHtmlWithNonStringValue(): void { // Mock the AbstractElement $elementMock = $this->createMock(AbstractElement::class); diff --git a/Test/Unit/Helper/DataTest.php b/Test/Unit/Helper/DataTest.php index 1063ae1d1344ad560e4d3388fb7dd551048787e2..ca45a68a744fcd77185afac7bf655905f75a8e38 100644 --- a/Test/Unit/Helper/DataTest.php +++ b/Test/Unit/Helper/DataTest.php @@ -51,7 +51,7 @@ class DataTest extends TestCase $this->helper = new Data($this->contextMock, $this->moduleListMock); } - public function testIsEnabled() + public function testIsEnabled(): void { // Mock the scopeConfig to return '1' when checking if the module is enabled $this->scopeConfigMock->method('getValue') @@ -62,7 +62,7 @@ class DataTest extends TestCase $this->assertEquals('1', $result); } - public function testIsEnabledReturnsNullWhenDisabled() + public function testIsEnabledReturnsNullWhenDisabled(): void { // Mock the scopeConfig to return null when the module is disabled $this->scopeConfigMock->method('getValue') @@ -73,7 +73,7 @@ class DataTest extends TestCase $this->assertNull($result); } - public function testGetDebugStatus() + public function testGetDebugStatus(): void { // Mock the scopeConfig to return '1' when checking if debug is enabled $this->scopeConfigMock->method('getValue') @@ -84,7 +84,7 @@ class DataTest extends TestCase $this->assertEquals('1', $result); } - public function testGetDebugStatusReturnsNullWhenDisabled() + public function testGetDebugStatusReturnsNullWhenDisabled(): void { // Mock the scopeConfig to return null when debug is disabled $this->scopeConfigMock->method('getValue') @@ -95,7 +95,7 @@ class DataTest extends TestCase $this->assertNull($result); } - public function testGetExtensionVersion() + public function testGetExtensionVersion(): void { // Mock the moduleList to return a specific version $this->moduleListMock->method('getOne') @@ -106,7 +106,7 @@ class DataTest extends TestCase $this->assertEquals('1.2.3', $result); } - public function testGetExtensionVersionReturnsNAWhenModuleNotFound() + public function testGetExtensionVersionReturnsNAWhenModuleNotFound(): void { // Mock the moduleList to return null (module not found) $this->moduleListMock->method('getOne') @@ -117,7 +117,7 @@ class DataTest extends TestCase $this->assertEquals('N/A', $result); } - public function testLogWithDebugEnabled() + public function testLogWithDebugEnabled(): void { // Mock the scopeConfig to return '1' when checking if debug is enabled $this->scopeConfigMock->method('getValue') @@ -132,7 +132,7 @@ class DataTest extends TestCase $this->helper->log('Test message'); } - public function testLogWithDebugDisabled() + public function testLogWithDebugDisabled(): void { // Mock the scopeConfig to return null when debug is disabled $this->scopeConfigMock->method('getValue') @@ -146,7 +146,7 @@ class DataTest extends TestCase $this->helper->log('Test message'); } - public function testLogWithSeparator() + public function testLogWithSeparator(): void { // Mock the scopeConfig to return '1' when checking if debug is enabled $this->scopeConfigMock->method('getValue') diff --git a/Test/Unit/Model/Carrier/AdditionalInfoTest.php b/Test/Unit/Model/Carrier/AdditionalInfoTest.php index c9a95b22d4a4cdb82cce3b182b6d99a3a2cecacd..4c143753a95f45dfba0234fac4d60dff151fdcdc 100644 --- a/Test/Unit/Model/Carrier/AdditionalInfoTest.php +++ b/Test/Unit/Model/Carrier/AdditionalInfoTest.php @@ -10,9 +10,16 @@ use PHPUnit\Framework\TestCase; class AdditionalInfoTest extends TestCase { + /** @var AdditionalInfo */ private $additionalInfo; + + /** @var Http|\PHPUnit\Framework\MockObject\MockObject */ private $requestMock; + + /** @var CountryFactory|\PHPUnit\Framework\MockObject\MockObject */ private $countryFactoryMock; + + /** @var Country|\PHPUnit\Framework\MockObject\MockObject */ private $countryMock; protected function setUp(): void @@ -30,7 +37,7 @@ class AdditionalInfoTest extends TestCase $this->additionalInfo = new AdditionalInfo($this->countryFactoryMock, $this->requestMock); } - public function testGetCountryName() + public function testGetCountryName(): void { $countryId = 'US'; @@ -42,7 +49,7 @@ class AdditionalInfoTest extends TestCase $this->assertEquals('United States', $result); } - public function testGetDestComp() + public function testGetDestComp(): void { $requestBody = json_encode([ 'address' => [ @@ -58,7 +65,7 @@ class AdditionalInfoTest extends TestCase $this->assertEquals('Test Company', $result); } - public function testGetDestCompReturnsEmptyStringWhenNotSet() + public function testGetDestCompReturnsEmptyStringWhenNotSet(): void { $requestBody = json_encode([]); @@ -70,7 +77,7 @@ class AdditionalInfoTest extends TestCase $this->assertEquals('', $result); } - public function testGetSuburb() + public function testGetSuburb(): void { $requestBody = json_encode([ 'address' => [ @@ -88,7 +95,7 @@ class AdditionalInfoTest extends TestCase $this->assertEquals('Test Suburb', $result); } - public function testGetSuburbReturnsEmptyStringWhenNotSet() + public function testGetSuburbReturnsEmptyStringWhenNotSet(): void { $requestBody = json_encode([]); @@ -100,7 +107,7 @@ class AdditionalInfoTest extends TestCase $this->assertEquals('', $result); } - public function testGetDestTelephone() + public function testGetDestTelephone(): void { $requestBody = json_encode([ 'address' => [ @@ -116,7 +123,7 @@ class AdditionalInfoTest extends TestCase $this->assertEquals('123456789', $result); } - public function testGetDestTelephoneReturnsEmptyStringWhenNotSet() + public function testGetDestTelephoneReturnsEmptyStringWhenNotSet(): void { $requestBody = json_encode([]); diff --git a/Test/Unit/Model/Carrier/BobGoTest.php b/Test/Unit/Model/Carrier/BobGoTest.php index e18a792a6f771af6c264a4318cecbd845e729d7c..a40c30247f1825ac373fab6db0b7042dab157c69 100644 --- a/Test/Unit/Model/Carrier/BobGoTest.php +++ b/Test/Unit/Model/Carrier/BobGoTest.php @@ -13,11 +13,10 @@ use Magento\Directory\Model\RegionFactory; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\Request\Http as MagentoHttp; use Magento\Framework\Controller\Result\JsonFactory; -use Magento\Framework\DataObject; use Magento\Framework\HTTP\Client\Curl; use Magento\Framework\HTTP\Client\CurlFactory; use Magento\Framework\Xml\Security; -use Magento\Quote\Model\Quote\Address\RateRequest; +use Magento\Quote\Model\Quote\Address\RateRequest; // Correct class reference use Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory; use Magento\Quote\Model\Quote\Address\RateResult\MethodFactory; use Magento\Shipping\Model\Rate\ResultFactory; @@ -29,12 +28,25 @@ use Psr\Log\LoggerInterface; class BobGoTest extends TestCase { + /** @var BobGo */ private $bobGo; + + /** @var StoreManagerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $storeManagerMock; + + /** @var ScopeConfigInterface|\PHPUnit\Framework\MockObject\MockObject */ private $scopeConfigMock; + + /** @var Curl|\PHPUnit\Framework\MockObject\MockObject */ private $curlMock; + + /** @var ResultFactory|\PHPUnit\Framework\MockObject\MockObject */ private $resultFactoryMock; + + /** @var MethodFactory|\PHPUnit\Framework\MockObject\MockObject */ private $methodFactoryMock; + + /** @var AdditionalInfo|\PHPUnit\Framework\MockObject\MockObject */ private $additionalInfoMock; protected function setUp(): void @@ -98,10 +110,7 @@ class BobGoTest extends TestCase $this->bobGo->additionalInfo = $this->additionalInfoMock; } - -// Your test methods go here... - -public function testGetBaseUrl() + public function testGetBaseUrl(): void { $storeMock = $this->createMock(\Magento\Store\Model\Store::class); $this->storeManagerMock->method('getStore')->willReturn($storeMock); @@ -112,7 +121,7 @@ public function testGetBaseUrl() $this->assertEquals('example.com', $baseUrl); } - public function testGetDestComp() + public function testGetDestComp(): void { $this->additionalInfoMock->method('getDestComp')->willReturn('Test Company'); @@ -121,7 +130,7 @@ public function testGetBaseUrl() $this->assertEquals('Test Company', $destComp); } - public function testGetDestSuburb() + public function testGetDestSuburb(): void { $this->additionalInfoMock->method('getSuburb')->willReturn('Test Suburb'); @@ -130,7 +139,7 @@ public function testGetBaseUrl() $this->assertEquals('Test Suburb', $destSuburb); } - public function testGetRates() + public function testGetRates(): void { $payload = [ 'identifier' => 'example.com', @@ -168,7 +177,7 @@ public function testGetBaseUrl() $this->assertEquals('rate-1', $rates['rates'][0]['id']); } - public function testProcessAdditionalValidation() + public function testProcessAdditionalValidation(): void { // Create a mock for Product $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); @@ -179,7 +188,7 @@ public function testGetBaseUrl() $quoteItemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class); $quoteItemMock->method('getProduct')->willReturn($productMock); - // Create a real RateRequest object + // Create a real RateRequest object from the correct namespace $rateRequest = new RateRequest(); $rateRequest->setDestPostcode('12345'); $rateRequest->setDestCountryId('ZA'); @@ -189,6 +198,4 @@ public function testGetBaseUrl() $this->assertInstanceOf(BobGo::class, $result); } - - } diff --git a/Test/Unit/Model/Carrier/USubsTest.php b/Test/Unit/Model/Carrier/USubsTest.php index e1c1f0692025190362ab486aaeb060bcfe15f0d7..dc2d393d541183d64d35be3f4c49af1acd7a1cfc 100644 --- a/Test/Unit/Model/Carrier/USubsTest.php +++ b/Test/Unit/Model/Carrier/USubsTest.php @@ -25,7 +25,7 @@ class USubsTest extends TestCase $this->uSubs = new USubs($this->requestMock); } - public function testGetDestComp() + public function testGetDestComp(): void { $requestBody = json_encode([ 'address' => [ @@ -33,6 +33,7 @@ class USubsTest extends TestCase ] ]); + // Ensure getContent returns a valid JSON string $this->requestMock->method('getContent') ->willReturn($requestBody); @@ -41,19 +42,18 @@ class USubsTest extends TestCase $this->assertEquals('Test Company', $result); } - public function testGetDestCompReturnsEmptyStringWhenNotSet() + public function testGetDestCompReturnsEmptyStringWhenNotSet(): void { - $requestBody = json_encode([]); - + // Return an empty JSON object $this->requestMock->method('getContent') - ->willReturn($requestBody); + ->willReturn('{}'); $result = $this->uSubs->getDestComp(); $this->assertEquals('', $result); } - public function testGetDestCompReturnsEmptyStringWhenInvalidStructure() + public function testGetDestCompReturnsEmptyStringWhenInvalidStructure(): void { // Test case where the JSON structure is invalid $requestBody = json_encode([ diff --git a/Test/Unit/Model/Source/FreemethodTest.php b/Test/Unit/Model/Source/FreemethodTest.php index 7b70d1111a52e026388ac20f8e95dec31c0f1598..0dc63f485bcb14bcb151c33017ddea39f1aa7463 100644 --- a/Test/Unit/Model/Source/FreemethodTest.php +++ b/Test/Unit/Model/Source/FreemethodTest.php @@ -27,7 +27,7 @@ class FreemethodTest extends TestCase $this->freemethod = new Freemethod($this->bobGoMock); } - public function testToOptionArray() + public function testToOptionArray(): void { // Call the method under test $result = $this->freemethod->toOptionArray(); diff --git a/Test/Unit/Model/Source/GenericTest.php b/Test/Unit/Model/Source/GenericTest.php index b9e0cfac8e10218b17e2db051ff1d0bd5704c01a..abb2441c42e38d292c64be7853dc302069bf93a0 100644 --- a/Test/Unit/Model/Source/GenericTest.php +++ b/Test/Unit/Model/Source/GenericTest.php @@ -33,7 +33,7 @@ class GenericTest extends TestCase $codeProperty->setValue($this->generic, 'test_code'); } - public function testToOptionArray() + public function testToOptionArray(): void { // Set up the expected return value from the BobGo's getCode method $this->bobGoMock->method('getCode')->with('test_code')->willReturn([ @@ -53,7 +53,7 @@ class GenericTest extends TestCase $this->assertEquals($expected, $result); } - public function testToOptionArrayWithEmptyConfig() + public function testToOptionArrayWithEmptyConfig(): void { // Set up the getCode method to return null $this->bobGoMock->method('getCode')->with('test_code')->willReturn(null); diff --git a/Test/Unit/Observer/ConfigChangeObserverTest.php b/Test/Unit/Observer/ConfigChangeObserverTest.php index 2838be88f2ce31b2293db5cf2aec092d38ecdbaa..695f03a60111ec5d2c363862944976106bc56516 100644 --- a/Test/Unit/Observer/ConfigChangeObserverTest.php +++ b/Test/Unit/Observer/ConfigChangeObserverTest.php @@ -46,7 +46,7 @@ class ConfigChangeObserverTest extends TestCase ); } - public function testExecuteWithActiveCarrierAndSuccessfulConnection() + public function testExecuteWithActiveCarrierAndSuccessfulConnection(): void { // Set up the observer mock $observerMock = $this->createMock(Observer::class); @@ -68,7 +68,7 @@ class ConfigChangeObserverTest extends TestCase $this->observer->execute($observerMock); } - public function testExecuteWithActiveCarrierAndFailedConnection() + public function testExecuteWithActiveCarrierAndFailedConnection(): void { // Set up the observer mock $observerMock = $this->createMock(Observer::class); @@ -93,7 +93,7 @@ class ConfigChangeObserverTest extends TestCase $this->observer->execute($observerMock); } - public function testExecuteWithInactiveCarrier() + public function testExecuteWithInactiveCarrier(): void { // Set up the observer mock $observerMock = $this->createMock(Observer::class); diff --git a/Test/Unit/Plugin/AddWeightUnitToOrderPluginTest.php b/Test/Unit/Plugin/AddWeightUnitToOrderPluginTest.php index 6dc3e80325cef30ff66cdc36f6beae8e094a392d..d4bf6b6a7bf13d9d841da2c05dc13126e06467f2 100644 --- a/Test/Unit/Plugin/AddWeightUnitToOrderPluginTest.php +++ b/Test/Unit/Plugin/AddWeightUnitToOrderPluginTest.php @@ -39,7 +39,7 @@ class AddWeightUnitToOrderPluginTest extends TestCase ); } - public function testBeforeSaveWithLbsWeightUnit() + public function testBeforeSaveWithLbsWeightUnit(): void { // Mock the OrderInterface $orderMock = $this->createMock(OrderInterface::class); @@ -68,7 +68,7 @@ class AddWeightUnitToOrderPluginTest extends TestCase $this->assertSame([$orderMock], $result); } - public function testBeforeSaveWithNonLbsWeightUnit() + public function testBeforeSaveWithNonLbsWeightUnit(): void { // Mock the OrderInterface $orderMock = $this->createMock(OrderInterface::class); diff --git a/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php b/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php index 6ee232d891058d788bf5edad9df46fa79062c338..4d8bd9d0a66447160396590cc4b878cb8acfad25 100644 --- a/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php +++ b/Test/Unit/Plugin/Block/DataProviders/Tracking/ChangeTitleTest.php @@ -21,7 +21,7 @@ class ChangeTitleTest extends TestCase $this->plugin = new ChangeTitle(); } - public function testAfterGetTitleWithBobGoCarrier() + public function testAfterGetTitleWithBobGoCarrier(): void { // Create a custom Status object with BobGo carrier $status = $this->getMockBuilder(Status::class) @@ -40,7 +40,7 @@ class ChangeTitleTest extends TestCase $this->assertEquals('Expected delivery:', $result); } - public function testAfterGetTitleWithOtherCarrier() + public function testAfterGetTitleWithOtherCarrier(): void { // Create a custom Status object with a different carrier $status = $this->getMockBuilder(Status::class) diff --git a/Test/Unit/Plugin/Block/Tracking/PopUpDeliveryDateTest.php b/Test/Unit/Plugin/Block/Tracking/PopUpDeliveryDateTest.php index 4b04a208c83ea6370591449eb1e267dd309e1ff9..6c01770254cd04592f5fbafa8bfccacd4d6bfd27 100644 --- a/Test/Unit/Plugin/Block/Tracking/PopUpDeliveryDateTest.php +++ b/Test/Unit/Plugin/Block/Tracking/PopUpDeliveryDateTest.php @@ -20,48 +20,60 @@ class PopupDeliveryDateTest extends TestCase $this->plugin = new PopupDeliveryDate(); } - public function testAfterFormatDeliveryDateTimeWithBobGoCarrier() + public function testAfterFormatDeliveryDateTimeWithBobGoCarrier(): void { - // Mock the Status class with BobGo carrier code - $statusMock = $this->createMock(Status::class); - $statusMock->method('getCarrier')->willReturn('bobgo_carrier_code'); + // Create an instance of the Status class + $status = new Status(); + $status->setCarrier('bobgo_carrier_code'); // Mock the Popup class $popupMock = $this->createMock(Popup::class); $popupMock->method('getTrackingInfo')->willReturn([ - ['tracking_info' => $statusMock], + ['tracking_info' => $status], ]); // Mock the formatDeliveryDate method - $popupMock->method('formatDeliveryDate')->with('2024-08-19')->willReturn('Aug 19, 2024'); + $popupMock->method('formatDeliveryDate') + ->with('2024-08-19') + ->willReturn('Aug 19, 2024'); // Call the plugin method afterFormatDeliveryDateTime - $result = $this->plugin->afterFormatDeliveryDateTime($popupMock, 'Aug 19, 2024 10:00 AM', '2024-08-19', '10:00 AM'); + $result = $this->plugin->afterFormatDeliveryDateTime( + $popupMock, + 'Aug 19, 2024 10:00 AM', + '2024-08-19', + '10:00 AM' + ); // Assert that the time was stripped for BobGo carrier $this->assertEquals('Aug 19, 2024', $result); } - public function testAfterFormatDeliveryDateTimeWithOtherCarrier() + public function testAfterFormatDeliveryDateTimeWithOtherCarrier(): void { - // Mock the Status class with a different carrier code - $statusMock = $this->createMock(Status::class); - $statusMock->method('getCarrier')->willReturn('other_carrier_code'); + // Create an instance of the Status class + $status = new Status(); + $status->setCarrier('other_carrier_code'); // Mock the Popup class $popupMock = $this->createMock(Popup::class); $popupMock->method('getTrackingInfo')->willReturn([ - ['tracking_info' => $statusMock], + ['tracking_info' => $status], ]); // Call the plugin method afterFormatDeliveryDateTime - $result = $this->plugin->afterFormatDeliveryDateTime($popupMock, 'Aug 19, 2024 10:00 AM', '2024-08-19', '10:00 AM'); + $result = $this->plugin->afterFormatDeliveryDateTime( + $popupMock, + 'Aug 19, 2024 10:00 AM', + '2024-08-19', + '10:00 AM' + ); // Assert that the time remains unchanged for other carriers $this->assertEquals('Aug 19, 2024 10:00 AM', $result); } - public function testGetCarrierWithNoTrackingInfo() + public function testGetCarrierWithNoTrackingInfo(): void { // Mock the Popup class with no tracking info $popupMock = $this->createMock(Popup::class); diff --git a/Test/Unit/Plugin/Checkout/Block/LayoutProcessorPluginTest.php b/Test/Unit/Plugin/Checkout/Block/LayoutProcessorPluginTest.php deleted file mode 100644 index 9799548a1fbe953358dc84a90fc448518b41c68c..0000000000000000000000000000000000000000 --- a/Test/Unit/Plugin/Checkout/Block/LayoutProcessorPluginTest.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php - -namespace BobGroup\BobGo\Test\Unit\Plugin\Checkout\Block; - -use BobGroup\BobGo\Plugin\Checkout\Block\LayoutProcessorPlugin; -use Magento\Checkout\Block\Checkout\LayoutProcessor; -use PHPUnit\Framework\TestCase; - -class LayoutProcessorPluginTest extends TestCase -{ - /** - * @var LayoutProcessorPlugin - */ - private $plugin; - - /** - * @var \PHPUnit\Framework\MockObject\MockObject - */ - private $layoutProcessorMock; - - protected function setUp(): void - { - // Instantiate the LayoutProcessorPlugin - $this->plugin = new LayoutProcessorPlugin(); - - // Mock the LayoutProcessor class - $this->layoutProcessorMock = $this->createMock(LayoutProcessor::class); - } - - public function testAfterProcessWithValidJsLayout() - { - // Mock the jsLayout array with the necessary structure - $jsLayout = [ - 'components' => [ - 'checkout' => [ - 'children' => [ - 'steps' => [ - 'children' => [ - 'shipping-step' => [ - 'children' => [ - 'shippingAddress' => [ - 'children' => [ - 'shipping-address-fieldset' => [ - 'children' => [] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ]; - - // Call the plugin's afterProcess method - $result = $this->plugin->afterProcess($this->layoutProcessorMock, $jsLayout); - - // Assert that the suburb field has been added to the jsLayout - $this->assertArrayHasKey('suburb', $result['components']['checkout']['children']['steps']['children'] - ['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']); - - $suburbField = $result['components']['checkout']['children']['steps']['children']['shipping-step']['children'] - ['shippingAddress']['children']['shipping-address-fieldset']['children']['suburb']; - - $this->assertEquals('Suburb', $suburbField['label']); - $this->assertEquals(true, $suburbField['visible']); - $this->assertEquals('shippingAddress.custom_attributes.suburb', $suburbField['dataScope']); - } - - public function testAfterProcessWithInvalidJsLayout() - { - // Mock the jsLayout array with an incomplete structure - $jsLayout = [ - 'components' => [] - ]; - - // Call the plugin's afterProcess method - $result = $this->plugin->afterProcess($this->layoutProcessorMock, $jsLayout); - - // Assert that the jsLayout remains unchanged - $this->assertEquals($jsLayout, $result); - } -}