From 4a88a35b9d66b49b9666089f0348e4a1731684b8 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 9 Jan 2017 23:00:28 +0300 Subject: [PATCH] TestPostRepository added. --- .../Repository/TestPostRepository.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/Skobkin/PointToolsBundle/Repository/TestPostRepository.php diff --git a/tests/Skobkin/PointToolsBundle/Repository/TestPostRepository.php b/tests/Skobkin/PointToolsBundle/Repository/TestPostRepository.php new file mode 100644 index 0000000..735346c --- /dev/null +++ b/tests/Skobkin/PointToolsBundle/Repository/TestPostRepository.php @@ -0,0 +1,60 @@ +em = static::$kernel->getContainer()->get('doctrine')->getManager(); + $this->postRepo = $this->em->getRepository('SkobkinPointToolsBundle:Blogs\Post'); + } + + public function testFindOneById() + { + /** @var Post $post */ + $post = $this->postRepo->findOneBy(['id' => 'shortpost']); + + $this->assertNotNull($post, 'Post #shortpost not found'); + $this->assertEquals('shortpost', $post->getId(), 'Post id is not #shortpost'); + $this->assertEquals(99999, $post->getAuthor()->getId(), 'Post author id is not 99999'); + $this->assertEquals('Test post with many comments', $post->getText(), 'Invalid post text'); + $this->assertFalse($post->getPrivate(), 'Post is private'); + } + + public function testFindAll() + { + /** @var Post[] $posts */ + $posts = $this->postRepo->findAll(); + + $this->assertCount(2, $posts, 'Not exactly 2 posts found'); + } + + public function testGetPostWithComments() + { + /** @var Post $longPost */ + $longPost = $this->postRepo->getPostWithComments('longpost'); + + $this->assertNotNull($longPost, '#longpost not found'); + $this->assertEquals(99999, $longPost->getAuthor()->getId(), 'Post author ID is not 99999'); + $this->assertEquals('testuser', $longPost->getAuthor()->getLogin(), 'Post author login is not testuser'); + $this->assertCount(10000, $longPost->getComments(), 'Not exactly 10000 comments found'); + } +} \ No newline at end of file