Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions
ComposerTest Class Reference
Inheritance diagram for ComposerTest:

Public Member Functions

 testValidComposerJson ()
 
 validateComposerJsonDataProvider ()
 
 testComponentPathsInRoot ()
 

Static Public Member Functions

static setUpBeforeClass ()
 
static getBlacklist (string $pattern)
 

Detailed Description

A test that enforces validity of composer.json files and any other conventions in Magento components

Definition at line 15 of file ComposerTest.php.

Member Function Documentation

◆ getBlacklist()

static getBlacklist ( string  $pattern)
static

Return aggregated blacklist

Parameters
string$pattern
Returns
string[]

Definition at line 67 of file ComposerTest.php.

68  {
69  $blacklist = [];
70  foreach (glob($pattern) as $list) {
71  $blacklist = array_merge($blacklist, file($list, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
72  }
73  return $blacklist;
74  }
$pattern
Definition: website.php:22

◆ setUpBeforeClass()

static setUpBeforeClass ( )
static

Definition at line 48 of file ComposerTest.php.

49  {
50  self::$root = BP;
51  self::$rootJson = json_decode(file_get_contents(self::$root . '/composer.json'), true);
52  self::$dependencies = [];
53  self::$objectManager = Bootstrap::create(BP, $_SERVER)->getObjectManager();
54  // A block can be whitelisted and thus not be required to be public
55  self::$rootComposerModuleBlacklist = self::getBlacklist(
56  __DIR__ . '/_files/blacklist/composer_root_modules*.txt'
57  );
58  self::$moduleNameBlacklist = self::getBlacklist(__DIR__ . '/_files/blacklist/composer_module_names*.txt');
59  }
static create($rootDir, array $initParams, ObjectManagerFactory $factory=null)
Definition: Bootstrap.php:119
$objectManager
Definition: bootstrap.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
static getBlacklist(string $pattern)
const BP
Definition: autoload.php:14

◆ testComponentPathsInRoot()

testComponentPathsInRoot ( )

Definition at line 414 of file ComposerTest.php.

415  {
416  if (!isset(self::$rootJson['extra']) || !isset(self::$rootJson['extra']['component_paths'])) {
417  $this->markTestSkipped("The root composer.json file doesn't mention any extra component paths information");
418  }
419  $this->assertArrayHasKey(
420  'replace',
421  self::$rootJson,
422  "If there are any component paths specified, then they must be reflected in 'replace' section"
423  );
424  $flat = $this->getFlatPathsInfo(self::$rootJson['extra']['component_paths']);
425  foreach ($flat as $item) {
426  list($component, $path) = $item;
427  $this->assertFileExists(
428  self::$root . '/' . $path,
429  "Missing or invalid component path: {$component} -> {$path}"
430  );
431  $this->assertArrayHasKey(
432  $component,
433  self::$rootJson['replace'],
434  "The {$component} is specified in 'extra->component_paths', but missing in 'replace' section"
435  );
436  }
437  foreach (array_keys(self::$rootJson['replace']) as $replace) {
439  $this->assertArrayHasKey(
440  $replace,
441  self::$rootJson['extra']['component_paths'],
442  "The {$replace} is specified in 'replace', but missing in 'extra->component_paths' section"
443  );
444  }
445  }
446  }

◆ testValidComposerJson()

testValidComposerJson ( )
Parameters
string$dir
string$packageType

Definition at line 76 of file ComposerTest.php.

77  {
78  $invoker = new \Magento\Framework\App\Utility\AggregateInvoker($this);
79  $invoker(
84  function ($dir, $packageType) {
85  $file = $dir . '/composer.json';
86  $this->assertFileExists($file);
87  $this->validateComposerJsonFile($dir);
89  $json = json_decode($contents);
90  $this->assertCodingStyle($contents);
91  $this->assertMagentoConventions($dir, $packageType, $json);
92  },
94  );
95  }
$contents
Definition: website.php:14

◆ validateComposerJsonDataProvider()

validateComposerJsonDataProvider ( )
Returns
array

Definition at line 100 of file ComposerTest.php.

101  {
102  $root = BP;
103  $componentRegistrar = new ComponentRegistrar();
104  $result = [];
105  foreach ($componentRegistrar->getPaths(ComponentRegistrar::MODULE) as $dir) {
106  $result[$dir] = [$dir, 'magento2-module'];
107  }
108  foreach ($componentRegistrar->getPaths(ComponentRegistrar::LANGUAGE) as $dir) {
109  $result[$dir] = [$dir, 'magento2-language'];
110  }
111  foreach ($componentRegistrar->getPaths(ComponentRegistrar::THEME) as $dir) {
112  $result[$dir] = [$dir, 'magento2-theme'];
113  }
114  foreach ($componentRegistrar->getPaths(ComponentRegistrar::LIBRARY) as $dir) {
115  $result[$dir] = [$dir, 'magento2-library'];
116  }
117  $result[$root] = [$root, 'project'];
118 
119  return $result;
120  }
$componentRegistrar
Definition: bootstrap.php:23
const BP
Definition: autoload.php:14

The documentation for this class was generated from the following file: