public function testToString()
 {
     $this->fixture->setAttackers(array(1, 2))->setTime(new MongoDate(time() - 4000))->setVictimId(3)->setVictimShip(4)->setFinalBlowAttacker(1);
     $expected = $this->fixture->generateHash();
     $actual = (string) $this->fixture;
     $this->assertEquals($expected, $actual);
     $actual = $this->fixture->__toString();
     $this->assertEquals($expected, $actual);
 }
 /**
  * Get the ID hash, generate one if not available
  *
  * @return string
  */
 protected function getIdHash()
 {
     if (!$this->idHash) {
         $this->idHash = Kingboard_KillmailHash_IdHash::getByData(array('killTime' => $this->getTime(), 'victim' => $this->getVictim(), 'attackers' => $this->getAttackers(), 'items' => $this->getItems()));
     }
     return $this->idHash->generateHash();
 }
 public function parseKills($kills)
 {
     $oldkills = 0;
     $newkills = 0;
     $errors = 0;
     $lastID = 0;
     $lastIntID = 0;
     foreach ($kills as $kill) {
         try {
             // this needs to be run before exit of loop, otherwise having all kills of this run
             // will cause the lastID not being updated
             if (!is_null($kill->killID) && $kill->killID > 0) {
                 $lastID = $kill->killID;
             }
             if (!is_null(@$kill->killInternalID) && @$kill->killInternalID > 0) {
                 $lastIntID = $kill->killInternalID;
             }
             /*if(!is_null(Kingboard_Kill::getByKillId($kill->killID)))
               {
                   $oldkills++;
                   continue;
               }*/
             $killdata = array("killID" => $kill->killID, "solarSystemID" => $kill->solarSystemID, "location" => array("solarSystem" => Kingboard_EveSolarSystem::getBySolarSystemId($kill->solarSystemID)->itemName, "security" => Kingboard_EveSolarSystem::getBySolarSystemId($kill->solarSystemID)->security, "region" => Kingboard_EveSolarSystem::getBySolarSystemId($kill->solarSystemID)->Region['itemName']), "killTime" => new MongoDate(strtotime($kill->killTime)), "moonID" => $kill->moonID, "victim" => array("characterID" => $this->ensureCharacterID($kill->victim->characterID, $kill->victim->characterName), "characterName" => $kill->victim->characterName, "corporationID" => $this->ensureCorporationID($kill->victim->corporationID, $kill->victim->corporationName), "corporationName" => $kill->victim->corporationName, "allianceID" => (int) $kill->victim->allianceID, "allianceName" => $kill->victim->allianceName, "factionID" => (int) $kill->victim->factionID, "factionName" => $kill->victim->factionName, "damageTaken" => $kill->victim->damageTaken, "shipTypeID" => (int) $kill->victim->shipTypeID, "shipType" => Kingboard_EveItem::getByItemId($kill->victim->shipTypeID)->typeName));
             $killdata['attackers'] = array();
             foreach ($kill->attackers as $attacker) {
                 $killdata['attackers'][] = array("characterID" => $attacker->characterID, "characterName" => $attacker->characterName, "entityType" => Kingboard_Helper_EntityType::getEntityTypeByEntityId((int) $attacker->characterID), "corporationID" => $this->ensureCorporationID($attacker->corporationID, $attacker->corporationName), "corporationName" => $attacker->corporationName, "allianceID" => (int) $attacker->allianceID, "allianceName" => $attacker->allianceName, "factionID" => (int) $attacker->factionID, "factionName" => $attacker->factionName, "securityStatus" => $attacker->securityStatus, "damageDone" => $attacker->damageDone, "finalBlow" => $attacker->finalBlow, "weaponTypeID" => (int) $attacker->weaponTypeID, "weaponType" => Kingboard_EveItem::getByItemId($attacker->weaponTypeID)->typeName, "shipTypeID" => (int) $attacker->shipTypeID, "shipType" => Kingboard_EveItem::getByItemId($attacker->shipTypeID)->typeName);
             }
             $killdata['items'] = array();
             if (isset($kill->items) && !is_null($kill->items)) {
                 foreach ($kill->items as $item) {
                     $killdata['items'][] = $this->ParseItem($item);
                 }
             }
             $hash = Kingboard_KillmailHash_IdHash::getByData($killdata);
             $killdata['idHash'] = (string) $hash;
             if (is_null(Kingboard_Kill::getInstanceByIdHash($killdata['idHash']))) {
                 $killObject = new Kingboard_Kill();
                 $killObject->injectDataFromMail($killdata);
                 $killObject->save();
                 $newkills++;
             } else {
                 $oldkills++;
             }
         } catch (Kingboard_KillmailParser_KillmailErrorException $e) {
             $errors++;
         }
     }
     return array('oldkills' => $oldkills, 'newkills' => $newkills, 'lastID' => $lastID, 'lastIntID' => $lastIntID, 'errors' => $errors);
 }
 public function testIfCollisionCanOccurWithTheCurrentIdHash()
 {
     // Comment out the next linge to enable the test
     $this->markTestSkipped('Not part of the build process');
     $found = array();
     $errors = array();
     $allKills = Kingboard_Kill::find();
     foreach ($allKills as $kill) {
         $hash = new Kingboard_KillmailHash_IdHash();
         $hash->setVictimId((int) (empty($kill['victim']['characterID']) ? $kill['victim']['corporationID'] : $kill['victim']['characterID']));
         $hash->setTime(new MongoDate(strtotime(str_replace('.', '-', $kill['killTime']))));
         $hash->setVictimShip($kill['victim']['shipTypeID']);
         foreach ($kill['attackers'] as $attacker) {
             $hash->pushAttackerData($attacker);
         }
         foreach ($kill['items'] as $item) {
             $hash->addItem($item);
         }
         try {
             $hash = $hash->generateHash();
             if (!isset($found[$hash])) {
                 $found[$hash] = array();
             }
             $found[$hash][] = $kill['killID'];
         } catch (Kingboard_KillmailHash_ErrorException $e) {
             $errors[] = "Error {$e->getMessage()}: at kill {$kill['killID']}\n";
         }
     }
     if (!empty($errors)) {
         echo implode('', $errors) . "\n";
     }
     $collisions = false;
     foreach ($found as $hash => $foundOnes) {
         if (count($foundOnes) > 1) {
             echo "Hash '{$hash}' generated for this kills: " . implode(', ', $foundOnes) . "\n";
             $collisions = true;
         }
     }
     if ($collisions) {
         $this->fail('Collisions detected');
     }
 }
 /**
  * Method that takes an associative array with killmail data and creates a hash for that.
  * 
  * @static
  * @param array $data
  * @return Kingboard_KillmailHash_IdHash
  */
 public static function getByData($data)
 {
     $victimId = !empty($data['victim']['characterID']) ? $data['victim']['characterID'] : $data['victim']['corporationID'];
     $idHash = new Kingboard_KillmailHash_IdHash();
     $idHash->setVictimId($victimId)->setVictimShip($data['victim']['shipTypeID'])->setTime($data['killTime']);
     foreach ($data['items'] as $item) {
         $idHash->addItem($item);
     }
     foreach ($data['attackers'] as $attacker) {
         $idHash->pushAttackerData($attacker);
     }
     return $idHash;
 }