diff --git a/src/Document.php b/src/Document.php index b895933..6986336 100644 --- a/src/Document.php +++ b/src/Document.php @@ -87,6 +87,7 @@ public function has(string $offset) public function with(array $fields) { $document = new static(); + $document->collection = $this->collection; $document->document = []; foreach ($fields as $field) { @@ -108,6 +109,7 @@ public function with(array $fields) public function without(array $fields) { $document = new static(); + $document->collection = $this->collection; $document->document = []; foreach ($this->document as $key => $value) { diff --git a/tests/Tests/DocumentTest.php b/tests/Tests/DocumentTest.php index 061fc09..08e70b8 100644 --- a/tests/Tests/DocumentTest.php +++ b/tests/Tests/DocumentTest.php @@ -3,9 +3,12 @@ namespace Xenus\Tests\Tests; use Xenus\Document; +use Xenus\Tests\Support\SetupCollectionTest; class DocumentTest extends \PHPUnit\Framework\TestCase { + use SetupCollectionTest; + public function test_has_method() { $document = new Document([ @@ -85,6 +88,8 @@ public function test_with_method() protected $withId = true; }; + $document->connect($this->cities); + $document = $document->fill([ 'name' => 'Antoine', 'city' => 'Paris' ]); @@ -100,6 +105,10 @@ public function test_with_method() $this->assertEquals( ['name' => 'Antoine'], $document->with(['name', 'unknown'])->toArray() ); + + $this->assertEquals( + $document->collection(), $document->with([])->collection() + ); } public function test_without_method() @@ -108,6 +117,8 @@ public function test_without_method() protected $withId = true; }; + $document->connect($this->cities); + $document = $document->fill([ 'name' => 'Antoine', 'city' => 'Paris' ]); @@ -119,6 +130,10 @@ public function test_without_method() $this->assertEquals( ['name' => 'Antoine', 'city' => 'Paris'], $document->without(['_id'])->toArray() ); + + $this->assertEquals( + $document->collection(), $document->without([])->collection() + ); } public function test_get_from_getter_method()