diff --git a/phpunit.xml b/phpunit.xml index ce50e64..9c0f214 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,3 +1,8 @@ - + \ No newline at end of file diff --git a/tests/DateFormatTest.php b/tests/DateFormatTest.php index 666b58b..b152738 100644 --- a/tests/DateFormatTest.php +++ b/tests/DateFormatTest.php @@ -30,16 +30,6 @@ protected function setUp(): void $this->object = new DateFormat('fr-CA'); } - /** - * @covers ::__construct - */ - public function testDefaultConstructor(): void - { - $obj2 = new DateFormat('en-CA'); - - static::assertSame('en-CA', Assert::readAttribute($obj2, 'locale')); - } - /** * @covers ::__construct */ @@ -59,7 +49,7 @@ public function testAddResource(): void { $this->object->addResource(__DIR__ . '/resources/dateformats.json'); - $ref = Assert::readAttribute($this->object, 'formatters'); + $ref = $this->object->__debugInfo(); static::assertArrayHasKey('day_date', $ref['en-CA']); static::assertArrayHasKey('day_date_time', $ref['fr-CA']); @@ -85,7 +75,7 @@ public function testFormat(string $expected, $input, string $locale): void static::assertSame($expected, $this->object->format($input, 'day', $locale)); } - public function formatDataProvider(): iterable + public static function formatDataProvider(): iterable { $date = new DateTime('2014-01-01', new DateTimeZone(self::TIMEZONE)); $date2 = DateTime::createFromFormat('Y-m-d H:i:s', '2014-07-01 08:00:00'); diff --git a/tests/ResourceTest.php b/tests/ResourceTest.php index 5c2daaf..a29407b 100644 --- a/tests/ResourceTest.php +++ b/tests/ResourceTest.php @@ -6,7 +6,6 @@ use Iterator; use JsonI18n\Resource; -use PHPUnit\Framework\Error\Error; use PHPUnit\Framework\Error\Notice; use PHPUnit\Framework\TestCase; @@ -33,7 +32,7 @@ class ResourceTest extends TestCase */ protected $data = [ 'station' => "Station", - 'goodbye' => "Have a good day!" + 'goodbye' => "Have a good day!", ]; /** @@ -44,6 +43,7 @@ class ResourceTest extends TestCase protected function setUp(): void { + error_reporting(\E_ALL); $this->json = json_encode([$this->locale => $this->data]); $this->object = new Resource($this->locale, $this->data); } @@ -58,7 +58,7 @@ public function testFromJson(): void $resource = Resource::fromJson($this->json); static::assertSame($this->locale, $resource->getLocale()); - static::assertSame($this->data, $this->readAttribute($this->object, 'data')); + static::assertSame($this->data, $this->object->getData()); } /** @@ -84,12 +84,12 @@ public function testAddData(): void { $new = [ 'station' => 'Terminal', - 'greeting' => 'Hello' + 'greeting' => 'Hello', ]; $this->object->addData($new); - $data = $this->readAttribute($this->object, 'data'); + $data = $this->object->getData(); static::assertArrayHasKey('greeting', $data); static::assertSame('Terminal', $data['station']); @@ -102,12 +102,12 @@ public function testAddDataNoOverwrite(): void { $new = [ 'station' => 'Terminal', - 'greeting' => 'Hello' + 'greeting' => 'Hello', ]; $this->object->addData($new, false); - $data = $this->readAttribute($this->object, 'data'); + $data = $this->object->getData(); static::assertSame('Station', $data['station']); } @@ -126,12 +126,12 @@ public function testMerge(): void { $new = [ 'station' => 'Terminal', - 'greeting' => 'Hello' + 'greeting' => 'Hello', ]; $this->object->merge(new Resource($this->locale, $new)); - $data = $this->readAttribute($this->object, 'data'); + $data = $this->object->getData(); static::assertSame('Terminal', $data['station']); static::assertArrayHasKey('greeting', $new); } @@ -143,12 +143,12 @@ public function testMergeNoOverwrite(): void { $new = [ 'station' => 'Terminal', - 'greeting' => 'Hello' + 'greeting' => 'Hello', ]; $this->object->merge(new Resource($this->locale, $new), false); - $data = $this->readAttribute($this->object, 'data'); + $data = $this->object->getData(); static::assertSame('Station', $data['station']); static::assertArrayHasKey('greeting', $new); } @@ -158,7 +158,16 @@ public function testMergeNoOverwrite(): void */ public function testMergeDifferentLocales(): void { - static::expectException(Notice::class); + set_error_handler( + static function ( $errno, $errstr ) { + restore_error_handler(); + throw new \Exception( $errstr, $errno ); + }, + E_ALL + ); + + static::expectException(\Exception::class); + static::expectExceptionCode(\E_USER_NOTICE); $this->object->merge(new Resource('zh-CN')); } @@ -201,7 +210,7 @@ public function testOffsetGet(): void */ public function testOffsetGetInexistent(): void { - static::expectException(Error::class); + static::expectException(\TypeError::class); $this->object['foo']; } @@ -213,7 +222,7 @@ public function testOffsetSet(): void { $this->object['greeting'] = 'Hello'; - static::assertArrayHasKey('greeting', $this->readAttribute($this->object, 'data')); + static::assertArrayHasKey('greeting', $this->object->getData()); } /** @@ -223,7 +232,7 @@ public function testOffsetUnset(): void { unset($this->object['station']); - static::assertArrayNotHasKey('station', $this->readAttribute($this->object, 'data')); + static::assertArrayNotHasKey('station', $this->object->getData()); } /** diff --git a/tests/TranslateTest.php b/tests/TranslateTest.php index e224a4c..33e5030 100644 --- a/tests/TranslateTest.php +++ b/tests/TranslateTest.php @@ -8,7 +8,6 @@ use JsonI18n\Translate; use LengthException; use OutOfBoundsException; -use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use TypeError; use const JSON_ERROR_SYNTAX; @@ -38,7 +37,7 @@ class TranslateTest extends TestCase 'headsign_en' => 'Blackbird Mall', 'headsign_fr' => 'Centre commercial Blackbird', 'subtext_en' => 'Main Street', - 'subtext_fr' => 'Rue Main' + 'subtext_fr' => 'Rue Main', ]; /** @@ -48,7 +47,7 @@ class TranslateTest extends TestCase protected $arr2D = [ ['headsign_en' => 'University', 'headsign_fr' => 'Université'], ['headsign_en' => 'College', 'headsign_fr' => 'Collège'], - ['headsign_en' => 'Airport', 'headsign_fr' => 'Aéroport'] + ['headsign_en' => 'Airport', 'headsign_fr' => 'Aéroport'], ]; /** @@ -62,8 +61,8 @@ class TranslateTest extends TestCase 'crosstown' => [ ['headsign_en' => 'Blackbird Mall', 'headsign_fr' => 'Centre commercial Blackbird'], ['headsign_en' => 'University', 'headsign_fr' => 'Université'], - ['headsign_en' => 'College', 'headsign_fr' => 'Collège'] - ] + ['headsign_en' => 'College', 'headsign_fr' => 'Collège'], + ], ]; protected function setUp(): void @@ -78,7 +77,7 @@ public function testDefaultConstructor(): void { $obj2 = new Translate('en-CA'); - static::assertSame('en-CA', Assert::readAttribute($obj2, 'lang')); + static::assertSame('en-CA', $this->object->getLanguage()); } /** @@ -135,12 +134,11 @@ public function testAddResourceFile(): void { $this->object->addResource(__DIR__ . '/resources/test.json'); - $data = Assert::readAttribute($this->object, 'data'); + $data = $this->object->__debugInfo(); static::assertNotEmpty($data); static::assertArrayHasKey('en-CA', $data); static::assertArrayHasKey('fr-CA', $data); - static::assertNotEmpty(Assert::readAttribute($this->object, 'arrayGroups')); } /** @@ -156,7 +154,7 @@ public function testAddResourceArray(): void $this->object->addResource($array); - $data = Assert::readAttribute($this->object, 'data'); + $data = $this->object->__debugInfo(); static::assertArrayHasKey('en-CA', $data); static::assertArrayHasKey('fr-CA', $data); @@ -171,12 +169,11 @@ public function testAddResourceJson(): void { $this->object->addResource($this->json, 'json'); - $data = Assert::readAttribute($this->object, 'data'); + $data = $this->object->__debugInfo(); static::assertNotEmpty($data); static::assertArrayHasKey('en-CA', $data); static::assertArrayHasKey('fr-CA', $data); - static::assertNotEmpty(Assert::readAttribute($this->object, 'arrayGroups')); } /** @@ -362,7 +359,7 @@ public function testLocalize1DArray(): void static::assertEquals([ 'headsign' => 'Blackbird Mall', - 'subtext' => 'Rue Main' + 'subtext' => 'Rue Main', ], $arr1); } @@ -381,13 +378,13 @@ public function testLocalize2DArray(): void static::assertEquals([ ['headsign' => 'University'], ['headsign' => 'College'], - ['headsign' => 'Airport'] + ['headsign' => 'Airport'], ], $arr1); static::assertEquals([ ['headsign' => 'Université'], ['headsign' => 'Collège'], - ['headsign' => 'Aéroport'] + ['headsign' => 'Aéroport'], ], $arr2); } @@ -408,9 +405,9 @@ public function testLocalize3DArray(): void 'crosstown' => [ ['headsign' => 'Blackbird Mall'], ['headsign' => 'University'], - ['headsign' => 'College'] - ]], $arr - ); + ['headsign' => 'College'], + ], + ], $arr); } /**