ScopeResolverTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Url\Test\Unit;
  7. class ScopeResolverTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $scopeResolverMock;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $_object;
  17. protected function setUp()
  18. {
  19. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  20. $this->scopeResolverMock = $this->getMockBuilder(
  21. \Magento\Framework\App\ScopeResolverInterface::class
  22. )->getMock();
  23. $this->_object = $objectManager->getObject(
  24. \Magento\Framework\Url\ScopeResolver::class,
  25. ['scopeResolver' => $this->scopeResolverMock]
  26. );
  27. }
  28. /**
  29. * @dataProvider getScopeDataProvider
  30. * @param int|null$scopeId
  31. */
  32. public function testGetScope($scopeId)
  33. {
  34. $scopeMock = $this->getMockBuilder(\Magento\Framework\Url\ScopeInterface::class)->getMock();
  35. $this->scopeResolverMock->expects(
  36. $this->at(0)
  37. )->method(
  38. 'getScope'
  39. )->with(
  40. $scopeId
  41. )->will(
  42. $this->returnValue($scopeMock)
  43. );
  44. $this->_object->getScope($scopeId);
  45. }
  46. /**
  47. * @expectedException \Magento\Framework\Exception\LocalizedException
  48. * @expectedExceptionMessage The scope object is invalid. Verify the scope object and try again.
  49. */
  50. public function testGetScopeException()
  51. {
  52. $this->_object->getScope();
  53. }
  54. /**
  55. * @return array
  56. */
  57. public function getScopeDataProvider()
  58. {
  59. return [[null], [1]];
  60. }
  61. public function testGetScopes()
  62. {
  63. $this->scopeResolverMock->expects($this->once())->method('getScopes');
  64. $this->_object->getScopes();
  65. }
  66. }