/
githubmirror
/
magento2
Обзор
Документация
Войти
/
githubmirror
/
magento2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
2.4-develop
dev/tests/integration/testsuite/Magento/Directory/Model/RegionTest.php
94 строки
3 KB
Raj Mohan R
AC-16236::Upgrade Core Test Framework to PHPUnit 12 and Migrate from PHPUnit 10
11 фев 2026, 13:51
11 фев 2026, 13:51
152ed41
Код
Авторство
О чём код?
<?php /** * Copyright 2020 Adobe * All Rights Reserved. */ declare(strict_types=1); namespace Magento\Directory\Model; use Magento\Directory\Model\ResourceModel\Region\CollectionFactory as RegionCollectionFactory; use Magento\Directory\Setup\Patch\Data\UpdateRegionNamesForSwitzerland as SwitzerlandRegionData; use Magento\Framework\AppInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use SebastianBergmann\RecursionContext\InvalidArgumentException; use Magento\Framework\Exception\LocalizedException; class RegionTest extends TestCase { /** * @var Country */ private $country; /** * @var RegionCollectionFactory */ private $regionCollectionFactory; /** * @inheritDoc */ protected function setUp(): void { $this->country = Bootstrap::getObjectManager()->create(Country::class); $this->regionCollectionFactory = Bootstrap::getObjectManager()->create(RegionCollectionFactory::class); } /** * Verify country has regions. * * @param string $countryId * * @throws ExpectationFailedException * @throws InvalidArgumentException * @throws LocalizedException */ #[DataProvider('getCountryIdDataProvider')] public function testCountryHasRegions(string $countryId): void { $country = $this->country->loadByCode($countryId); $region = $country->getRegions()->getItems(); $this->assertNotEmpty($region, 'Country ' . $countryId . ' not have regions'); } /** * Data provider for testCountryHasRegions * * @return array */ public static function getCountryIdDataProvider(): array { return [ ['US'], ['CA'], ['CN'], ['IN'], ['AU'], ['BE'], ['CO'], ['MX'], ['PL'], ['IT'], ['BG'], ['AR'], ['BO'], ['CL'], ['EC'], ['GY'], ['PY'], ['PE'], ['SR'], ['VE'], ['PT'], ['IS'], ['SE'], ['GR'], ['DK'], ['AL'], ['BY'], ['UA'], ]; } /** * Verify updated Switzerland regions * * @throws ExpectationFailedException * @throws InvalidArgumentException */ public function testUpdatedSwitzerlandRegions(): void { $regionCollection = $this->regionCollectionFactory->create(); $regionCollection->addCountryFilter(SwitzerlandRegionData::SWITZERLAND_COUNTRY_CODE); $regionCollection->addRegionCodeFilter( array_keys(SwitzerlandRegionData::SWITZERLAND_COUNTRY_REGION_DATA_TO_UPDATE) ); $regionCollection->addBindParam(':region_locale', AppInterface::DISTRO_LOCALE_CODE); foreach ($regionCollection->getItems() as $regionItem) { $code = $regionItem->getData('code'); $expectRegionName = SwitzerlandRegionData::SWITZERLAND_COUNTRY_REGION_DATA_TO_UPDATE[$code] ?? null; $this->assertEquals($expectRegionName, $regionItem->getData('default_name')); $this->assertEquals($expectRegionName, $regionItem->getData('name')); } } }