22
33namespace PhpOffice \PhpSpreadsheetTests ;
44
5- use PhpOffice \PhpSpreadsheet \Exception as ssException ;
5+ use PhpOffice \PhpSpreadsheet \Exception ;
66use PhpOffice \PhpSpreadsheet \Spreadsheet ;
77use PhpOffice \PhpSpreadsheet \Worksheet \Worksheet ;
88use PHPUnit \Framework \TestCase ;
@@ -67,7 +67,7 @@ public function testGetSheetByName(?int $index, string $sheetName): void
6767 public function testAddSheetDuplicateTitle (): void
6868 {
6969 $ spreadsheet = $ this ->getSpreadsheet ();
70- $ this ->expectException (ssException ::class);
70+ $ this ->expectException (Exception ::class);
7171 $ sheet = new Worksheet ();
7272 $ sheet ->setTitle ('someSheet2 ' );
7373 $ spreadsheet ->addSheet ($ sheet );
@@ -98,7 +98,7 @@ public function testAddSheetAdjustActive(): void
9898 public function testRemoveSheetIndexTooHigh (): void
9999 {
100100 $ spreadsheet = $ this ->getSpreadsheet ();
101- $ this ->expectException (ssException ::class);
101+ $ this ->expectException (Exception ::class);
102102 $ spreadsheet ->removeSheetByIndex (4 );
103103 }
104104
@@ -123,14 +123,14 @@ public function testRemoveSheetAdjustActive(): void
123123 public function testGetSheetIndexTooHigh (): void
124124 {
125125 $ spreadsheet = $ this ->getSpreadsheet ();
126- $ this ->expectException (ssException ::class);
126+ $ this ->expectException (Exception ::class);
127127 $ spreadsheet ->getSheet (4 );
128128 }
129129
130130 public function testGetIndexNonExistent (): void
131131 {
132132 $ spreadsheet = $ this ->getSpreadsheet ();
133- $ this ->expectException (ssException ::class);
133+ $ this ->expectException (Exception ::class);
134134 $ sheet = new Worksheet ();
135135 $ sheet ->setTitle ('someSheet4 ' );
136136 $ spreadsheet ->getIndex ($ sheet );
@@ -175,14 +175,14 @@ public function testBug1735(): void
175175 public function testSetActiveSheetIndexTooHigh (): void
176176 {
177177 $ spreadsheet = $ this ->getSpreadsheet ();
178- $ this ->expectException (ssException ::class);
178+ $ this ->expectException (Exception ::class);
179179 $ spreadsheet ->setActiveSheetIndex (4 );
180180 }
181181
182182 public function testSetActiveSheetNoSuchName (): void
183183 {
184184 $ spreadsheet = $ this ->getSpreadsheet ();
185- $ this ->expectException (ssException ::class);
185+ $ this ->expectException (Exception ::class);
186186 $ spreadsheet ->setActiveSheetIndexByName ('unknown ' );
187187 }
188188
@@ -210,7 +210,7 @@ public function testAddExternal(): void
210210
211211 public function testAddExternalDuplicateName (): void
212212 {
213- $ this ->expectException (ssException ::class);
213+ $ this ->expectException (Exception ::class);
214214 $ spreadsheet = new Spreadsheet ();
215215 $ sheet = $ spreadsheet ->createSheet ()->setTitle ('someSheet1 ' );
216216 $ sheet ->getCell ('A1 ' )->setValue (1 );
@@ -275,4 +275,22 @@ public function testAddExternalRowDimensionStyles(): void
275275 self ::assertEquals ($ countXfs + $ index , $ sheet3 ->getCell ('A2 ' )->getXfIndex ());
276276 self ::assertEquals ($ countXfs + $ index , $ sheet3 ->getRowDimension (2 )->getXfIndex ());
277277 }
278+
279+ public function testNotSerializable (): void
280+ {
281+ $ this ->spreadsheet = $ spreadsheet = new Spreadsheet ();
282+
283+ $ this ->expectException (Exception::class);
284+ $ this ->expectExceptionMessage ('Spreadsheet objects cannot be serialized ' );
285+ serialize ($ this ->spreadsheet );
286+ }
287+
288+ public function testNotJsonEncodable (): void
289+ {
290+ $ this ->spreadsheet = $ spreadsheet = new Spreadsheet ();
291+
292+ $ this ->expectException (Exception::class);
293+ $ this ->expectExceptionMessage ('Spreadsheet objects cannot be json encoded ' );
294+ json_encode ($ this ->spreadsheet );
295+ }
278296}
0 commit comments