示例#1
0
 /**
  * test grabbing a Favorite by profile id
  **/
 public function testGetValidFavoriteByProfileId()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("favorite");
     // create a new Favorite and insert to into mySQL
     $favorite = new Favorite($this->tweet->getTweetId(), $this->profile->getProfileId(), $this->VALID_FAVORITEDATE);
     $favorite->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $results = Favorite::getFavoriteByProfileId($this->getPDO(), $this->profile->getProfileId());
     $this->assertEquals($numRows + 1, $this->getConnection()->getRowCount("favorite"));
     $this->assertCount(1, $results);
     $this->assertContainsOnlyInstancesOf("Favorite", $results);
     // grab the result from the array and validate it
     $pdoFavorite = $results[0];
     $this->assertEquals($pdoFavorite->getTweetId(), $this->tweet->getTweetId());
     $this->assertEquals($pdoFavorite->getProfileId(), $this->profile->getProfileId());
     $this->assertEquals($pdoFavorite->getFavoriteDate(), $this->VALID_FAVORITEDATE);
 }
示例#2
0
    /*if(sizeof($result)>0){
    		echo json_encode($result);
    	}else{
    		echo json_encode(array(array("id"=>"not_found")));
    	}*/
});
$app->get('/favorite', function () {
    $favoriteDAO = new Favorite();
    $result = $favoriteDAO->get();
    echo json_encode($result);
});
$app->post('/favorite', function () {
    $request = \Slim\Slim::getInstance()->request();
    $favorite = json_decode($request->getBody());
    $favoriteDAO = new Favorite();
    $favoriteDAO->insert($favorite);
    echo '{"result":"ok"}';
});
$app->put('/favorite', function () {
    $request = \Slim\Slim::getInstance()->request();
    $favorite = json_decode($request->getBody());
    $favoriteDAO = new Favorite();
    $favoriteDAO->update($favorite);
    echo '{"result":"ok"}';
});
$app->delete('/favorite', function () {
    $request = \Slim\Slim::getInstance()->request();
    $favorite = json_decode($request->getBody());
    $favoriteDAO = new Favorite();
    $favoriteDAO->delete($favorite);
    echo '{"result":"ok"}';