1
1
<?php namespace text \csv \unittest ;
2
2
3
3
use io \streams \{MemoryInputStream , MemoryOutputStream , TextReader , TextWriter };
4
- use lang \FormatException ;
5
- use text \csv \{CellProcessor , CsvFormat , CsvListReader , CsvListWriter };
6
- use text \csv \processors \{AsBool , AsDate , AsDouble , AsEnum , AsInteger , FormatBool , FormatDate , FormatEnum , FormatNumber };
4
+ use lang \{FormatException , XPClass };
7
5
use text \csv \processors \constraint \{Optional , Required , Unique };
6
+ use text \csv \processors \{AsBool , AsDate , AsDouble , AsEnum , AsInteger , FormatBool , FormatDate , FormatEnum , FormatNumber };
7
+ use text \csv \{CellProcessor , CsvFormat , CsvListReader , CsvListWriter };
8
+ use util \{Date , Objects };
8
9
9
10
/**
10
11
* TestCase
@@ -92,7 +93,7 @@ public function asDate() {
92
93
new AsDate (),
93
94
null
94
95
]);
95
- $ this ->assertEquals ([new \ util \ Date ('2009-09-09 15:45 ' ), 'Order placed ' ], $ in ->read ());
96
+ $ this ->assertEquals ([new Date ('2009-09-09 15:45 ' ), 'Order placed ' ], $ in ->read ());
96
97
}
97
98
98
99
#[@test, @expect(FormatException::class)]
@@ -121,7 +122,7 @@ public function emptyAsDateWithNullDefault() {
121
122
122
123
#[@test]
123
124
public function emptyAsDateWithDefault () {
124
- $ now = \ util \ Date::now ();
125
+ $ now = Date::now ();
125
126
$ in = $ this ->newReader (';Order placed ' )->withProcessors ([
126
127
(new AsDate ())->withDefault ($ now ),
127
128
null
@@ -135,7 +136,7 @@ public function formatDate() {
135
136
new FormatDate ('Y-m-d H:i ' ),
136
137
null
137
138
]);
138
- $ writer ->write ([new \ util \ Date ('2009-09-09 15:45 ' ), 'Order placed ' ]);
139
+ $ writer ->write ([new Date ('2009-09-09 15:45 ' ), 'Order placed ' ]);
139
140
$ this ->assertEquals ("2009-09-09 15:45;Order placed \n" , $ this ->out ->getBytes ());
140
141
}
141
142
@@ -157,7 +158,7 @@ public function formatNull() {
157
158
158
159
#[@test]
159
160
public function formatNullWithDefault () {
160
- $ now = \ util \ Date::now ();
161
+ $ now = Date::now ();
161
162
$ writer = $ this ->newWriter ()->withProcessors ([
162
163
(new FormatDate ('Y-m-d H:i ' ))->withDefault ($ now ),
163
164
null
@@ -272,7 +273,7 @@ public function formatFalseAsN() {
272
273
public function pennyCoin () {
273
274
$ in = $ this ->newReader ('200;penny ' )->withProcessors ([
274
275
null ,
275
- new AsEnum (\ lang \ XPClass::forName ('text.csv.unittest.Coin ' ))
276
+ new AsEnum (XPClass::forName ('text.csv.unittest.Coin ' ))
276
277
]);
277
278
$ this ->assertEquals (['200 ' , Coin::$ penny ], $ in ->read ());
278
279
}
@@ -281,15 +282,15 @@ public function pennyCoin() {
281
282
public function invalidCoin () {
282
283
$ this ->newReader ('200;dollar ' )->withProcessors ([
283
284
null ,
284
- new AsEnum (\ lang \ XPClass::forName ('text.csv.unittest.Coin ' ))
285
+ new AsEnum (XPClass::forName ('text.csv.unittest.Coin ' ))
285
286
])->read ();
286
287
}
287
288
288
289
#[@test, @expect(FormatException::class)]
289
290
public function emptyCoin () {
290
291
$ this ->newReader ('200; ' )->withProcessors ([
291
292
null ,
292
- new AsEnum (\ lang \ XPClass::forName ('text.csv.unittest.Coin ' ))
293
+ new AsEnum (XPClass::forName ('text.csv.unittest.Coin ' ))
293
294
])->read ();
294
295
}
295
296
@@ -475,7 +476,7 @@ public function readUnique() {
475
476
try {
476
477
$ in ->read ();
477
478
$ this ->fail ('Duplicate value not detected ' , null , 'lang.FormatException ' );
478
- } catch (\ lang \ FormatException $ expected ) { }
479
+ } catch (FormatException $ expected ) { }
479
480
}
480
481
481
482
#[@test]
@@ -489,7 +490,7 @@ public function writeUnique() {
489
490
try {
490
491
$ writer ->write (['200 ' , 'NACK ' ]);
491
492
$ this ->fail ('Duplicate value not detected ' , null , 'lang.FormatException ' );
492
- } catch (\ lang \ FormatException $ expected ) { }
493
+ } catch (FormatException $ expected ) { }
493
494
494
495
$ this ->assertEquals ("200;OK \n" , $ this ->out ->getBytes ());
495
496
}
@@ -502,7 +503,7 @@ public function writeUnique() {
502
503
* @return text.csv.CellProcessor
503
504
*/
504
505
protected function newUnwantedValueProcessor ($ value ) {
505
- return newinstance (CellProcessor::class, [ $ value], ' {
506
+ return new class ( $ value) extends CellProcessor {
506
507
protected $ unwanted = NULL ;
507
508
508
509
public function __construct ($ value , $ next = NULL ) {
@@ -512,9 +513,9 @@ public function __construct($value, $next= NULL) {
512
513
513
514
public function process ($ in ) {
514
515
if ($ this ->unwanted !== $ in ) return $ this ->proceed ($ in );
515
- throw new \lang\ FormatException("Unwanted value ".\util\ Objects::stringOf($this->unwanted)." encountered");
516
+ throw new FormatException ("Unwanted value " .Objects::stringOf ($ this ->unwanted )." encountered " );
516
517
}
517
- } ' ) ;
518
+ };
518
519
}
519
520
520
521
#[@test]
@@ -526,7 +527,7 @@ public function processorExceptionsDoNotBreakReading() {
526
527
try {
527
528
$ in ->read ();
528
529
$ this ->fail ('Unwanted value not detected ' , null , 'lang.FormatException ' );
529
- } catch (\ lang \ FormatException $ expected ) { }
530
+ } catch (FormatException $ expected ) { }
530
531
$ this ->assertEquals (['404 ' , 'Not found ' ], $ in ->read ());
531
532
}
532
533
@@ -539,7 +540,7 @@ public function processorExceptionsDoNotBreakReadingMultiline() {
539
540
try {
540
541
$ in ->read ();
541
542
$ this ->fail ('Unwanted value not detected ' , null , 'lang.FormatException ' );
542
- } catch (\ lang \ FormatException $ expected ) { }
543
+ } catch (FormatException $ expected ) { }
543
544
$ this ->assertEquals (['404 ' , "Not found \nFamous " ], $ in ->read ());
544
545
}
545
546
@@ -553,7 +554,7 @@ public function processorExceptionsDoNotBreakWriting() {
553
554
try {
554
555
$ writer ->write (['200 ' , 'OK ' ]);
555
556
$ this ->fail ('Unwanted value not detected ' , null , 'lang.FormatException ' );
556
- } catch (\ lang \ FormatException $ expected ) { }
557
+ } catch (FormatException $ expected ) { }
557
558
558
559
$ writer ->write (['404 ' , 'Not found ' ]);
559
560
$ this ->assertEquals ("404;Not found \n" , $ this ->out ->getBytes ());
@@ -569,7 +570,7 @@ public function processorExceptionsDoNotCausePartialWriting() {
569
570
try {
570
571
$ writer ->write (['500 ' , 'Internal Server Error ' ]);
571
572
$ this ->fail ('Unwanted value not detected ' , null , 'lang.FormatException ' );
572
- } catch (\ lang \ FormatException $ expected ) { }
573
+ } catch (FormatException $ expected ) { }
573
574
574
575
$ writer ->write (['404 ' , 'Not found ' ]);
575
576
$ this ->assertEquals ("404;Not found \n" , $ this ->out ->getBytes ());
0 commit comments