Fixed tests broken by abstract test case rollback

This commit is contained in:
Marcin Kurczewski 2014-11-09 13:08:24 +01:00
parent 9ca712cc6d
commit 1edc1636a3
3 changed files with 27 additions and 9 deletions

View file

@ -77,19 +77,34 @@ final class CommentDaoTest extends AbstractDatabaseTestCase
$post = $postDao->findById($post->getId());
$this->assertNotNull($post);
$this->assertEquals(1, $post->getCommentCount());
return [$postDao, $commentDao, $post, $comment];
}
/**
* @depends testPostMetadataSyncInsert
*/
public function testPostMetadataSyncDelete($args)
public function testPostMetadataSyncDelete()
{
list ($postDao, $commentDao, $post, $comment) = $args;
$userDao = Injector::get(UserDao::class);
$postDao = Injector::get(PostDao::class);
$commentDao = Injector::get(CommentDao::class);
$user = self::getTestUser('olivia');
$userDao->save($user);
$post = self::getTestPost();
$postDao->save($post);
$this->assertEquals(0, $post->getCommentCount());
$this->assertNotNull($post->getId());
$comment = new Comment();
$comment->setUser($user);
$comment->setPost($post);
$comment->setCreationTime(date('c'));
$comment->setLastEditTime(date('c'));
$comment->setText('whatever');
$commentDao->save($comment);
$commentDao->deleteById($comment->getId());
$this->assertNotNull($post->getId());
$post = $postDao->findById($post->getId());
$this->assertNotNull($post);
$this->assertEquals(0, $post->getCommentCount());

View file

@ -38,6 +38,9 @@ final class TransactionManagerTest extends AbstractDatabaseTestCase
//ids that could be forged in transaction get left behind after rollback
$this->assertNotNull($testEntity->getId());
$this->databaseConnection->getPDO()->rollBack();
$this->databaseConnection->getPDO()->beginTransaction();
//but entities shouldn't be saved to database
$this->assertNull($testDao->findById($testEntity->getId()));
}

View file

@ -25,7 +25,7 @@ final class TagServiceTest extends AbstractDatabaseTestCase
$tagService = $this->getTagService();
$result = $tagService->createTags([$tag]);
$this->assertEquals(1, count($result));
$this->assertEquals(1, $result[0]->getId());
$this->assertNotNull($result[0]->getId());
$this->assertEquals('test', $result[0]->getName());
}
@ -64,7 +64,7 @@ final class TagServiceTest extends AbstractDatabaseTestCase
$result = $tagService->createTags([$tag1, $tag2]);
$this->assertEquals(2, count($result));
$this->assertEquals(1, $result[0]->getId());
$this->assertEquals(3, $result[1]->getId());
$this->assertNotNull($result[1]->getId());
$this->assertEquals('test1', $result[0]->getName());
$this->assertEquals('test3', $result[1]->getName());
}