em = $this->getMockBuilder(EntityManager::class) ->disableOriginalConstructor() ->getMock(); $this->listener = new CreateConfigListener( $this->em, 20, 50, 'fr', 1, 1, 1, $session ); $this->dispatcher = new EventDispatcher(); $this->dispatcher->addSubscriber($this->listener); $this->request = Request::create('/'); $this->response = Response::create(); } public function testWithValidUser() { $user = new User(); $user->setEnabled(true); $event = new FilterUserResponseEvent( $user, $this->request, $this->response ); $config = new Config($user); $config->setItemsPerPage(20); $config->setFeedLimit(50); $config->setLanguage('fr'); $config->setReadingSpeed(200); $this->em->expects($this->once()) ->method('persist') ->willReturn($config); $this->em->expects($this->once()) ->method('flush'); $this->dispatcher->dispatch( FOSUserEvents::REGISTRATION_COMPLETED, $event ); } }