DatabaseTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Test\Integrity;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. class DatabaseTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * Assure that there are no redundant indexes declared in database
  12. */
  13. public function testDuplicateKeys()
  14. {
  15. if (!defined('PERCONA_TOOLKIT_BIN_DIR')) {
  16. $this->markTestSkipped('Path to Percona Toolkit is not specified.');
  17. }
  18. $checkerPath = PERCONA_TOOLKIT_BIN_DIR . '/pt-duplicate-key-checker';
  19. $db = Bootstrap::getInstance()->getBootstrap()->getApplication()->getDbInstance();
  20. $command = $checkerPath . ' -d ' . $db->getSchema()
  21. . ' h=' . $db->getHost()['db-host'] . ',u=' . $db->getUser() . ',p=' . $db->getPassword();
  22. exec($command, $output, $exitCode);
  23. $this->assertEquals(0, $exitCode);
  24. $output = implode(PHP_EOL, $output);
  25. if (preg_match('/Total Duplicate Indexes\s+(\d+)/', $output, $matches)) {
  26. $this->fail($matches[1] . ' duplicate indexes found.' . PHP_EOL . PHP_EOL . $output);
  27. }
  28. }
  29. }