protected function tearDown() { if ($this->prophet) { $this->prophet->checkPredictions(); } parent::tearDown(); }
function it_should_be_able_to_run_processes() { $prophet = new Prophet(); $processes = []; for ($i = 0; $i < 20; $i++) { $process = $prophet->prophesize(Process::class); $process->started = false; $process->terminated = false; $process->start()->will(function () use($process) { $process->started = true; })->shouldBeCalledTimes(1); $process->isTerminated()->will(function () use($process) { if (!$process->terminated) { $process->terminated = true; return false; } return true; })->shouldBeCalledTimes(2); // The number of times isStarted() is called starts at 3 // and increases by 2 after each chunk of five processes. $process->isStarted()->will(function () use($process) { return $process->started; })->shouldBeCalledTimes(floor($i / 5) * 2 + 3); $processes[] = $process->reveal(); } $this->run($processes); $prophet->checkPredictions(); }
protected function verifyMockObjects() { parent::verifyMockObjects(); if (null === $this->prophet) { return; } try { $this->prophet->checkPredictions(); } catch (\Exception $e) { /** Intentionally left empty */ } $this->countProphecyAssertions(); if (isset($e)) { throw $e; } }
/** * Calling no optional parameter * * @test * @see https://github.com/php-mock/php-mock-prophecy/issues/1 */ public function expectingWithoutOptionalParameter() { $prophet = new Prophet(); $prophecy = $prophet->prophesize(OptionalParameterHolder::class); $prophecy->call("arg1")->willReturn("mocked"); $mock = $prophecy->reveal(); $this->assertEquals("mocked", $mock->call("arg1")); $prophet->checkPredictions(); }
/** * {@inheritdoc} */ protected function verifyMockObjects() { parent::verifyMockObjects(); if ($this->prophet !== null) { try { $this->prophet->checkPredictions(); } catch (\Exception $e) { /** Intentionally left empty */ } foreach ($this->prophet->getProphecies() as $objectProphecy) { foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { foreach ($methodProphecies as $methodProphecy) { $this->addToAssertionCount(count($methodProphecy->getCheckedPredictions())); } } } if (isset($e)) { throw $e; } } }
public function testOnNewAccountCreated() { $userName = '******'; $userEmail = '*****@*****.**'; $messageBody = 'Body'; $messageSubject = 'Subject'; $template = $this->prophet->prophesize('Twig_Template'); $event = $this->prophet->prophesize('Smoovio\\Bundle\\CoreBundle\\Event\\NewAccountCreatedEvent'); $user = $this->prophet->prophesize('Smoovio\\Bundle\\CoreBundle\\Entity\\User'); $this->templating->loadTemplate($this->templateName)->willReturn($template->reveal())->shouldBeCalled(); $template->renderBlock('subject', [])->willReturn('Subject'); $event->getUser()->willReturn($user); $user->getUsername()->willReturn($userName); $user->getEmail()->willReturn($userEmail); $template->renderBlock('body', ['username' => $userName])->willReturn($messageBody)->shouldBeCalled(); $this->mailer->send(Argument::that(function (\Swift_Message $message) use($userEmail, $messageBody, $messageSubject) { $this->assertSame($this->sender, $message->getSender()); $this->assertSame($userEmail, $message->getTo()); $this->assertSame($messageSubject, $message->getSubject()); $this->assertSame($messageBody, $message->getBody()); })); $this->listener->onNewAccountCreated($event->reveal()); $this->prophet->checkPredictions(); }
public function testManagerCreatesUserSuccessfulWithProphecy() { $prophet = new Prophet(); $manager = $prophet->prophesize('Doctrine\\Common\\Persistence\\ObjectManager'); $encoderFactory = $prophet->prophesize('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface'); $encoder = $prophet->prophesize('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface'); $dispatcher = $prophet->prophesize('Symfony\\Component\\Eventdispatcher\\EventDispatcherInterface'); $user = $prophet->prophesize('Smoovio\\Bundle\\CoreBundle\\Entity\\User'); $encoderFactory->getEncoder($user->reveal())->willReturn($encoder)->shouldBeCalled(); $user->encodePassword($encoder->reveal())->shouldBeCalled(); $manager->persist($user)->shouldBeCalled(); $manager->flush()->shouldBeCalled(); $dispatcher->dispatch(CoreEvents::NEW_ACCOUNT_CREATED, Argument::that(function ($event) use($user) { return $event instanceof NewAccountCreatedEvent && $event->getUser() === $user; })); $userManager = new UserManager($manager->reveal(), $encoderFactory->reveal(), $dispatcher->reveal()); $userManager->createUser($user->reveal()); $prophet->checkPredictions(); }
function it_should_return_messages_to_given_recipient(ConnectionInterface $connection, ArrayToMessageTransformer $messageTransformer) { $rawMessages = array(array('id' => 4, 'recipients' => array('*****@*****.**')), array('id' => 2, 'recipients' => array('*****@*****.**', '*****@*****.**')), array('id' => 1, 'recipients' => array('*****@*****.**'))); $prophet = new Prophet(); $mockMessages = array($prophet->prophesize('Kibao\\MailCatcher\\Message\\MessageInterface'), $prophet->prophesize('Kibao\\MailCatcher\\Message\\MessageInterface'), $prophet->prophesize('Kibao\\MailCatcher\\Message\\MessageInterface')); for ($i = 0; $i < 3; $i++) { $rawMessage = $rawMessages[$i]; $recipients = array(); foreach ($rawMessage['recipients'] as $email) { $recipient = $prophet->prophesize('Kibao\\MailCatcher\\Address\\AddressInterface'); $recipient->getEmail()->willReturn($email); $recipients[] = $recipient; } $mockMessages[$i]->getRecipients()->willReturn($recipients); $messageTransformer->transform($rawMessage)->willReturn($mockMessages[$i]); $connection->getMessage($rawMessage['id'])->willReturn($rawMessage); } $connection->getMessages()->willReturn($rawMessages); $this->getMessagesTo('*****@*****.**')->shouldReturn(array($mockMessages[0], $mockMessages[1])); $prophet->checkPredictions(); }
/** * Verifies the mock object expectations. * * @since Method available since Release 3.5.0 */ protected function verifyMockObjects() { foreach ($this->mockObjects as $mockObject) { if ($mockObject->__phpunit_hasMatchers()) { $this->numAssertions++; } $mockObject->__phpunit_verify(); } if ($this->prophet !== null) { try { $this->prophet->checkPredictions(); } catch (Exception $e) { /** Intentionally left empty */ } foreach ($this->prophet->getProphecies() as $objectProphecy) { foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { foreach ($methodProphecies as $methodProphecy) { $this->numAssertions += count($methodProphecy->getCheckedPredictions()); } } } if (isset($e)) { throw $e; } } }
public function tearDown() { $this->prophet->checkPredictions(); }
/** * @param ExampleNode $example * @param SpecificationInterface $context * @param MatcherManager $matchers * @param CollaboratorManager $collaborators */ public function teardown(ExampleNode $example, SpecificationInterface $context, MatcherManager $matchers, CollaboratorManager $collaborators) { $this->prophet->checkPredictions(); }
public function letgo() { $this->prophet->checkPredictions(); }
protected function tearDown() { $prophet = new Prophet(); $prophet->checkPredictions(); }
/** * {@inheridoc}. */ protected function tearDown() { $this->prophet->checkPredictions(); }
protected function assertPostConditions() { if ($this->prophet) { $this->prophet->checkPredictions(); } }
/** * {@inheritdoc} */ public function afterTestMethod($testMethod) { $this->prophet->checkPredictions(); }
/** * Verifies the mock object expectations. * * @since Method available since Release 3.5.0 */ protected function verifyMockObjects() { foreach ($this->mockObjects as $mockObject) { if ($mockObject->__phpunit_hasMatchers()) { $this->numAssertions++; } $mockObject->__phpunit_verify(); } if ($this->prophet !== null) { foreach ($this->prophet->getProphecies() as $objectProphecy) { foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { foreach ($methodProphecies as $methodProphecy) { if ($methodProphecy->getPrediction() !== null) { $this->numAssertions++; } } } } $this->prophet->checkPredictions(); } }
protected function tearDown() { $this->prophet->checkPredictions(); GeneralUtility::resetSingletonInstances($this->singletonInstances); parent::tearDown(); }