diff --git a/src/Model/JsonStringConvertible.php b/src/Model/JsonStringConvertible.php index 5222474..8c9c712 100644 --- a/src/Model/JsonStringConvertible.php +++ b/src/Model/JsonStringConvertible.php @@ -14,9 +14,12 @@ public static function fromJSON(string $json): self return static::jsonDeserialize($object); } - public function toJSON(): string + public function toJSON(int $flags = 0): string { - return \Safe\json_encode(static::jsonSerialize()); + return \Safe\json_encode( + static::jsonSerialize(), + $flags + ); } abstract public static function jsonDeserialize(\stdClass $object): self; diff --git a/src/Model/Value.php b/src/Model/Value.php index d7eafeb..ad5204b 100644 --- a/src/Model/Value.php +++ b/src/Model/Value.php @@ -15,10 +15,10 @@ public function __construct(Document $document) $this->document = $document; } - public static function jsonDeserialize(\stdClass $value): self + public static function jsonDeserialize(\stdClass $object): self { return new self( - Document::jsonDeserialize($value->document) + Document::jsonDeserialize($object->document) ); } diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index 6dbc211..4a707ae 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -8,7 +8,7 @@ public function testGetConcatenatedPlainTextContentOfInnerNodes(): void { $document = $this->loadDocumentFromFixture(__DIR__ . '/fixtures/document_with_text.json'); - $this->assertEquals( + $this->assertSame( "I'd like to introduce you to a very important person!", $document->text ); diff --git a/tests/LeafTest.php b/tests/LeafTest.php new file mode 100644 index 0000000..219de5f --- /dev/null +++ b/tests/LeafTest.php @@ -0,0 +1,15 @@ +assertSame('{"object":"leaf","text":"foo 😎","marks":[]}', $leaf->toJSON(JSON_UNESCAPED_UNICODE)); + $this->assertSame('{"object":"leaf","text":"foo \ud83d\ude0e","marks":[]}', $leaf->toJSON()); + } +} diff --git a/tests/UnserializerTest.php b/tests/UnserializerTest.php index 61a7c61..b5744a1 100644 --- a/tests/UnserializerTest.php +++ b/tests/UnserializerTest.php @@ -67,9 +67,9 @@ public function testAddChildrenToDocument(): void $this->assertInstanceOf(Block::class, $node); } - $this->assertEquals('paragraph', $nodes[0]->type); - $this->assertEquals('blockquote', $nodes[1]->type); - $this->assertEquals('list', $nodes[2]->type); + $this->assertSame('paragraph', $nodes[0]->type); + $this->assertSame('blockquote', $nodes[1]->type); + $this->assertSame('list', $nodes[2]->type); } public function testNestChildren(): void @@ -109,7 +109,7 @@ public function testLoadDocumentWithLeaves(): void foreach ($text->leaves as $i => $leaf) { $this->assertInstanceOf(Leaf::class, $leaf); - $this->assertEquals($expected_texts[$i], $leaf->text); + $this->assertSame($expected_texts[$i], $leaf->text); } } @@ -122,8 +122,8 @@ public function testSetNodeData(): void $block->data ); - /** @var Inline $inline */ $inline = $block->nodes[0]; + assert($inline instanceof Inline); $this->assertEquals( (object) ['name' => 'John Doe', 'id' => 1234], $inline->data diff --git a/tests/ValueTest.php b/tests/ValueTest.php index 5264436..dfd4178 100644 --- a/tests/ValueTest.php +++ b/tests/ValueTest.php @@ -5,7 +5,7 @@ final class ValueTest extends TestCase { /** @dataProvider fixtures */ - public function testSerializeToJson(string $filePath): void + public function testSerializeToJSON(string $filePath): void { $json = $this->loadFixture($filePath); $value = $this->loadContentFromFixture($filePath); @@ -18,7 +18,7 @@ public function testSerializeToJson(string $filePath): void ) ); - $this->assertEquals(trim($json), \Safe\json_encode($value, JSON_PRETTY_PRINT)); + $this->assertSame(trim($json), \Safe\json_encode($value, JSON_PRETTY_PRINT)); } /** @return iterable */