Skip to content

Commit ea106f2

Browse files
committed
Use imports
1 parent 67e68c2 commit ea106f2

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/test/php/text/csv/unittest/CellProcessorTest.class.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php namespace text\csv\unittest;
22

33
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};
75
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};
89

910
/**
1011
* TestCase
@@ -92,7 +93,7 @@ public function asDate() {
9293
new AsDate(),
9394
null
9495
]);
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());
9697
}
9798

9899
#[@test, @expect(FormatException::class)]
@@ -121,7 +122,7 @@ public function emptyAsDateWithNullDefault() {
121122

122123
#[@test]
123124
public function emptyAsDateWithDefault() {
124-
$now= \util\Date::now();
125+
$now= Date::now();
125126
$in= $this->newReader(';Order placed')->withProcessors([
126127
(new AsDate())->withDefault($now),
127128
null
@@ -135,7 +136,7 @@ public function formatDate() {
135136
new FormatDate('Y-m-d H:i'),
136137
null
137138
]);
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']);
139140
$this->assertEquals("2009-09-09 15:45;Order placed\n", $this->out->getBytes());
140141
}
141142

@@ -157,7 +158,7 @@ public function formatNull() {
157158

158159
#[@test]
159160
public function formatNullWithDefault() {
160-
$now= \util\Date::now();
161+
$now= Date::now();
161162
$writer= $this->newWriter()->withProcessors([
162163
(new FormatDate('Y-m-d H:i'))->withDefault($now),
163164
null
@@ -272,7 +273,7 @@ public function formatFalseAsN() {
272273
public function pennyCoin() {
273274
$in= $this->newReader('200;penny')->withProcessors([
274275
null,
275-
new AsEnum(\lang\XPClass::forName('text.csv.unittest.Coin'))
276+
new AsEnum(XPClass::forName('text.csv.unittest.Coin'))
276277
]);
277278
$this->assertEquals(['200', Coin::$penny], $in->read());
278279
}
@@ -281,15 +282,15 @@ public function pennyCoin() {
281282
public function invalidCoin() {
282283
$this->newReader('200;dollar')->withProcessors([
283284
null,
284-
new AsEnum(\lang\XPClass::forName('text.csv.unittest.Coin'))
285+
new AsEnum(XPClass::forName('text.csv.unittest.Coin'))
285286
])->read();
286287
}
287288

288289
#[@test, @expect(FormatException::class)]
289290
public function emptyCoin() {
290291
$this->newReader('200;')->withProcessors([
291292
null,
292-
new AsEnum(\lang\XPClass::forName('text.csv.unittest.Coin'))
293+
new AsEnum(XPClass::forName('text.csv.unittest.Coin'))
293294
])->read();
294295
}
295296

@@ -475,7 +476,7 @@ public function readUnique() {
475476
try {
476477
$in->read();
477478
$this->fail('Duplicate value not detected', null, 'lang.FormatException');
478-
} catch (\lang\FormatException $expected) { }
479+
} catch (FormatException $expected) { }
479480
}
480481

481482
#[@test]
@@ -489,7 +490,7 @@ public function writeUnique() {
489490
try {
490491
$writer->write(['200', 'NACK']);
491492
$this->fail('Duplicate value not detected', null, 'lang.FormatException');
492-
} catch (\lang\FormatException $expected) { }
493+
} catch (FormatException $expected) { }
493494

494495
$this->assertEquals("200;OK\n", $this->out->getBytes());
495496
}
@@ -502,7 +503,7 @@ public function writeUnique() {
502503
* @return text.csv.CellProcessor
503504
*/
504505
protected function newUnwantedValueProcessor($value) {
505-
return newinstance(CellProcessor::class, [$value], '{
506+
return new class($value) extends CellProcessor {
506507
protected $unwanted= NULL;
507508

508509
public function __construct($value, $next= NULL) {
@@ -512,9 +513,9 @@ public function __construct($value, $next= NULL) {
512513

513514
public function process($in) {
514515
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");
516517
}
517-
}');
518+
};
518519
}
519520

520521
#[@test]
@@ -526,7 +527,7 @@ public function processorExceptionsDoNotBreakReading() {
526527
try {
527528
$in->read();
528529
$this->fail('Unwanted value not detected', null, 'lang.FormatException');
529-
} catch (\lang\FormatException $expected) { }
530+
} catch (FormatException $expected) { }
530531
$this->assertEquals(['404', 'Not found'], $in->read());
531532
}
532533

@@ -539,7 +540,7 @@ public function processorExceptionsDoNotBreakReadingMultiline() {
539540
try {
540541
$in->read();
541542
$this->fail('Unwanted value not detected', null, 'lang.FormatException');
542-
} catch (\lang\FormatException $expected) { }
543+
} catch (FormatException $expected) { }
543544
$this->assertEquals(['404', "Not found\nFamous"], $in->read());
544545
}
545546

@@ -553,7 +554,7 @@ public function processorExceptionsDoNotBreakWriting() {
553554
try {
554555
$writer->write(['200', 'OK']);
555556
$this->fail('Unwanted value not detected', null, 'lang.FormatException');
556-
} catch (\lang\FormatException $expected) { }
557+
} catch (FormatException $expected) { }
557558

558559
$writer->write(['404', 'Not found']);
559560
$this->assertEquals("404;Not found\n", $this->out->getBytes());
@@ -569,7 +570,7 @@ public function processorExceptionsDoNotCausePartialWriting() {
569570
try {
570571
$writer->write(['500', 'Internal Server Error']);
571572
$this->fail('Unwanted value not detected', null, 'lang.FormatException');
572-
} catch (\lang\FormatException $expected) { }
573+
} catch (FormatException $expected) { }
573574

574575
$writer->write(['404', 'Not found']);
575576
$this->assertEquals("404;Not found\n", $this->out->getBytes());

0 commit comments

Comments
 (0)