ResourceTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Test for \Magento\Framework\Model\ResourceModel
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Model;
  9. class ResourceTest extends \PHPUnit\Framework\TestCase
  10. {
  11. /**
  12. * @var \Magento\Framework\App\ResourceConnection
  13. */
  14. protected $_model;
  15. protected function setUp()
  16. {
  17. $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
  18. ->create(\Magento\Framework\App\ResourceConnection::class);
  19. }
  20. public function testGetTableName()
  21. {
  22. $tablePrefix = 'prefix_';
  23. $tableSuffix = 'suffix';
  24. $tableNameOrig = 'store_website';
  25. $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  26. \Magento\Framework\App\ResourceConnection::class,
  27. ['tablePrefix' => 'prefix_']
  28. );
  29. $tableName = $this->_model->getTableName([$tableNameOrig, $tableSuffix]);
  30. $this->assertContains($tablePrefix, $tableName);
  31. $this->assertContains($tableSuffix, $tableName);
  32. $this->assertContains($tableNameOrig, $tableName);
  33. }
  34. /**
  35. * Init profiler during creation of DB connect
  36. * @return void
  37. */
  38. public function testProfilerInit()
  39. {
  40. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  41. /** @var \Magento\Framework\DB\Adapter\Pdo\Mysql $connection */
  42. $connection = $objectManager->create(
  43. \Magento\TestFramework\Db\Adapter\Mysql::class,
  44. [
  45. 'config' => [
  46. 'profiler' => [
  47. 'class' => \Magento\Framework\Model\ResourceModel\Db\Profiler::class,
  48. 'enabled' => 'true',
  49. ],
  50. 'username' => 'username',
  51. 'password' => 'password',
  52. 'host' => 'host',
  53. 'type' => 'type',
  54. 'dbname' => 'dbname',
  55. ]
  56. ]
  57. );
  58. /** @var \Magento\Framework\Model\ResourceModel\Db\Profiler $profiler */
  59. $profiler = $connection->getProfiler();
  60. $this->assertInstanceOf(\Magento\Framework\Model\ResourceModel\Db\Profiler::class, $profiler);
  61. $this->assertTrue($profiler->getEnabled());
  62. }
  63. }