Skip to content

Commit

Permalink
Merge branch '3.5' into 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed May 6, 2018
2 parents 75c0919 + e73760b commit 4ca6d97
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/KeywordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ 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);

$this->assertNull($stub2->getSlug());
$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 */
Expand All @@ -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']));
}
}
62 changes: 62 additions & 0 deletions tests/SerializerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Orchestra\Support\TestCase;

use Orchestra\Support\Fluent;
use PHPUnit\Framework\TestCase;
use Orchestra\Support\Serializer;
use Illuminate\Support\Collection;

class SerializerTest extends TestCase
{
/** @test */
public function it_can_serialize_single_dataset()
{
$dataset = new Fluent([
'fullname' => 'Mior Muhammad Zaki', 'email' => '[email protected]',
]);

$serializer = new class() extends Serializer {
protected $key = 'user';
};

$this->assertSame([
'user' => [
'fullname' => 'Mior Muhammad Zaki',
'email' => '[email protected]',
],
], $serializer($dataset));
}

/** @test */
public function it_can_serialize_dataset_collection()
{
$dataset = new Collection(
[
new Fluent([
'fullname' => 'Mior Muhammad Zaki', 'email' => '[email protected]',
]),
new Fluent([
'fullname' => 'Miki', 'email' => '[email protected]',
])
]
);

$serializer = new class() extends Serializer {
protected $key = 'user';
};

$this->assertSame([
'users' => [
[
'fullname' => 'Mior Muhammad Zaki',
'email' => '[email protected]',
],
[
'fullname' => 'Miki',
'email' => '[email protected]',
],
],
], $serializer($dataset));
}
}

0 comments on commit 4ca6d97

Please sign in to comment.