From fcbe23d3cd53fa4cec527397c2aa07b305e4e3d4 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sun, 29 Apr 2018 12:59:33 +0800 Subject: [PATCH 1/2] Add serializer tests. Signed-off-by: Mior Muhammad Zaki --- tests/SerializerTest.php | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/SerializerTest.php diff --git a/tests/SerializerTest.php b/tests/SerializerTest.php new file mode 100644 index 0000000..73c945b --- /dev/null +++ b/tests/SerializerTest.php @@ -0,0 +1,62 @@ + 'Mior Muhammad Zaki', 'email' => 'crynobone@gmail.com', + ]); + + $serializer = new class() extends Serializer { + protected $key = 'user'; + }; + + $this->assertSame([ + 'user' => [ + 'fullname' => 'Mior Muhammad Zaki', + 'email' => 'crynobone@gmail.com', + ], + ], $serializer($dataset)); + } + + /** @test */ + public function it_can_serialize_dataset_collection() + { + $dataset = new Collection( + [ + new Fluent([ + 'fullname' => 'Mior Muhammad Zaki', 'email' => 'crynobone@gmail.com', + ]), + new Fluent([ + 'fullname' => 'Miki', 'email' => 'hello@orchestraplatform.com', + ]) + ] + ); + + $serializer = new class() extends Serializer { + protected $key = 'user'; + }; + + $this->assertSame([ + 'users' => [ + [ + 'fullname' => 'Mior Muhammad Zaki', + 'email' => 'crynobone@gmail.com', + ], + [ + 'fullname' => 'Miki', + 'email' => 'hello@orchestraplatform.com', + ], + ], + ], $serializer($dataset)); + } +} From e73760ba10235481e2d0c8d9f67db9447f89239e Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Sun, 29 Apr 2018 16:32:06 +0800 Subject: [PATCH 2/2] Improves keyword tests. Signed-off-by: Mior Muhammad Zaki --- tests/KeywordTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/KeywordTest.php b/tests/KeywordTest.php index a5d3525..3dbd3e5 100644 --- a/tests/KeywordTest.php +++ b/tests/KeywordTest.php @@ -17,6 +17,8 @@ public function it_can_be_used() $this->assertEquals('Hello World', $stub1->getValue()); $this->assertEquals(1, $stub1->searchIn(['foo', 'hello-world'])); $this->assertFalse($stub1->searchIn(['foo', 'bar'])); + $this->assertTrue($stub1->hasIn(['foo' => 'Foobar', 'hello-world' => 'Hello World'])); + $this->assertFalse($stub1->hasIn(['foo' => 'Foo', 'bar' => 'Bar'])); $stub2 = Keyword::make(5); @@ -24,6 +26,8 @@ public function it_can_be_used() $this->assertEmpty((string) $stub2); $this->assertEquals(5, $stub2->getValue()); $this->assertEquals(4, $stub2->searchIn(['hello', 'world', 'foo', 'bar', 5, 'foobar'])); + $this->assertTrue($stub2->hasIn(['foo' => 'Foobar', 5 => 'Hello World'])); + $this->assertFalse($stub2->hasIn(['foo' => 'Foo', 'bar' => 'Bar'])); } /** @test */ @@ -34,5 +38,7 @@ public function it_can_return_self_when_given_same_type() $stub = Keyword::make($keyword); $this->assertEquals($keyword, $stub); + $this->assertTrue($stub->hasIn(['foo' => 'Foobar', 'hello' => 'Hello World'])); + $this->assertFalse($stub->hasIn(['foo' => 'Foo', 'bar' => 'Bar'])); } }