/**
* Abstract test
*
* @param mixed $value1 first value to push
* @param mixed $value2 second value to push
* @param array $expectedList expected list, stored in db
* @param int $fieldName name of field, where values pushed: one of self::FIELD_NAME_*
* @param bool $isDocumentSaved is document already stored to db before push
*/
private function doPushTest($value1, $value2, $expectedList, $fieldName, $isDocumentSaved)
{
// create document
$doc = $this->collection->createDocument($this->initialDocument);
// test push to saved or new document
if ($isDocumentSaved) {
$doc->save();
}
// prepare expected value
switch ($fieldName) {
case self::FIELD_NAME_SCALAR:
$expectedList = array_merge(array($this->initialDocument[$fieldName]), $expectedList);
break;
case self::FIELD_NAME_LIST:
$expectedList = array_merge($this->initialDocument[$fieldName], $expectedList);
break;
}
// push single to empty
$doc->push($fieldName, $value1)->push($fieldName, $value2);
// test document in identity map after push before save
$this->assertEquals($expectedList, $doc->get($fieldName));
$doc->save();
// test document in identity map after push after save
$this->assertEquals($expectedList, $this->collection->getDocument($doc->getId())->get($fieldName));
// test document in db
$this->assertEquals($expectedList, $this->collection->getDocumentDirectly($doc->getId())->get($fieldName));
}