ConfigTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Test\Integrity;
  7. use Magento\Framework\App\Utility\Classes;
  8. class ConfigTest extends \PHPUnit\Framework\TestCase
  9. {
  10. public function testPaymentMethods()
  11. {
  12. $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
  13. $invoker(
  14. /**
  15. * Verify whether all payment methods are declared in appropriate modules
  16. */
  17. function ($configFile, $moduleName) {
  18. $config = simplexml_load_file($configFile);
  19. $nodes = $config->xpath('/config/default/payment/*/model') ?: [];
  20. $formalModuleName = str_replace('_', '\\', $moduleName);
  21. foreach ($nodes as $node) {
  22. if (!Classes::isVirtual((string)$node)) {
  23. $this->assertStringStartsWith(
  24. $formalModuleName . '\Model\\',
  25. (string)$node,
  26. "'{$node}' payment method is declared in '{$configFile}' module, " .
  27. "but doesn't belong to '{$moduleName}' module"
  28. );
  29. }
  30. }
  31. },
  32. $this->paymentMethodsDataProvider()
  33. );
  34. }
  35. public function paymentMethodsDataProvider()
  36. {
  37. $data = [];
  38. foreach ($this->_getConfigFilesPerModule() as $configFile => $moduleName) {
  39. $data[] = [$configFile, $moduleName];
  40. }
  41. return $data;
  42. }
  43. /**
  44. * Get list of configuration files associated with modules
  45. *
  46. * @return array
  47. */
  48. protected function _getConfigFilesPerModule()
  49. {
  50. $data = [];
  51. $componentRegistrar = new \Magento\Framework\Component\ComponentRegistrar();
  52. $modulesPaths = $componentRegistrar->getPaths(\Magento\Framework\Component\ComponentRegistrar::MODULE);
  53. foreach ($modulesPaths as $moduleName => $path) {
  54. if (file_exists($configFile = $path . '/etc/config.xml')) {
  55. $data[$configFile] = $moduleName;
  56. }
  57. }
  58. return $data;
  59. }
  60. }