7
7
8
8
namespace Magento \Framework \Model \Test \Unit \ResourceModel \Db \VersionControl ;
9
9
10
+ use Magento \Framework \Exception \LocalizedException ;
10
11
use Magento \Framework \Model \AbstractModel ;
11
12
use Magento \Framework \Model \ResourceModel \Db \VersionControl \Metadata ;
12
13
use Magento \Framework \Model \ResourceModel \Db \VersionControl \Snapshot ;
13
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
14
+ use Magento \Framework \Serialize \SerializerInterface ;
15
+ use PHPUnit \Framework \MockObject \Exception ;
14
16
use PHPUnit \Framework \MockObject \MockObject ;
15
17
use PHPUnit \Framework \TestCase ;
16
18
@@ -19,38 +21,47 @@ class SnapshotTest extends TestCase
19
21
/**
20
22
* @var Snapshot
21
23
*/
22
- protected $ entitySnapshot ;
24
+ protected Snapshot $ entitySnapshot ;
23
25
24
26
/**
25
27
* @var MockObject|Metadata
26
28
*/
27
- protected $ entityMetadata ;
29
+ private Metadata $ entityMetadata ;
28
30
29
31
/**
30
32
* @var MockObject|AbstractModel
31
33
*/
32
- protected $ model ;
34
+ private AbstractModel $ model ;
33
35
34
36
/**
35
- * Initialization
37
+ * @var SerializerInterface|MockObject
38
+ */
39
+ private SerializerInterface $ serializer ;
40
+
41
+ /**
42
+ * @return void
43
+ * @throws Exception
36
44
*/
37
45
protected function setUp (): void
38
46
{
39
- $ objectManager = new ObjectManager ($ this );
40
47
$ this ->model = $ this ->createPartialMock (AbstractModel::class, ['getId ' ]);
41
48
42
49
$ this ->entityMetadata = $ this ->createPartialMock (
43
50
Metadata::class,
44
51
['getFields ' ]
45
52
);
53
+ $ this ->serializer = $ this ->createMock (SerializerInterface::class);
46
54
47
- $ this ->entitySnapshot = $ objectManager ->getObject (
48
- Snapshot::class,
49
- ['metadata ' => $ this ->entityMetadata ]
50
- );
55
+ $ this ->entitySnapshot = new Snapshot ($ this ->entityMetadata , $ this ->serializer );
56
+
57
+ parent ::setUp ();
51
58
}
52
59
53
- public function testRegisterSnapshot ()
60
+ /**
61
+ * @return void
62
+ * @throws LocalizedException
63
+ */
64
+ public function testRegisterSnapshot (): void
54
65
{
55
66
$ entityId = 1 ;
56
67
$ data = [
@@ -72,19 +83,26 @@ public function testRegisterSnapshot()
72
83
$ this ->assertFalse ($ this ->entitySnapshot ->isModified ($ this ->model ));
73
84
}
74
85
75
- public function testIsModified ()
86
+ /**
87
+ * @return void
88
+ * @throws LocalizedException
89
+ */
90
+ public function testIsModified (): void
76
91
{
77
92
$ entityId = 1 ;
93
+ $ options = ['option1 ' => 'value1 ' , 'option2 ' => 'value2 ' ];
78
94
$ data = [
79
95
'id ' => $ entityId ,
80
96
'name ' => 'test ' ,
81
97
'description ' => '' ,
82
- 'custom_not_present_attribute ' => ''
98
+ 'custom_not_present_attribute ' => '' ,
99
+ 'options ' => json_encode ($ options )
83
100
];
84
101
$ fields = [
85
102
'id ' => [],
86
103
'name ' => [],
87
- 'description ' => []
104
+ 'description ' => [],
105
+ 'options ' => []
88
106
];
89
107
$ modifiedData = array_merge ($ data , ['name ' => 'newName ' ]);
90
108
$ this ->model ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ entityId );
@@ -93,11 +111,19 @@ public function testIsModified()
93
111
$ this ->entitySnapshot ->registerSnapshot ($ this ->model );
94
112
$ this ->model ->setData ($ modifiedData );
95
113
$ this ->assertTrue ($ this ->entitySnapshot ->isModified ($ this ->model ));
114
+
115
+ $ this ->model ->setData ('options ' , $ options );
116
+ $ this ->assertTrue ($ this ->entitySnapshot ->isModified ($ this ->model ));
117
+
96
118
$ this ->entitySnapshot ->registerSnapshot ($ this ->model );
97
119
$ this ->assertFalse ($ this ->entitySnapshot ->isModified ($ this ->model ));
98
120
}
99
121
100
- public function testClear ()
122
+ /**
123
+ * @return void
124
+ * @throws LocalizedException
125
+ */
126
+ public function testClear (): void
101
127
{
102
128
$ entityId = 1 ;
103
129
$ data = [
0 commit comments