55 $this->fieldsProvider = $this->objectManager->create(\
Magento\
Mtf\Util\Generate\Fixture\FieldsProvider::class);
56 $this->dom = new \DOMDocument(
'1.0');
57 $this->dom->load(dirname(
__FILE__) .
'/template.xml');
58 $this->dom->preserveWhiteSpace =
false;
59 $this->dom->formatOutput =
true;
69 $options = getopt(
'', [
'type:',
'name:',
'entity_type:',
'collection:',
'help']);
70 $checkKeyExists = count(array_diff($this->requiredFields, array_keys(
$options)));
76 if (
$config[
'type'] ===
'composite') {
93 if (!$this->fieldsProvider->checkConnection()) {
97 $this->generateFixtureXml(
$config);
106 protected function generateFixtureXml(array
$config)
108 $classShortName = ucfirst(
$config[
'name']);
116 $handlerInterface .= $classShortName .
'\\' . $classShortName .
'Interface';
117 $fixtureClass =
$path . $classShortName;
119 $pathToFile = str_replace(
'\\', DIRECTORY_SEPARATOR, $folderName .
$fileName);
120 if (file_exists($pathToFile)) {
121 echo
"Fixture with name ($pathToFile) already exists.\n";
124 if (!
is_dir($folderName)) {
125 mkdir($folderName, 0777,
true);
129 $root = $this->dom->getElementsByTagName(
'config')->item(0);
131 $fixture = $this->dom->createElement(
'fixture');
132 $fixture->setAttribute(
'name',
$config[
'name']);
133 $fixture->setAttribute(
'module', $module);
134 $fixture->setAttribute(
'type',
$config[
'type']);
135 $fixture->setAttribute(
'collection', implode(
'\\',
$collection));
136 $fixture->setAttribute(
'repository_class', $repositoryClass);
137 $fixture->setAttribute(
'handler_interface', $handlerInterface);
138 $fixture->setAttribute(
'class', $fixtureClass);
139 if (isset(
$config[
'entity_type'])) {
140 $fixture->setAttribute(
'entity_type',
$config[
'entity_type']);
142 $root->appendChild($fixture);
145 foreach (
$fields as $fieldName => $fieldValue) {
146 $field = $this->dom->createElement(
'field');
147 $field->setAttribute(
'name', $fieldName);
148 $field->setAttribute(
'is_required', intval($fieldValue[
'is_required']));
149 $fixture->appendChild($field);
163 Usage:
Magento 2 fixture schema generator.
165 --type\t\t<flat>|<eav>|<table>|<composite>\t\tTable type
for the entity\tDefault: flat
166 --name\t\t<className>\t\t\t\t\tName of generated
class 167 --entity_type\t<entity_type>|<entity_type1,entity_type2>\tDatabase table
name where entity data is stored
168 --collection\t<path\\\\to\\\\collection>\t\t\t\tCollection to
generate data sets\tNOTE: All backslashes must be escaped
171 name, entity_type, collection - required fields
defined('MTF_BOOT_FILE')||define('MTF_BOOT_FILE' __FILE__
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
__construct(ObjectManagerInterface $objectManager)