Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexTableSwitcherTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 use PHPUnit\Framework\TestCase;
17 
21 class IndexTableSwitcherTest extends TestCase
22 {
26  private $indexTableSwitcher;
27 
31  private $indexName;
32 
36  private $resourceConnection;
37 
41  private $indexNameResolver;
42 
46  private $adapter;
47 
51  protected function setUp()
52  {
53  parent::setUp();
54 
55  $objectManager = new ObjectManager($this);
56  $this->indexName = $this->createMock(IndexName::class);
57  $this->resourceConnection = $this->createMock(ResourceConnection::class);
58  $this->indexNameResolver = $this->createMock(IndexNameResolverInterface::class);
59  $this->adapter = $this->createMock(AdapterInterface::class);
60 
61  $this->indexTableSwitcher = $objectManager->getObject(
62  IndexTableSwitcher::class,
63  [
64  'resourceConnection' => $this->resourceConnection,
65  'indexNameResolver' => $this->indexNameResolver,
66  ]
67  );
68  }
69 
70  public function testSwitch()
71  {
72  $connectionName = 'testConnection';
73  $tableName = 'some_table_name';
74  $toRename =
75  [
76  [
77  'oldName' => $tableName,
78  'newName' => $tableName . '_outdated',
79  ],
80  [
81  'oldName' => $tableName . '_replica',
82  'newName' => $tableName,
83  ],
84  [
85  'oldName' => $tableName . '_outdated',
86  'newName' => $tableName . '_replica',
87  ],
88  ];
89 
90  $this->resourceConnection->expects($this->once())->method('getConnection')
91  ->with($connectionName)->willReturn($this->adapter);
92  $this->indexNameResolver->expects($this->once())->method('resolveName')
93  ->with($this->indexName)->willReturn($tableName);
94  $this->adapter->expects($this->once())->method('renameTablesBatch')
95  ->with($toRename);
96 
97  $this->indexTableSwitcher->switch($this->indexName, $connectionName);
98  }
99 }
$tableName
Definition: trigger.php:13
$objectManager
Definition: bootstrap.php:17