Example #1
0
 /**
  * @param array $expectedTablesCounts
  */
 private function thenItShouldHaveGeneratedTheRecords($expectedTablesCounts)
 {
     foreach ($expectedTablesCounts as $tableName => $expectedTablesCount) {
         $recordIds = $this->recordGenerator->getRecordIds($tableName);
         $this->assertCount($expectedTablesCount, $recordIds);
     }
 }
Example #2
0
 /**
  * @param string $name
  */
 private function thenUser_AndHisCommentIsDeleted($name)
 {
     // there is a warning (undefined offset). when this code is reached that issue is fixed
     $rm = self::createDefaultRecordManager();
     $queryHasResult = $rm->createQuery('user')->andWhere('username = ?', $name)->hasResult();
     $this->assertFalse($queryHasResult, "Expected, that user {$name} has been deleted");
     $userCommentId = $this->recordGenerator->getRecordIdFromMap('comment', 'PreparedForDeletion');
     $queryHasResult = $rm->createQuery('comment')->andWhere('id = ?', $userCommentId)->hasResult();
     $this->assertFalse($queryHasResult, "Expected, that user comment of user {$name} has been deleted");
 }
Example #3
0
 /**
  * NOTE Table should use a different record manager than generator to use different table repositories
  *
  * @param \Dive\Record\Generator\RecordGenerator $generator
  * @param  Table            $table
  * @param  string           $recordKey
  * @return Record
  */
 protected function getGeneratedRecord(RecordGenerator $generator, Table $table, $recordKey)
 {
     $tableName = $table->getTableName();
     $pk = $generator->getRecordIdFromMap($tableName, $recordKey);
     if ($table->hasCompositePrimaryKey()) {
         $pk = explode(Record::COMPOSITE_ID_SEPARATOR, $pk);
     }
     $record = $table->findByPk($pk);
     $message = "Could not load record for '{$recordKey}' in table '{$tableName}'";
     $this->assertInstanceOf('\\Dive\\Record', $record, $message);
     return $record;
 }
 /**
  * @dataProvider provideDeleteBothForRestrictedConstraint
  * @param string $tableName
  * @param string $restrictedByRelation
  * @param array  $deleteOrder
  */
 public function testDeleteBothForRestrictedConstraint($tableName, $restrictedByRelation, array $deleteOrder)
 {
     // get record manager for fixture scheme
     $rm = self::createDefaultRecordManager(self::getSchemaDefinition());
     $recordGenerator = new Record\Generator\RecordGenerator($rm, new FieldValuesGenerator());
     // we generate two records, which both will be deleted
     // second record is needed for testing, that restrict-map is cleared after commit
     $tableRows = array('myRecord' => array(), 'myRecord2' => array());
     $recordGenerator->setTableRows($tableName, $tableRows)->generate();
     $table = $rm->getTable($tableName);
     foreach ($tableRows as $recordKey => $recordData) {
         // get record and restricted by relation-record
         $recordId = $recordGenerator->getRecordIdFromMap($tableName, $recordKey);
         $record = $table->findByPk($recordId);
         $restrictedByRecord = $record->{$restrictedByRelation};
         if ($restrictedByRecord instanceof RecordCollection) {
             $restrictedByRecord = $restrictedByRecord[0];
         }
         // delete in right order
         $deleteMap = array($tableName => $record, $restrictedByRelation => $restrictedByRecord);
         foreach ($deleteOrder as $deleteKey) {
             $rm->scheduleDelete($deleteMap[$deleteKey]);
         }
         // commit should NOT throw Exception
         $e = null;
         try {
             $rm->commit();
         } catch (\Exception $e) {
             // do nothing
         }
         $this->assertNull($e);
     }
 }