47 $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)
48 ->disableOriginalConstructor()
50 $this->resourceConnectionMock = $this->getMockBuilder(ResourceConnection::class)
51 ->disableOriginalConstructor()
53 $this->metadataMock = $this->getMockBuilder(EntityMetadataInterface::class)
54 ->getMockForAbstractClass();
55 $this->connectionMock = $this->getMockBuilder(AdapterInterface::class)
56 ->getMockForAbstractClass();
57 $this->metadataMock = $this->getMockBuilder(EntityMetadataInterface::class)
58 ->getMockForAbstractClass();
60 $this->model = (
new ObjectManager($this))->getObject(UpdateRow::class, [
61 'metadataPool' => $this->metadataPoolMock,
62 'resourceConnection' => $this->resourceConnectionMock,
74 $primaryKeyName =
'entity_id';
75 $this->metadataPoolMock->expects($this->once())
76 ->method(
'getMetadata')
78 ->willReturn($this->metadataMock);
79 $this->resourceConnectionMock->expects($this->once())
80 ->method(
'getConnectionByName')
81 ->willReturn($this->connectionMock);
82 $this->metadataMock->expects($this->once())
83 ->method(
'getEntityConnectionName')
84 ->willReturn(
'test_connection_name');
85 $this->metadataMock->expects($this->atLeastOnce())
86 ->method(
'getEntityTable')
87 ->willReturn(
'test_entity_table');
88 $this->connectionMock->expects($this->once())
90 ->with(
'test_entity_table', $preparedColumns, [
'test_link_field' .
' = ?' =>
$data[
'test_link_field']]);
91 $this->connectionMock->expects($this->once())->method(
'getIndexList')
92 ->willReturn([$primaryKeyName => [
'COLUMNS_LIST' => [
'test_link_field']]]);
93 $this->connectionMock->expects($this->once())->method(
'getPrimaryKeyName')
94 ->willReturn($primaryKeyName);
95 $this->connectionMock->expects($this->once())
96 ->method(
'describeTable')
98 $this->metadataMock->expects($this->exactly(2))
99 ->method(
'getIdentifierField')
100 ->willReturn(
'test_identified_field');
101 if (empty(
$data[
'updated_at'])) {
102 unset(
$data[
'updated_at']);
104 $this->assertSame(
$data, $this->model->execute(
'test',
$data));
113 'test_link_field' => 1,
114 'identified_field' =>
'test_identified_field',
115 'test_simple' =>
'test_value',
122 'COLUMN_NAME' =>
'test_nullable',
128 'COLUMN_NAME' =>
'test_simple',
132 'test_identified_field' =>
null,
133 'test_nullable' =>
null,
134 'test_simple' =>
'test_value',
141 'preparedColumns' => $preparedColumns,
143 'empty timestamp field' => [
144 'data' => array_merge(
$data, [
'updated_at' =>
'']),
145 'columns' => array_merge(
150 'DEFAULT' =>
'CURRENT_TIMESTAMP',
152 'COLUMN_NAME' =>
'updated_at',
156 'preparedColumns' => $preparedColumns,
158 'filled timestamp field' => [
159 'data' => array_merge(
$data, [
'updated_at' =>
'2016-01-01 00:00:00']),
160 'columns' => array_merge(
165 'DEFAULT' =>
'CURRENT_TIMESTAMP',
167 'COLUMN_NAME' =>
'updated_at',
171 'preparedColumns' => array_merge($preparedColumns, [
'updated_at' =>
'2016-01-01 00:00:00']),
testExecute(array $data, array $columns, array $preparedColumns)