File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 3333/**
3434 * Input for the Luhn Algorithm contains a number and a check digit.
3535 */
36- class Number implements NumberInterface
36+ class Number implements NumberInterface, \Serializable
3737{
3838 /**
3939 * @var string
@@ -114,4 +114,14 @@ public function __toString()
114114 {
115115 return $ this ->number . $ this ->checkDigit ;
116116 }
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+ }
117127}
Original file line number Diff line number Diff line change @@ -121,4 +121,14 @@ public function provideProperties()
121121 "Valid number and check digit (null) " => [123 , null ],
122122 ];
123123 }
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+ }
124134}
You can’t perform that action at this time.
0 commit comments