예제 #1
0
 /**
  * @test
  */
 public function removeFromDatabaseTest()
 {
     $databaseIdentifier = 'contacts';
     $testEmail = '*****@*****.**';
     /** @var Database $database */
     $database = $this->fixture->getDatabase($databaseIdentifier);
     $dataInstance = new Document();
     $dataInstance->setData(array('firstName' => 'Paul', 'lastName' => 'McKenzy', 'email' => $testEmail));
     $database->remove($dataInstance);
     $this->assertEquals($this->numberOfContacts - 1, $database->count());
     // A database just loaded from the filesystem should only contain the original number of entries
     /** @var DatabaseInterface $newlyLoadedDatabase */
     $newlyLoadedDatabase = $this->databaseReader->loadDatabase($databaseIdentifier);
     $this->assertEquals($this->numberOfContacts, $newlyLoadedDatabase->count());
     $this->assertEquals($database->count() + 1, $newlyLoadedDatabase->count());
     // A database again retrieved from the coordinator should contain the added entry
     /** @var DatabaseInterface $databaseRetrievedFromTheCoordinator */
     $databaseRetrievedFromTheCoordinator = $this->fixture->getDatabase($databaseIdentifier);
     $this->assertEquals($this->numberOfContacts - 1, $databaseRetrievedFromTheCoordinator->count());
     $this->assertEquals($database->count(), $databaseRetrievedFromTheCoordinator->count());
     $expectedPath = ConfigurationManager::getSharedInstance()->getConfigurationForKeyPath('writeDataPath') . $databaseIdentifier . '.json';
     $this->fixture->commitDatabase($database);
     $this->assertFileExists($expectedPath);
     $writtenData = json_decode(file_get_contents($expectedPath), TRUE);
     $this->assertTrue($writtenData !== FALSE);
     foreach ($writtenData as $data) {
         $this->assertNotEquals($testEmail, isset($data['email']) ? $data['email'] : 'no-email-at-all');
     }
     //		$this->assertEquals($database->count(), count($writtenData));
     //		$this->assertEquals($this->numberOfContacts - 1, count($writtenData));
     unlink($expectedPath);
 }
예제 #2
0
 /**
  * Returns the database with the given identifier
  *
  * @param string $databaseIdentifier
  * @return Database
  */
 protected function _getDatabase($databaseIdentifier)
 {
     if (!Manager::hasObject($databaseIdentifier)) {
         $memoryUsage = NULL;
         $database = $this->dataReader->loadDatabase($databaseIdentifier, $memoryUsage);
         Manager::registerObject($database, $databaseIdentifier, array(self::MEMORY_MANAGER_TAG));
         return $database;
     }
     return Manager::getObject($databaseIdentifier);
 }