Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require __DIR__ . '/../src/Tweet.php';
- use PHPUnit\DbUnit\TestCaseTrait;
- use PHPUnit\Framework\TestCase;
- class TweetTest extends TestCase
- {
- use TestCaseTrait;
- public static function setUpBeforeClass()
- {
- $conn = new mysqli(
- 'localhost',
- $GLOBALS['DB_USER'],
- $GLOBALS['DB_PASSWORD'],
- $GLOBALS['DB_NAME']
- );
- Tweet::SetConnection($conn);
- }
- public function getConnection()
- {
- $pdo = new PDO($GLOBALS['DB_DSN'],
- $GLOBALS['DB_USER'],
- $GLOBALS['DB_PASSWORD']);
- return $this->createDefaultDBConnection($pdo, $GLOBALS['DB_NAME']);
- }
- public function getDataSet()
- {
- return $this->createMySQLXMLDataSet(__DIR__ . '/file.xml');
- }
- public function testCreateTweet()
- {
- $this->assertEquals(1, $this->getConnection()->getRowCount('Tweets'));
- Tweet::CreateTweet(1, 'Paweł', 'Some tweet');
- $this->assertEquals(2, $this->getConnection()->getRowCount('Tweets'));
- $new2 = Tweet::CreateTweet(9, 'Paweł', 'Some tweet');
- $this->assertNull($new2);
- }
- public function testDeleteTweet()
- {
- $this->assertEquals(1, $this->getConnection()->getRowCount('Tweets'));
- $this->assertFalse(
- Tweet::DeleteTweet(555) //this tweet not exist
- );
- $this->assertEquals(1, $this->getConnection()->getRowCount('Tweets'));
- Tweet::DeleteTweet(1);
- $this->assertEquals(0, $this->getConnection()->getRowCount('Tweets'));
- }
- public function testSelectTweets()
- {
- $tweets = Tweet::GetAllUserTweets(1, 'Zbyszek', 1);
- $this->assertInstanceOf(Tweet::class, $tweets[0]);
- $this->assertEquals('Zbyszek', $tweets[0]->getUserName());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement