/** * @param object $entity * @param array $arguments * @return object */ public function execute($entity, $arguments = []) { $entityType = $this->typeResolver->resolve($entity); $hydrator = $this->hydratorPool->getHydrator($entityType); $arguments = array_merge($hydrator->extract($entity), $arguments); $entityData = $this->updateRow->execute($entityType, $arguments); $entity = $hydrator->hydrate($entity, $entityData); return $entity; }
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)); }