Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require '../../vendor/autoload.php';
- require '../Comment.php';
- class CommentTest extends PHPUnit_Extensions_Database_TestCase
- {
- private $conn;
- protected function getConnection()
- {
- $conn = new PDO("mysql:host=mysql-461469.vipserv.org;dbname=daf_cdlab", "daf_cdlab", "cdlab" );
- return new PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection($conn, "daf_cdlab");
- }
- /**
- *
- */
- protected function setUp()
- {
- parent::setUp();
- $configDB = array(
- 'servername' => "mysql-461469.vipserv.org",
- 'username' => "daf_cdlab",
- 'password' => "cdlab",
- 'baseName' => "daf_cdlab"
- );
- $this->conn = new mysqli($configDB['servername'], $configDB['username'], $configDB['password'], $configDB['baseName']);
- Comment::SetConnection($this->conn);
- }
- protected function getDataSet()
- {
- $csv_data_set = new PHPUnit_Extensions_Database_DataSet_CsvDataSet();
- $csv_data_set->addTable('Users', 'fixtures/users.csv');
- $csv_data_set->addTable('Tweets', 'fixtures/news.csv');
- $csv_data_set->addTable('Messages', 'fixtures/messages.csv');
- $csv_data_set->addTable('Comments', 'fixtures/coments.csv');
- return $csv_data_set;
- }
- public function test_createComment_should_create_comment_in_db(){
- //when
- Comment::CreateComment(1,"Tester",2,"Some comment");
- //then
- $this->assertEquals(4, $this->getConnection()->getRowCount('Comments'));
- $res = $this->conn->query("Select * from Comments where id = 4")->fetch_assoc();
- $this->assertEquals("Some comment",$res['comment']);
- $this->assertEquals(1,$res['user_id']);
- $this->assertEquals(2,$res['tweet_id']);
- }
- public function test_removeComment_should_remove_comment_from_db(){
- //when
- Comment::DeleteComment(3);
- //then
- $this->assertEquals(2, $this->getConnection()->getRowCount('Comments'));
- $this->assertNull($this->conn->query("Select * from Comments where id = 3")->fetch_assoc());
- }
- public function test_getAllTweetComments_should_return_all_tweets(){
- //when
- $comments = Comment::GetAllTweetComments(2);
- //then
- $this->assertCount(2, $comments);
- $this->assertEquals(1,$comments[0]->getId());
- $this->assertEquals("something",$comments[0]->getCommentText());
- $this->assertEquals(2,$comments[1]->getId());
- $this->assertEquals("anything",$comments[1]->getCommentText());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement