/** * A test that should validate the behavior of data object references in a database * * @test */ public function objectLiveCycleTest() { $database2 = $this->coordinator->getDatabase('people'); /** @var DocumentInterface $personFromDatabase2 */ $personFromDatabase2 = $database2->current(); /** @var DocumentInterface $personFromFixture */ $personFromFixture = $this->fixture->current(); $this->assertEquals($personFromDatabase2, $personFromFixture); $movie = 'Star Wars'; $key = 'favorite_movie'; $personFromDatabase2->setValueForKey($movie, $key); $this->assertEquals($personFromDatabase2, $personFromFixture); $this->assertSame($personFromDatabase2, $personFromFixture); $this->assertEquals($movie, $personFromFixture->valueForKey($key)); $this->assertEquals($movie, $personFromDatabase2->valueForKey($key)); }
/** * Fills the database with the given data * * @param Database $database * @param array<Document> $data * @param array<Document> $metaData */ protected function _fillDatabaseWithData($database, $dataCollection, $metaDataCollection) { $database->setRawData($dataCollection); }
/** * Creates a deep clone of the given collection * * @param Database|Iterator $originalCollection * @return \SplObjectStorage */ protected function _cloneCollection($originalCollection) { // If the collection is immutable just return it if ($originalCollection instanceof Immutable) { return $originalCollection; } if ($originalCollection instanceof DatabaseInterface) { return clone $originalCollection; } $collection = new SplFixedArray($originalCollection->count()); $i = 0; foreach ($originalCollection as $item) { $collection[$i] = clone $item; $i++; } $collection->rewind(); return $collection; }