From 772d8c4b93adc36baefda93ec37007e4a85321de Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Oct 2015 22:25:23 +0200 Subject: Add test on RegistrationConfirmedListener And PLEASE @nicosomb, NEVER EVER inject the whole container inside a service. --- .../RegistrationConfirmedListenerTest.php | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php (limited to 'src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php new file mode 100644 index 00000000..137c097c --- /dev/null +++ b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php @@ -0,0 +1,92 @@ +em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->listener = new RegistrationConfirmedListener( + $this->em, + 'baggy', + 20, + 50, + 'fr' + ); + + $this->dispatcher = new EventDispatcher(); + $this->dispatcher->addSubscriber($this->listener); + + $this->request = Request::create('/'); + $this->response = Response::create(); + } + + public function testWithInvalidUser() + { + $user = new User(); + $user->setEnabled(false); + + $event = new FilterUserResponseEvent( + $user, + $this->request, + $this->response + ); + + $this->em->expects($this->never())->method('persist'); + $this->em->expects($this->never())->method('flush'); + + $this->dispatcher->dispatch( + FOSUserEvents::REGISTRATION_CONFIRMED, + $event + ); + } + + public function testWithValidUser() + { + $user = new User(); + $user->setEnabled(true); + + $event = new FilterUserResponseEvent( + $user, + $this->request, + $this->response + ); + + $config = new Config($user); + $config->setTheme('baggy'); + $config->setItemsPerPage(20); + $config->setRssLimit(50); + $config->setLanguage('fr'); + + $this->em->expects($this->once()) + ->method('persist') + ->will($this->returnValue($config)); + $this->em->expects($this->once()) + ->method('flush'); + + $this->dispatcher->dispatch( + FOSUserEvents::REGISTRATION_CONFIRMED, + $event + ); + } +} -- cgit v1.2.3 From 0a878469d4038c36c84d1dd707265d880fa342e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Sat, 3 Oct 2015 06:29:55 +0200 Subject: move some files to UserBundle --- .../Tests/EventListener/RegistrationConfirmedListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php') diff --git a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php index 137c097c..df94fad2 100644 --- a/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php +++ b/src/Wallabag/CoreBundle/Tests/EventListener/RegistrationConfirmedListenerTest.php @@ -9,8 +9,8 @@ use Symfony\Component\HttpFoundation\Response; use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Event\FilterUserResponseEvent; use Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener; -use Wallabag\CoreBundle\Entity\User; use Wallabag\CoreBundle\Entity\Config; +use Wallabag\UserBundle\Entity\User; class RegistrationConfirmedListenerTest extends KernelTestCase { -- cgit v1.2.3