SeparateAppsTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\NewRelicReporting\Plugin;
  8. use Magento\Framework\App\State;
  9. use Magento\NewRelicReporting\Model\NewRelicWrapper;
  10. use Magento\TestFramework\ObjectManager;
  11. use Magento\TestFramework\Helper\Bootstrap;
  12. /**
  13. * Class SeparateAppsTest
  14. */
  15. class SeparateAppsTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var ObjectManager
  19. */
  20. private $objectManager;
  21. /**
  22. * @inheritdoc
  23. */
  24. protected function setUp()
  25. {
  26. $this->objectManager = Bootstrap::getObjectManager();
  27. }
  28. /**
  29. * @magentoConfigFixture default/newrelicreporting/general/enable 1
  30. * @magentoConfigFixture default/newrelicreporting/general/app_name beverly_hills
  31. * @magentoConfigFixture default/newrelicreporting/general/separate_apps 1
  32. */
  33. public function testAppNameIsSetWhenConfiguredCorrectly()
  34. {
  35. $newRelicWrapper = $this->getMockBuilder(NewRelicWrapper::class)
  36. ->setMethods(['setAppName'])
  37. ->getMock();
  38. $this->objectManager->configure([NewRelicWrapper::class => ['shared' => true]]);
  39. $this->objectManager->addSharedInstance($newRelicWrapper, NewRelicWrapper::class);
  40. $newRelicWrapper->expects($this->once())
  41. ->method('setAppName')
  42. ->with($this->equalTo('beverly_hills;beverly_hills_90210'));
  43. $state = $this->objectManager->get(State::class);
  44. $state->setAreaCode('90210');
  45. }
  46. /**
  47. * @magentoConfigFixture default/newrelicreporting/general/enable 1
  48. * @magentoConfigFixture default/newrelicreporting/general/app_name beverly_hills
  49. * @magentoConfigFixture default/newrelicreporting/general/separate_apps 0
  50. */
  51. public function testAppNameIsNotSetWhenDisabled()
  52. {
  53. $newRelicWrapper = $this->getMockBuilder(NewRelicWrapper::class)
  54. ->setMethods(['setAppName'])
  55. ->getMock();
  56. $this->objectManager->configure([NewRelicWrapper::class => ['shared' => true]]);
  57. $this->objectManager->addSharedInstance($newRelicWrapper, NewRelicWrapper::class);
  58. $newRelicWrapper->expects($this->never())->method('setAppName');
  59. $state = $this->objectManager->get(State::class);
  60. $state->setAreaCode('90210');
  61. }
  62. }