ComponentRegistrarTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Component\Test\Unit;
  7. use Magento\Framework\Component\ComponentRegistrar;
  8. class ComponentRegistrarTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * Module registrar object
  12. *
  13. * @var ComponentRegistrar
  14. */
  15. private $object;
  16. protected function setUp()
  17. {
  18. $this->object = new ComponentRegistrar();
  19. }
  20. /**
  21. * @expectedException \LogicException
  22. * @expectedExceptionMessage 'some_type' is not a valid component type
  23. */
  24. public function testWithInvalidType()
  25. {
  26. ComponentRegistrar::register('some_type', "test_module_one", "some/path/name/one");
  27. }
  28. public function testGetPathsForModule()
  29. {
  30. ComponentRegistrar::register(ComponentRegistrar::MODULE, "test_module_one", "some/path/name/one");
  31. ComponentRegistrar::register(ComponentRegistrar::MODULE, "test_module_two", "some/path/name/two");
  32. $expected = [
  33. 'test_module_one' => "some/path/name/one",
  34. 'test_module_two' => "some/path/name/two",
  35. ];
  36. $this->assertContains($expected['test_module_one'], $this->object->getPaths(ComponentRegistrar::MODULE));
  37. $this->assertContains($expected['test_module_two'], $this->object->getPaths(ComponentRegistrar::MODULE));
  38. }
  39. /**
  40. * @expectedException \LogicException
  41. */
  42. public function testRegistrarWithExceptionForModules()
  43. {
  44. ComponentRegistrar::register(ComponentRegistrar::MODULE, "test_module_one", "some/path/name/onemore");
  45. }
  46. public function testGetPath()
  47. {
  48. $this->assertSame("some/path/name/one", $this->object->getPath(ComponentRegistrar::MODULE, 'test_module_one'));
  49. $this->assertSame("some/path/name/two", $this->object->getPath(ComponentRegistrar::MODULE, 'test_module_two'));
  50. }
  51. }