Ejemplo n.º 1
0
 /**
  * @param Record $other
  *
  * @return string
  */
 protected function failureDescription($other)
 {
     $otherOid = $other && $other instanceof Record ? $other->getOid() : 'NULL';
     $relation = $this->record->getTableRelation($this->relationName);
     $otherTableName = $relation->isOwningSide($this->relationName) ? $relation->getOwningTable() : $relation->getReferencedTable();
     $msg = $this->toString() . " to {$otherTableName}[{$otherOid}]";
     if ($otherOid === $this->record->getOid()) {
         $msg .= ", both have the same oid";
     }
     return $msg;
 }
 /**
  * @param Record $other
  *
  * @return string
  */
 protected function failureDescription($other)
 {
     $otherId = $other->getInternalId();
     $relation = $this->record->getTableRelation($this->relationName);
     $otherTableName = $relation->isOwningSide($this->relationName) ? $relation->getOwningTable() : $relation->getReferencedTable();
     return $this->toString() . " to {$otherTableName}[{$otherId}]";
 }
Ejemplo n.º 3
0
 /**
  * @param Record $record
  * @param array  $referenceMap
  */
 private function assertRecordReferenceMap(Record $record, array $referenceMap)
 {
     if (empty($referenceMap)) {
         return;
     }
     foreach ($referenceMap as $relationName => $refObjectIds) {
         $relation = $record->getTableRelation($relationName);
         if ($relation->isOwningSide($relationName)) {
             $this->assertOwningRelatedReferences($record, $relation, $refObjectIds);
         } else {
             $this->assertReferencedRelatedReferences($record, $relation, $refObjectIds);
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * @param Record $record
  * @param string $relationName
  * @param string $message
  */
 private function assertRecordIsNotReferencedByRelation(Record $record, $relationName, $message = '')
 {
     $internalId = $record->getInternalId();
     $relation = $record->getTableRelation($relationName);
     $isReferencedSide = $relation->isReferencedSide($relationName);
     /** @var ReferenceMap $referenceMap */
     $referenceMap = self::readAttribute($relation, 'map');
     $isOneToMany = $relation->isOneToMany();
     /** @var RecordCollection[] $relatedCollections */
     $relatedCollections = $isOneToMany ? self::readAttribute($referenceMap, 'relatedCollections') : null;
     $references = $referenceMap->getMapping();
     $referencedMessage = $message . " expected not be referenced (relation '{$relationName}')";
     $relatedCollectionMessage = $message . " expected not to be in a related collection (relation '{$relationName}')";
     $oid = $record->getOid();
     if ($isReferencedSide) {
         foreach ($references as $owningIds) {
             if ($isOneToMany) {
                 $this->assertNotContains($internalId, $owningIds, $referencedMessage);
             } else {
                 $this->assertNotEquals($internalId, $owningIds, $referencedMessage);
             }
         }
         if ($isOneToMany) {
             foreach ($relatedCollections as $relatedCollection) {
                 $this->assertFalse($relatedCollection->has($record), $relatedCollectionMessage);
             }
         }
         $this->assertFalse($referenceMap->hasFieldMapping($oid));
     } else {
         $this->assertArrayNotHasKey($internalId, $references, $referencedMessage);
         if ($isOneToMany) {
             $this->assertArrayNotHasKey($oid, $relatedCollections, $relatedCollectionMessage);
         }
     }
 }
 /**
  * @return Relation
  */
 private function getRelation()
 {
     $relationName = CamelCase::toCamelCase($this->relatedRecord->getTable()->getTableName());
     return $this->storedRecord->getTableRelation($relationName);
 }