@@ -1301,8 +1301,6 @@ function (...$args) use ($parentItem, $parentMapped, $childMapped) {
13011301 */
13021302 public function testConstructorFallsBackToOmForOptionalDependencies (): void
13031303 {
1304- // Do not call getInstance() in unit context; no original OM to restore
1305-
13061304 $ extFactory = $ this ->createMock (QuoteDetailsItemExtensionInterfaceFactory::class);
13071305 $ ext = new class implements \Magento \Tax \Api \Data \QuoteDetailsItemExtensionInterface
13081306 {
@@ -1331,13 +1329,10 @@ public function getPriceForTaxCalculation()
13311329 }
13321330 };
13331331 $ extFactory ->method ('create ' )->willReturn ($ ext );
1334-
13351332 $ customerAccount = $ this ->createMock (CustomerAccountManagement::class);
1336-
13371333 $ om = $ this ->getMockBuilder (\Magento \Framework \App \ObjectManager::class)
13381334 ->disableOriginalConstructor ()
1339- ->onlyMethods (['get ' ])
1340- ->getMock ();
1335+ ->onlyMethods (['get ' ])->getMock ();
13411336 $ om ->method ('get ' )->willReturnCallback (function ($ class ) use ($ extFactory , $ customerAccount ) {
13421337 if ($ class === QuoteDetailsItemExtensionInterfaceFactory::class) {
13431338 return $ extFactory ;
@@ -1347,10 +1342,8 @@ public function getPriceForTaxCalculation()
13471342 }
13481343 $ this ->fail ('Unexpected ObjectManager::get call for ' . $ class );
13491344 });
1350-
13511345 \Magento \Framework \App \ObjectManager::setInstance ($ om );
13521346 try {
1353- // Partially mock to safely execute populateAddressData without touching real mapAddress internals
13541347 $ sut = $ this ->getMockBuilder (CommonTaxCollector::class)
13551348 ->setConstructorArgs ([
13561349 $ this ->taxConfig ,
@@ -1361,69 +1354,47 @@ public function getPriceForTaxCalculation()
13611354 $ this ->customerAddressFactory ,
13621355 $ this ->customerAddressRegionFactory ,
13631356 $ this ->taxHelper ,
1364- null , // force fallback to OM for QuoteDetailsItemExtensionInterfaceFactory
1365- null // force fallback to OM for CustomerAccountManagement
1366- ])
1367- ->onlyMethods (['mapAddress ' ])
1368- ->getMock ();
1369-
1370- // Verify setPriceForTaxCalculation uses the ext factory from OM
1357+ null , null ])
1358+ ->onlyMethods (['mapAddress ' ])->getMock ();
13711359 $ ref = new \ReflectionClass (CommonTaxCollector::class);
13721360 $ method = $ ref ->getMethod ('setPriceForTaxCalculation ' );
13731361 $ method ->setAccessible (true );
1374-
1375- // verify via reading back from stub after invocation
1376-
13771362 $ qdi = $ this ->createMock (QuoteDetailsItemInterface::class);
13781363 $ qdi ->method ('getExtensionAttributes ' )->willReturn (null );
13791364 $ qdi ->expects ($ this ->once ())->method ('setExtensionAttributes ' )->with ($ ext )->willReturnSelf ();
13801365
13811366 $ method ->invoke ($ sut , $ qdi , 12.34 );
13821367 $ this ->assertSame (12.34 , $ ext ->getPriceForTaxCalculation ());
1383-
1384- // Verify CustomerAccountManagement from OM is used in populateAddressData default-billing path
13851368 $ billingMapped = $ this ->createMock (CustomerAddress::class);
13861369 $ shippingMapped = $ this ->createMock (CustomerAddress::class);
13871370 $ sut ->method ('mapAddress ' )->willReturnOnConsecutiveCalls ($ billingMapped , $ shippingMapped );
1388-
13891371 $ quoteDetails = $ this ->createMock (\Magento \Tax \Api \Data \QuoteDetailsInterface::class);
13901372 $ quoteDetails ->expects ($ this ->once ())->method ('setBillingAddress ' )->with ($ billingMapped )->willReturnSelf ();
13911373 $ quoteDetails ->expects ($ this ->once ())
1392- ->method ('setShippingAddress ' )
1393- ->with ($ shippingMapped )
1394- ->willReturnSelf ();
1395-
1374+ ->method ('setShippingAddress ' )->with ($ shippingMapped )->willReturnSelf ();
13961375 $ billingAddressFromQuote = $ this ->createMock (QuoteAddress::class);
1397-
13981376 $ customerAccount ->expects ($ this ->once ())
13991377 ->method ('getDefaultBillingAddress ' )
1400- ->with (15 )
1401- ->willReturn (null );
1378+ ->with (15 )->willReturn (null );
14021379
14031380 $ quote = $ this ->getMockBuilder (\stdClass::class)
1404- ->addMethods (['isVirtual ' , 'getCustomerId ' , 'getBillingAddress ' ])
1405- ->getMock ();
1381+ ->addMethods (['isVirtual ' , 'getCustomerId ' , 'getBillingAddress ' ])->getMock ();
14061382 $ quote ->method ('isVirtual ' )->willReturn (true );
14071383 $ quote ->method ('getCustomerId ' )->willReturn (15 );
14081384 $ quote ->method ('getBillingAddress ' )->willReturn ($ billingAddressFromQuote );
1409-
14101385 $ address = $ this ->getMockBuilder (QuoteAddress::class)
14111386 ->onlyMethods (['getQuote ' , 'getCountryId ' ])
14121387 ->addMethods (['getAddressType ' ])
1413- ->disableOriginalConstructor ()
1414- ->getMock ();
1388+ ->disableOriginalConstructor ()->getMock ();
14151389 $ address ->method ('getAddressType ' )->willReturn (QuoteAddress::ADDRESS_TYPE_BILLING );
14161390 $ address ->method ('getCountryId ' )->willReturn (null );
14171391 $ address ->method ('getQuote ' )->willReturn ($ quote );
1418-
14191392 $ sut ->populateAddressData ($ quoteDetails , $ address );
14201393 $ this ->assertTrue (true );
14211394 } finally {
1422- // Reset ObjectManager to a dummy mock implementing ObjectManagerInterface
14231395 $ resetOm = $ this ->getMockBuilder (\Magento \Framework \App \ObjectManager::class)
14241396 ->disableOriginalConstructor ()
1425- ->onlyMethods (['get ' ])
1426- ->getMock ();
1397+ ->onlyMethods (['get ' ])->getMock ();
14271398 \Magento \Framework \App \ObjectManager::setInstance ($ resetOm );
14281399 }
14291400 }
0 commit comments