Advertisement
sanjiisan

Untitled

Sep 7th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. <?php
  2.  
  3. require __DIR__ . '/../src/Tweet.php';
  4.  
  5. use PHPUnit\DbUnit\TestCaseTrait;
  6. use PHPUnit\Framework\TestCase;
  7.  
  8. class TweetTest extends TestCase
  9. {
  10. use TestCaseTrait;
  11.  
  12. public static function setUpBeforeClass()
  13. {
  14. $conn = new mysqli(
  15. 'localhost',
  16. $GLOBALS['DB_USER'],
  17. $GLOBALS['DB_PASSWORD'],
  18. $GLOBALS['DB_NAME']
  19. );
  20.  
  21. Tweet::SetConnection($conn);
  22. }
  23.  
  24. public function getConnection()
  25. {
  26. $pdo = new PDO($GLOBALS['DB_DSN'],
  27. $GLOBALS['DB_USER'],
  28. $GLOBALS['DB_PASSWORD']);
  29.  
  30. return $this->createDefaultDBConnection($pdo, $GLOBALS['DB_NAME']);
  31. }
  32.  
  33. public function getDataSet()
  34. {
  35. return $this->createMySQLXMLDataSet(__DIR__ . '/file.xml');
  36. }
  37.  
  38. public function testCreateTweet()
  39. {
  40. $this->assertEquals(1, $this->getConnection()->getRowCount('Tweets'));
  41.  
  42. Tweet::CreateTweet(1, 'Paweł', 'Some tweet');
  43.  
  44. $this->assertEquals(2, $this->getConnection()->getRowCount('Tweets'));
  45. $new2 = Tweet::CreateTweet(9, 'Paweł', 'Some tweet');
  46.  
  47. $this->assertNull($new2);
  48. }
  49.  
  50. public function testDeleteTweet()
  51. {
  52. $this->assertEquals(1, $this->getConnection()->getRowCount('Tweets'));
  53.  
  54. $this->assertFalse(
  55. Tweet::DeleteTweet(555) //this tweet not exist
  56. );
  57.  
  58. $this->assertEquals(1, $this->getConnection()->getRowCount('Tweets'));
  59.  
  60. Tweet::DeleteTweet(1);
  61. $this->assertEquals(0, $this->getConnection()->getRowCount('Tweets'));
  62. }
  63.  
  64. public function testSelectTweets()
  65. {
  66. $tweets = Tweet::GetAllUserTweets(1, 'Zbyszek', 1);
  67.  
  68. $this->assertInstanceOf(Tweet::class, $tweets[0]);
  69. $this->assertEquals('Zbyszek', $tweets[0]->getUserName());
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement