Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. <?php
  2.  
  3. require '../../vendor/autoload.php';
  4. require '../Comment.php';
  5.  
  6. class CommentTest extends PHPUnit_Extensions_Database_TestCase
  7. {
  8.     private $conn;
  9.  
  10.     protected function getConnection()
  11.     {
  12.         $conn = new PDO("mysql:host=mysql-461469.vipserv.org;dbname=daf_cdlab", "daf_cdlab", "cdlab" );
  13.         return new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($conn, "daf_cdlab");
  14.     }
  15.  
  16.     /**
  17.      *
  18.      */
  19.     protected function setUp()
  20.     {
  21.         parent::setUp();
  22.  
  23.         $configDB = array(
  24.             'servername' => "mysql-461469.vipserv.org",
  25.             'username' => "daf_cdlab",
  26.             'password' => "cdlab",
  27.             'baseName' => "daf_cdlab"
  28.         );
  29.  
  30.         $this->conn = new mysqli($configDB['servername'], $configDB['username'], $configDB['password'], $configDB['baseName']);
  31.  
  32.         Comment::SetConnection($this->conn);
  33.  
  34.     }
  35.  
  36.  
  37.     protected function getDataSet()
  38.     {
  39.         $csv_data_set = new PHPUnit_Extensions_Database_DataSet_CsvDataSet();
  40.         $csv_data_set->addTable('Users', 'fixtures/users.csv');
  41.         $csv_data_set->addTable('Tweets', 'fixtures/news.csv');
  42.         $csv_data_set->addTable('Messages', 'fixtures/messages.csv');
  43.         $csv_data_set->addTable('Comments', 'fixtures/coments.csv');
  44.         return $csv_data_set;
  45.     }
  46.  
  47.     public function test_createComment_should_create_comment_in_db(){
  48.         //when
  49.         Comment::CreateComment(1,"Tester",2,"Some comment");
  50.  
  51.         //then
  52.         $this->assertEquals(4, $this->getConnection()->getRowCount('Comments'));
  53.         $res = $this->conn->query("Select * from Comments where id = 4")->fetch_assoc();
  54.         $this->assertEquals("Some comment",$res['comment']);
  55.         $this->assertEquals(1,$res['user_id']);
  56.         $this->assertEquals(2,$res['tweet_id']);
  57.     }
  58.  
  59.     public function test_removeComment_should_remove_comment_from_db(){
  60.         //when
  61.         Comment::DeleteComment(3);
  62.  
  63.         //then
  64.         $this->assertEquals(2, $this->getConnection()->getRowCount('Comments'));
  65.         $this->assertNull($this->conn->query("Select * from Comments where id = 3")->fetch_assoc());
  66.      }
  67.  
  68.     public function test_getAllTweetComments_should_return_all_tweets(){
  69.         //when
  70.         $comments = Comment::GetAllTweetComments(2);
  71.  
  72.         //then
  73.         $this->assertCount(2, $comments);
  74.         $this->assertEquals(1,$comments[0]->getId());
  75.         $this->assertEquals("something",$comments[0]->getCommentText());
  76.         $this->assertEquals(2,$comments[1]->getId());
  77.         $this->assertEquals("anything",$comments[1]->getCommentText());
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement