6 declare(strict_types=1);
30 private $objectManagerHelper;
35 private $componentRegistrarMock;
40 private $xmlPersistor;
42 protected function setUp() : void
44 $this->componentRegistrarMock = $this->getMockBuilder(ComponentRegistrar::class)
45 ->disableOriginalConstructor()
47 $this->xmlPersistor = $this->getMockBuilder(XmlPersistor::class)
49 $this->objectManagerHelper =
new ObjectManagerHelper($this);
50 $this->model = $this->objectManagerHelper->getObject(
51 \
Magento\Framework\Setup\SchemaPersistor::class,
53 'componentRegistrar' => $this->componentRegistrarMock,
54 'xmlPersistor' => $this->xmlPersistor
64 public function testPersist(array $tables, $expectedXML) : void
66 $moduleName =
'First_Module';
68 $schemaListenerMock = $this->getMockBuilder(SchemaListener::class)
69 ->disableOriginalConstructor()
71 $schemaListenerMock->expects(self::once())
73 ->willReturn($tables);
74 $this->componentRegistrarMock->expects(self::once())
76 ->with(
'module', $moduleName)
77 ->willReturn(
'some-non-existing-path');
78 $simpleXmlElement = new \SimpleXMLElement($expectedXML);
80 ->expects(self::once())
82 ->with($simpleXmlElement,
'some-non-existing-path/etc/db_schema.xml');
84 $this->model->persist($schemaListenerMock);
96 'schemaListenerTables' => [
100 'name' =>
'first_table',
101 'resource' =>
'default',
102 'engine' =>
'innodb',
105 'name' =>
'first_column',
106 'xsi:type' =>
'integer',
111 'name' =>
'second_column',
112 'xsi:type' =>
'date',
118 'name' =>
'TEST_INDEX',
119 'indexType' =>
'btree',
127 'some_foreign_constraint' => [
128 'referenceTable' =>
'table',
129 'referenceColumn' =>
'column',
130 'table' =>
'first_table',
131 'column' =>
'first_column' 136 'xsi:type' =>
'primary',
148 'XMLResult' =>
'<?xml version="1.0"?> 149 <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 150 xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"> 151 <table name="first_table" resource="default" engine="innodb"> 152 <column xmlns:xsi="xsi" xsi:type="integer" name="first_column" nullable="1" 154 <column xmlns:xsi="xsi" xsi:type="date" name="second_column" nullable="0"/> 155 <constraint xmlns:xsi="xsi" xsi:type="foreign" name="some_foreign_constraint" 156 referenceTable="table" referenceColumn="column" 157 table="first_table" column="first_column"/> 158 <constraint xmlns:xsi="xsi" xsi:type="primary" name="PRIMARY"> 159 <column name="second_column"/> 161 <index name="TEST_INDEX" indexType="btree"> 162 <column name="first_column"/>
schemaListenerTablesDataProvider()