|
| 1 | +<?php |
| 2 | +/************************************************************************ |
| 3 | + * |
| 4 | + * Copyright 2023 Adobe |
| 5 | + * All Rights Reserved. |
| 6 | + * |
| 7 | + * NOTICE: All information contained herein is, and remains |
| 8 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 9 | + * and technical concepts contained herein are proprietary to Adobe |
| 10 | + * and its suppliers and are protected by all applicable intellectual |
| 11 | + * property laws, including trade secret and copyright laws. |
| 12 | + * Dissemination of this information or reproduction of this material |
| 13 | + * is strictly forbidden unless prior written permission is obtained |
| 14 | + * from Adobe. |
| 15 | + * *********************************************************************** |
| 16 | + */ |
| 17 | +declare(strict_types=1); |
| 18 | + |
| 19 | +namespace Magento\Catalog; |
| 20 | + |
| 21 | +use Magento\Framework\App\ObjectManager; |
| 22 | +use Magento\Framework\App\ResourceConnection; |
| 23 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 24 | +use Monolog\Test\TestCase; |
| 25 | + |
| 26 | +class DbSchemaTest extends TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @param string $tableName |
| 30 | + * @param string $indexName |
| 31 | + * @param array $columns |
| 32 | + * @param string $indexType |
| 33 | + * @return void |
| 34 | + * @dataProvider indexDataProvider |
| 35 | + */ |
| 36 | + public function testIndex( |
| 37 | + string $tableName, |
| 38 | + string $indexName, |
| 39 | + array $columns, |
| 40 | + string $indexType = AdapterInterface::INDEX_TYPE_INDEX, |
| 41 | + ): void { |
| 42 | + $connection = ObjectManager::getInstance()->get(ResourceConnection::class)->getConnection(); |
| 43 | + $indexes = $connection->getIndexList($tableName); |
| 44 | + $this->assertArrayHasKey($indexName, $indexes); |
| 45 | + $this->assertSame($columns, $indexes[$indexName]['COLUMNS_LIST']); |
| 46 | + $this->assertSame($indexType, $indexes[$indexName]['INDEX_TYPE']); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @return array[] |
| 51 | + */ |
| 52 | + public function indexDataProvider(): array |
| 53 | + { |
| 54 | + return [ |
| 55 | + [ |
| 56 | + 'catalog_product_index_price_tmp', |
| 57 | + 'CAT_PRD_IDX_PRICE_TMP_ENTT_ID_CSTR_GROUP_ID_WS_ID', |
| 58 | + ['entity_id', 'customer_group_id', 'website_id'] |
| 59 | + ] |
| 60 | + ]; |
| 61 | + } |
| 62 | +} |
0 commit comments