Esempio n. 1
0
 public function setUp()
 {
     $this->requestStack = new RequestStack();
     $request = new Request();
     $this->requestStack->push($request);
     $this->session = new Session(new MockArraySessionStorage());
     $request->setSession($this->session);
     $this->dispatcher = new EventDispatcher();
     $translator = new Translator($this->getMock('\\Symfony\\Component\\DependencyInjection\\ContainerInterface'));
     $token = new TokenProvider($this->requestStack, $translator, 'test');
     $this->dispatcher->addSubscriber(new \Thelia\Action\Cart($this->requestStack, $token));
     $this->session->setSessionCart(null);
     $request->setSession($this->session);
     /** @var \Thelia\Action\Cart  cartAction */
     $this->cartAction = new \Thelia\Action\Cart($this->requestStack, new TokenProvider($this->requestStack, $translator, 'baba au rhum'));
     $this->dispatcherNull = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface', array(), array(), '', true, true, true, false);
     $this->dispatcher->expects($this->any())->method('dispatch')->will($this->returnCallback(function ($type, $event) {
         if ($type == TheliaEvents::CART_RESTORE_CURRENT) {
             $this->cartAction->restoreCurrentCart($event, null, $this->dispatcher);
         } elseif ($type == TheliaEvents::CART_CREATE_NEW) {
             $this->cartAction->createEmptyCart($event, null, $this->dispatcher);
         }
     }));
 }
Esempio n. 2
0
 public function testProcess()
 {
     $env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock();
     $formView = $this->getMockBuilder('Symfony\\Component\\Form\\FormView')->disableOriginalConstructor()->getMock();
     $this->eventDispatcher->expects($this->once())->method('dispatch')->with(Events::BEFORE_UPDATE_FORM_RENDER, $this->isInstanceOf('Oro\\Bundle\\UIBundle\\Event\\BeforeFormRenderEvent'));
     $formData = array("test");
     $this->assertEquals($formData, $this->extension->process($env, $formData, $formView));
 }
 public function testCanWithListener()
 {
     $this->dispatcher->expects($this->at(1))->method('dispatch')->with('finite.test_transition', $this->isInstanceOf('Finite\\Event\\TransitionEvent'));
     $this->dispatcher->expects($this->at(2))->method('dispatch')->with('finite.test_transition.t23', $this->callback(function ($event) {
         $event->reject();
         return $event instanceof \Finite\Event\TransitionEvent;
     }));
     $this->initialize();
     $this->assertFalse($this->object->can('t34'));
     $this->assertFalse($this->object->can('t23'));
 }
 public function testMatchedRequestDispatchesEvent()
 {
     $matchResult = new MatchResult(true, $event = new NotificationEvent('my-event'));
     /** @var RequestInterface $request */
     $request = self::createMock(RequestInterface::class);
     /** @var ResponseInterface $response */
     $response = self::createMock(ResponseInterface::class);
     $this->matcher->expects(self::any())->method('match')->willReturn($matchResult);
     $this->dispatcher->expects(self::once())->method('dispatch')->with($event->getName(), $event);
     $this->middleware->__invoke($request, $response);
 }
 public function testCloseJobDoesNotCreateMoreThanAllowedRetries()
 {
     $a = new Job('a');
     $a->setMaxRetries(2);
     $a->setState('running');
     $this->em->persist($a);
     $this->em->flush();
     $this->dispatcher->expects($this->at(0))->method('dispatch')->with('jms_job_queue.job_state_change', new StateChangeEvent($a, 'failed'));
     $this->dispatcher->expects($this->at(1))->method('dispatch')->with('jms_job_queue.job_state_change', new \PHPUnit_Framework_Constraint_Not($this->equalTo(new StateChangeEvent($a, 'failed'))));
     $this->dispatcher->expects($this->at(2))->method('dispatch')->with('jms_job_queue.job_state_change', new \PHPUnit_Framework_Constraint_Not($this->equalTo(new StateChangeEvent($a, 'failed'))));
     $this->assertCount(0, $a->getRetryJobs());
     $this->repo->closeJob($a, 'failed');
     $this->assertEquals('running', $a->getState());
     $this->assertCount(1, $a->getRetryJobs());
     $a->getRetryJobs()->first()->setState('running');
     $this->repo->closeJob($a->getRetryJobs()->first(), 'failed');
     $this->assertCount(2, $a->getRetryJobs());
     $this->assertEquals('failed', $a->getRetryJobs()->first()->getState());
     $this->assertEquals('running', $a->getState());
     $a->getRetryJobs()->last()->setState('running');
     $this->repo->closeJob($a->getRetryJobs()->last(), 'terminated');
     $this->assertCount(2, $a->getRetryJobs());
     $this->assertEquals('terminated', $a->getRetryJobs()->last()->getState());
     $this->assertEquals('terminated', $a->getState());
     $this->em->clear();
     $reloadedA = $this->em->find('JMSJobQueueBundle:Job', $a->getId());
     $this->assertCount(2, $reloadedA->getRetryJobs());
 }
Esempio n. 6
0
 /**
  * Test saving settings
  */
 public function testSave()
 {
     $settings = array('oro_user___level' => array('value' => 50));
     $removed = array('oro_user___greeting' => array('value' => 'new value'));
     $object = $this->getMock('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager', array('calculateChangeSet', 'reload', 'get'), array($this->ed, $this->om, new ConfigDefinitionImmutableBag($this->settings)));
     $changes = array($settings, $removed);
     $object->expects($this->once())->method('calculateChangeSet')->with($this->equalTo($settings))->will($this->returnValue($changes));
     $object->expects($this->once())->method('reload');
     $configMock = $this->getMock('Oro\\Bundle\\ConfigBundle\\Entity\\Config');
     $configMock->expects($this->once())->method('getOrCreateValue')->will($this->returnValue(new ConfigValue()));
     $configMock->expects($this->once())->method('getValues')->will($this->returnValue(new ArrayCollection()));
     $valueRepository = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigValueRepository')->disableOriginalConstructor()->getMock();
     $repository = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->once())->method('getByEntity')->with('app', 0)->will($this->returnValue($configMock));
     $this->om->expects($this->at(0))->method('getRepository')->will($this->returnValue($valueRepository));
     $this->om->expects($this->at(1))->method('getRepository')->will($this->returnValue($repository));
     $this->om->expects($this->once())->method('persist');
     $this->om->expects($this->once())->method('flush');
     $object->expects($this->exactly(3))->method('get');
     $this->ed->expects($this->once())->method('dispatch')->with($this->equalTo('oro_config.update_after'), $this->isInstanceOf('Oro\\Bundle\\ConfigBundle\\Event\\ConfigUpdateEvent'));
     $object->save($settings);
 }
 public function testShouldDispatchProcessEvent()
 {
     $this->dispatcherMock->expects($this->at(0))->method('dispatch')->with($this->equalTo(CommandEvents::RUN_TESTS_PROCESS), $this->isInstanceOf(RunTestsProcessEvent::class));
     $this->creator->createFromFiles($this->findDummyTests(), [], ['bar', 'foo']);
 }