Esempio n. 1
0
    protected function setUp()
    {
        $this->checkPersonFile();
        $this->setUpXhprof();
        $fixtureJSON = <<<FIXTURE
{
        "_id": 1,
        "congress_numbers": [
            99
        ],
        "current": false,
        "description": "Representative for Hawaii's 1st congressional district",
        "district": 1,
        "enddate": "1986-10-18",
        "leadership_title": null,
        "party": "Democrat",
        "person": {
            "bioguideid": "A000014",
            "birthday": "1938-06-26",
            "cspanid": null,
            "firstname": "Neil",
            "gender": "male",
            "gender_label": "Male",
            "id": 400001,
            "lastname": "Abercrombie",
            "link": "https:\\/\\/www.govtrack.us\\/congress\\/members\\/neil_abercrombie\\/400001",
            "middlename": "",
            "name": "Rep. Neil Abercrombie [D-HI1, 1991-2010]",
            "namemod": "",
            "nickname": "",
            "osid": "N00007665",
            "pvsid": "26827",
            "sortname": "Abercrombie, Neil (Rep.) [D-HI1, 1991-2010]",
            "twitterid": null,
            "youtubeid": null
        },
        "phone": null,
        "role_type": "representative",
        "role_type_label": "Representative",
        "senator_class": null,
        "senator_rank": null,
        "startdate": "1985-01-03",
        "state": "HI",
        "title": "Rep.",
        "title_long": "Representative",
        "website": ""
    }
FIXTURE;
        $document = new Document();
        $document->setData(json_decode($fixtureJSON, TRUE));
        $document->setDatabaseIdentifier('congress_members');
        $document->setCreationTime(isset($rawMetaData['creation_time']) ? $rawMetaData['creation_time'] : NULL);
        $document->setModificationTime(isset($rawMetaData['modification_time']) ? $rawMetaData['modification_time'] : NULL);
        $this->fixture = $document;
    }
Esempio n. 2
0
 /**
  * @test
  */
 public function valueForKeyPathTest()
 {
     $this->assertEquals(1, $this->fixture->valueForKeyPath(Constants::DATA_ID_KEY));
     $this->assertEquals('Representative for Hawaii\'s 1st congressional district', $this->fixture->valueForKeyPath('description'));
     $this->assertEquals(1, $this->fixture->valueForKeyPath('district'));
     $this->assertEquals('1986-10-18', $this->fixture->valueForKeyPath('enddate'));
     $this->assertEquals(null, $this->fixture->valueForKeyPath('leadership_title'));
     $this->assertEquals('Democrat', $this->fixture->valueForKeyPath('party'));
     $this->assertEquals('Neil', $this->fixture->valueForKeyPath('person.firstname'));
     $this->assertEquals('male', $this->fixture->valueForKeyPath('person.gender'));
     $this->assertEquals('Abercrombie', $this->fixture->valueForKeyPath('person.lastname'));
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
 /**
  * @test
  */
 public function sortPersonsByLatitudeAfterAddingAPersonTest()
 {
     $this->checkPersonFile();
     /** @var Reader $databaseReader */
     $databaseReader = $this->getDiContainer()->get('\\Cundd\\PersistentObjectStore\\DataAccess\\Reader');
     $newlyLoadedDatabase = $databaseReader->loadDatabase('people');
     $dataInstance = new Document();
     $dataInstance->setData(array('_id' => '541f004ef8f4d2df32ca60c2', 'index' => 5000, 'isActive' => FALSE, 'balance' => '$2,925.56', 'picture' => 'http://placehold.it/32x32', 'age' => 31, 'eyeColor' => 'brown', 'name' => 'Daniel Corn', 'gender' => 'male', 'company' => 'FARMEX', 'email' => '*****@*****.**', 'phone' => '+1 (973) 480-3194', 'address' => '125 Stone Avenue, Worton, Alabama, 6669', 'about' => 'Dolore in excepteur nisi dolor laboris ipsum proident cupidatat proident. Aliquip commodo culpa adipisicing ullamco ad. Ut ex duis tempor do id enim. Proident exercitation officia veniam magna mollit nostrud duis do qui reprehenderit. Ea culpa anim ullamco aliqua culpa nulla ex nisi irure qui incididunt reprehenderit. Labore do velit amet duis aute occaecat. Et sunt ex Lorem qui do deserunt ullamco labore.\\r\\n', 'registered' => '2014-06-29T15:29:47 -02:00', 'latitude' => 52.37284, 'longitude' => -70.88927, 'tags' => ['id', 'consequat', 'aute', 'deserunt', 'in', 'enim', 'veniam'], 'friends' => [array('id' => 0, 'name' => 'Bray Ruiz'), array('id' => 1, 'name' => 'Carr Kerr'), array('id' => 2, 'name' => 'Carter Dejesus')], 'greeting' => 'Hello, Conway Burch! You have 3 unread messages.', 'favoriteFruit' => 'apple'));
     $newlyLoadedDatabase->add($dataInstance);
     /** @var Database $database */
     $database = $this->coordinator->getDatabase('people');
     //		$start = microtime(TRUE);
     $sortedDatabase = $this->fixture->sortCollectionByPropertyKeyPath($newlyLoadedDatabase, 'latitude');
     //		$end = microtime(TRUE);
     //		printf("Sort %0.8f\n", $end - $start);
     $maxIterations = 100;
     $maxIterations = $database->count();
     // TODO: Make this work
     // $this->assertEquals($database->count(), $sortedDatabase->count());
     // $this->assertNotEquals($database->count(), $newlyLoadedDatabase->count());
     //		var_dump($sortedDatabase[$sortedDatabase->count() - 1]);
     $lastLatitude = -PHP_INT_MAX;
     for ($i = 0; $i < $maxIterations; $i++) {
         /** @var DocumentInterface $item */
         $item = $sortedDatabase[$i];
         $this->assertNotNull($item);
         //			printf('%d: Last latitude %0.9f to current %0.9f' . PHP_EOL, $i, $lastLatitude, $item->valueForKey('latitude'));
         if ($lastLatitude === $item->valueForKey('latitude')) {
             DebugUtility::var_dump($i, $item, $sortedDatabase[$i - 1]);
         }
         $this->assertGreaterThan($lastLatitude, $item->valueForKey('latitude'), 'Current latitude is not bigger than last for loop number ' . $i);
         $lastLatitude = $item->valueForKey('latitude');
     }
     //		$sortedDatabase = $this->fixture->sortCollectionByPropertyKeyPath($database, 'latitude', TRUE);
     //
     //		$this->assertEquals($database->count(), $sortedDatabase->count());
     //
     //		$lastLatitude = PHP_INT_MAX;
     //		for ($i = 0; $i < $maxIterations; $i++) {
     //			/** @var DocumentInterface $item */
     //			$item = $sortedDatabase[$i];
     //			$this->assertNotNull($item);
     //
     //			$this->assertLessThan($lastLatitude, $item->valueForKey('latitude'));
     //			$lastLatitude = $item->valueForKey('latitude');
     //		}
 }