public function testExecute() { $data = ['test_link_field' => 1, 'identified_field' => 'test_identified_field', 'test_simple' => 'test_value']; $columns = ['test_nullable' => ['NULLABLE' => true, 'DEFAULT' => false, 'IDENTITY' => false, 'COLUMN_NAME' => 'test_nullable'], 'test_simple' => ['NULLABLE' => true, 'DEFAULT' => false, 'IDENTITY' => false, 'COLUMN_NAME' => 'test_simple']]; $preparedColumns = ['test_identified_field' => null, 'test_nullable' => null, 'test_simple' => 'test_value']; $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with('test')->willReturn($this->metadataMock); $this->resourceConnectionMock->expects($this->once())->method('getConnectionByName')->willReturn($this->connectionMock); $this->metadataMock->expects($this->once())->method('getEntityConnectionName')->willReturn('test_connection_name'); $this->metadataMock->expects($this->exactly(2))->method('getEntityTable')->willReturn('test_entity_table'); $this->connectionMock->expects($this->once())->method('update')->with('test_entity_table', $preparedColumns, ['test_link_field' . ' = ?' => $data['test_link_field']]); $this->metadataMock->expects($this->exactly(2))->method('getLinkField')->willReturn('test_link_field'); $this->connectionMock->expects($this->once())->method('describeTable')->willReturn($columns); $this->metadataMock->expects($this->exactly(2))->method('getIdentifierField')->willReturn('test_identified_field'); $this->assertSame($data, $this->model->execute('test', $data)); }
/** * @param EntityMetadataInterface $metadata * @param AdapterInterface $connection * @param array $data * @return array */ protected function prepareData(EntityMetadataInterface $metadata, AdapterInterface $connection, $data) { $output = []; foreach ($connection->describeTable($metadata->getEntityTable()) as $column) { if ($column['DEFAULT'] == 'CURRENT_TIMESTAMP' || $column['IDENTITY']) { continue; } if (isset($data[strtolower($column['COLUMN_NAME'])])) { $output[strtolower($column['COLUMN_NAME'])] = $data[strtolower($column['COLUMN_NAME'])]; } } if (empty($data[$metadata->getIdentifierField()])) { $output[$metadata->getIdentifierField()] = $metadata->generateIdentifier(); } return $output; }