DirTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Module\Test\Unit;
  7. use Magento\Framework\Component\ComponentRegistrar;
  8. class DirTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Framework\Module\Dir
  12. */
  13. protected $_model;
  14. /**
  15. * @var \Magento\Framework\Component\ComponentRegistrarInterface|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. protected $moduleRegistryMock;
  18. protected function setUp()
  19. {
  20. $this->moduleRegistryMock = $this->createMock(\Magento\Framework\Component\ComponentRegistrarInterface::class);
  21. $this->_model = new \Magento\Framework\Module\Dir($this->moduleRegistryMock);
  22. }
  23. public function testGetDirModuleRoot()
  24. {
  25. $this->moduleRegistryMock->expects($this->once())
  26. ->method('getPath')
  27. ->with(ComponentRegistrar::MODULE, 'Test_Module')
  28. ->will($this->returnValue('/Test/Module'));
  29. $this->assertEquals('/Test/Module', $this->_model->getDir('Test_Module'));
  30. }
  31. public function testGetDirModuleSubDir()
  32. {
  33. $this->moduleRegistryMock->expects($this->once())
  34. ->method('getPath')
  35. ->with(ComponentRegistrar::MODULE, 'Test_Module')
  36. ->will($this->returnValue('/Test/Module'));
  37. $this->assertEquals('/Test/Module/etc', $this->_model->getDir('Test_Module', 'etc'));
  38. }
  39. public function testGetSetupDirModule()
  40. {
  41. $this->moduleRegistryMock->expects($this->once())
  42. ->method('getPath')
  43. ->with(ComponentRegistrar::MODULE, 'Test_Module')
  44. ->willReturn('/Test/Module');
  45. $this->assertEquals('/Test/Module/Setup', $this->_model->getDir('Test_Module', 'Setup'));
  46. }
  47. /**
  48. * @expectedException \InvalidArgumentException
  49. * @expectedExceptionMessage Directory type 'unknown' is not recognized
  50. */
  51. public function testGetDirModuleSubDirUnknown()
  52. {
  53. $this->moduleRegistryMock->expects($this->once())
  54. ->method('getPath')
  55. ->with(ComponentRegistrar::MODULE, 'Test_Module')
  56. ->will($this->returnValue('/Test/Module'));
  57. $this->_model->getDir('Test_Module', 'unknown');
  58. }
  59. /**
  60. * @expectedException \InvalidArgumentException
  61. * @expectedExceptionMessage Module 'Test Module' is not correctly registered.
  62. */
  63. public function testGetDirModuleIncorrectlyRegistered()
  64. {
  65. $this->moduleRegistryMock->expects($this->once())
  66. ->method('getPath')
  67. ->with($this->identicalTo(ComponentRegistrar::MODULE), $this->identicalTo('Test Module'))
  68. ->willReturn(null);
  69. $this->_model->getDir('Test Module');
  70. }
  71. }