File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 33
33
/**
34
34
* Input for the Luhn Algorithm contains a number and a check digit.
35
35
*/
36
- class Number implements NumberInterface
36
+ class Number implements NumberInterface, \Serializable
37
37
{
38
38
/**
39
39
* @var string
@@ -114,4 +114,14 @@ public function __toString()
114
114
{
115
115
return $ this ->number . $ this ->checkDigit ;
116
116
}
117
+
118
+ public function serialize ()
119
+ {
120
+ return serialize ([$ this ->number , $ this ->checkDigit ]);
121
+ }
122
+
123
+ public function unserialize ($ serialized )
124
+ {
125
+ list ($ this ->number , $ this ->checkDigit ) = unserialize ($ serialized );
126
+ }
117
127
}
Original file line number Diff line number Diff line change @@ -121,4 +121,14 @@ public function provideProperties()
121
121
"Valid number and check digit (null) " => [123 , null ],
122
122
];
123
123
}
124
+
125
+ public function testSerialize ()
126
+ {
127
+ $ number = new Number (133 , 7 );
128
+ $ serialized = serialize ($ number );
129
+ $ other = unserialize ($ serialized );
130
+ $ this ->assertInstanceOf (Number::class, $ other );
131
+ $ this ->assertEquals (133 , $ other ->getNumber ());
132
+ $ this ->assertEquals (7 , $ other ->getCheckDigit ());
133
+ }
124
134
}
You can’t perform that action at this time.
0 commit comments