/** * Builds a fake object using Prophecy */ public function buildFakeObject() { if (!isset($this->prophecy)) { $this->initProphecy(); } return $this->prophecy->reveal(); }
public function testInvokesSignatureVerifier() { $expected = new GnupgVerificationResult(['fingerprint' => 'foobar', 'summary' => 'baz']); $this->verifier->verify('foo', 'bar')->willReturn($expected); $service = new SignatureService($this->verifier->reveal()); $this->assertEquals($expected, $service->verify('foo', 'bar')); }
/** * @test */ public function datesAreReadFromQuery() { $shortCode = 'abc123'; $this->visitsTracker->info($shortCode, new DateRange(null, new \DateTime('2016-01-01 00:00:00')))->willReturn([])->shouldBeCalledTimes(1); $response = $this->action->__invoke(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)->withQueryParams(['endDate' => '2016-01-01 00:00:00']), new Response()); $this->assertEquals(200, $response->getStatusCode()); }
/** * Create a new database connection mock object for every test. * * @return void */ protected function setUp() { parent::setUp(); $this->typoScriptFrontendController = $this->prophesize(TypoScriptFrontendController::class); $GLOBALS['TSFE'] = $this->typoScriptFrontendController->reveal(); $this->subject = GeneralUtility::makeInstance(QueryContext::class); }
/** * @test */ public function tagsListIsReturnedIfCorrectShortCodeIsProvided() { $shortCode = 'abc123'; $this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl())->shouldBeCalledTimes(1); $response = $this->action->__invoke(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')->withParsedBody(['tags' => []]), new Response()); $this->assertEquals(200, $response->getStatusCode()); }
/** * @test */ public function invalidApiKeyReturnsErrorResponse() { $this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->setEnabled(false))->shouldBeCalledTimes(1); $request = ServerRequestFactory::fromGlobals()->withParsedBody(['apiKey' => 'foo']); $response = $this->action->__invoke($request, new Response()); $this->assertEquals(401, $response->getStatusCode()); }
public function it_should_return_406_response_if_no_best_format_found() { $this->formatNegotiator->getBestFormat(Argument::cetera())->willReturn(null); $this->route->getOption(Argument::any())->shouldBeCalled(); $request = Request::create('/?format=json'); $this->__invoke($request)->shouldReturn406Response(); }
/** * @test * @return void */ public function updateWizardDoesRunIfCssStyledContentIsNotInstalledAndExistingFlexFormContent() { $this->packageManagerProphecy->isPackageActive('css_styled_content')->willReturn(false); $this->dbProphecy->exec_SELECTcountRows(Argument::cetera())->willReturn(1); $description = ''; $this->assertTrue($this->updateWizard->checkForUpdate($description)); }
/** * */ public function testWrites() { $this->formatter->format(Argument::any())->shouldBeCalledTimes(1); $this->writer->write(Argument::any(), Argument::any())->shouldBeCalledTimes(1); $this->dumper->setEnabled(true); $this->dumper->dump('id', ['test' => 1]); }
/** * @expectedException \Linio\DynamicFormBundle\Exception\FormlyMapperException */ public function testIsThrowingNonExistentFormException() { $formName = 'foo'; $this->formFactoryMock->getConfiguration($formName)->willThrow('Linio\\DynamicFormBundle\\Exception\\NonExistentFormException'); $this->formlyMapper->setFormFactory($this->formFactoryMock->reveal()); $this->formlyMapper->map($formName); }
/** * @test * @return void */ public function updateWizardDoesNotRunIfCssStyledContentIsInstalled() { $this->packageManagerProphecy->isPackageActive('fluid_styled_content')->willReturn(true); $this->packageManagerProphecy->isPackageActive('css_styled_content')->willReturn(true); $description = ''; $this->assertFalse($this->updateWizard->checkForUpdate($description)); }
/** * @test */ public function it_adds_entries_if_there_are_present_in_xml() { $record = $this->prophesize(DTO\Record::class); $this->mockedEntryDecoder->addTransactionDetails(Argument::type(DTO\Entry::class), Argument::type('\\SimpleXMLElement'))->shouldBeCalled(); $record->addEntry(Argument::type(DTO\Entry::class))->shouldBeCalled(); $this->decoder->addEntries($record->reveal(), $this->getXmlRecord()); }
public function it_should_set_route_option_if_controller_found() { $request = Request::create('/'); $request->attributes->set('_controller', 'spec\\SDispatcher\\Middleware\\RouteOptionInspectorSpec'); $this->route->addOptions(Argument::any())->shouldBeCalled(); $this->__invoke($request); }
/** * @test */ public function translatePluralFallbacksToTranslator() { $this->translator->translatePlural('foo', 'bar', 'baz', 'default', null)->shouldBeCalledTimes(1); $this->extension->translatePlural('foo', 'bar', 'baz'); $this->translator->translatePlural('foo', 'bar', 'baz', 'another', 'en')->shouldBeCalledTimes(1); $this->extension->translatePlural('foo', 'bar', 'baz', 'another', 'en'); }
/** * @test */ public function exceptionWhileParsingLongUrlOutputsError() { $this->urlShortener->urlToShortCode(Argument::cetera())->willThrow(new InvalidUrlException())->shouldBeCalledTimes(1); $this->commandTester->execute(['command' => 'shortcode:generate', 'longUrl' => 'http://domain.com/invalid']); $output = $this->commandTester->getDisplay(); $this->assertTrue(strpos($output, 'Provided URL "http://domain.com/invalid" is invalid. Try with a different one.') === 0); }
/** * @test */ public function getUnlocatedVisitsFallbacksToRepository() { $repo = $this->prophesize(VisitRepository::class); $repo->findUnlocatedVisits()->shouldBeCalledTimes(1); $this->em->getRepository(Visit::class)->willReturn($repo->reveal())->shouldBeCalledTimes(1); $this->visitService->getUnlocatedVisits(); }
/** * Tests that there were no calls made. * * @param Call[] $calls * @param ObjectProphecy $object * @param MethodProphecy $method * * @throws \Prophecy\Exception\Prediction\UnexpectedCallsException */ public function check(array $calls, ObjectProphecy $object, MethodProphecy $method) { if (!count($calls)) { return; } throw new UnexpectedCallsException(sprintf("No calls expected that match:\n" . " %s->%s(%s)\n" . "but %d were made:\n%s", get_class($object->reveal()), $method->getMethodName(), $method->getArgumentsWildcard(), count($calls), $this->util->stringifyCalls($calls)), $method, $calls); }
public function testShouldDispatchEvents() { $notification = Email::create(); $notifyArg = Argument::allOf(Argument::type(Email::class), Argument::that(function ($arg) use($notification) { return $arg !== $notification; })); $handler = $this->prophesize(NotificationHandlerInterface::class); $handler->getName()->willReturn('default'); $handler->supports(Argument::any())->willReturn(true); $handler->notify($notifyArg)->willReturn(); $handler2 = $this->prophesize(NotificationHandlerInterface::class); $handler2->getName()->willReturn('default'); $handler2->supports(Argument::any())->willReturn(true); $handler2->notify($notifyArg)->willReturn(); $this->dispatcher->dispatch('notifire.pre_notify', Argument::type(PreNotifyEvent::class))->shouldBeCalled(); $this->dispatcher->dispatch('notifire.notify', Argument::that(function ($arg) use($notification) { if (!$arg instanceof NotifyEvent) { return false; } $not = $arg->getNotification(); return $not !== $notification; }))->shouldBeCalledTimes(2); $this->dispatcher->dispatch('notifire.post_notify', Argument::type(PostNotifyEvent::class))->shouldBeCalled(); $this->manager->addHandler($handler->reveal()); $this->manager->addHandler($handler2->reveal()); $this->manager->notify($notification); }
/** * @test */ public function anExceptionsReturnsErrorResponse() { $page = 3; $this->service->listShortUrls($page, null, [], null)->willThrow(\Exception::class)->shouldBeCalledTimes(1); $response = $this->action->__invoke(ServerRequestFactory::fromGlobals()->withQueryParams(['page' => $page]), new Response()); $this->assertEquals(500, $response->getStatusCode()); }
public function testGetTemplateFilename() { $config = new SkelCommandConfig($this->cliOptionsProphecy->reveal(), '/tmp/'); $expected = realpath(__DIR__ . '/../../../../conf/phive.skeleton.xml'); $actual = realpath($config->getTemplateFilename()); $this->assertEquals($expected, $actual); }
/** * @param $type */ private function createPropheciesForTaskRunnerRun($type) { $prophet = $this; $queueRunMethodProphecy = $this->queueProphecy->run($type, Argument::type('callable'))->will(function ($parameters) use($prophet) { $inputMessage = new InputMessage('input' . mt_rand(0, 65535)); $taskClass = 'Task' . mt_rand(0, 65535); $taskInput = new TaskInput([mt_rand(0, 65535)]); $prophet->taskInputMessageTransformerProphecy->getTaskClassFromMessage($inputMessage)->willReturn($taskClass); $prophet->taskInputMessageTransformerProphecy->getTaskInputFromMessage($inputMessage)->willReturn($taskInput); $prophet->taskFactoryProphecy->createTask($taskClass)->will(function () use($taskInput, &$outputMessage, $prophet) { $taskProphecy = $prophet->prophesize(Task::class); $taskRunMethodProphecy = $taskProphecy->run($taskInput)->will(function () use(&$outputMessage, $prophet) { $result = mt_rand(0, 65535); $outputMessage = new OutputMessage('output' . mt_rand(0, 65535)); $prophet->taskResultMessageTransformerProphecy->getOutputMessageFromResult(TaskResult::fromReturn($result))->willReturn($outputMessage); return $result; }); $taskRunMethodProphecy->shouldBeCalledTimes(1); return $taskProphecy->reveal(); }); $callable = $parameters[1]; $outputMessageResult = $callable($inputMessage); $prophet->assertEquals($outputMessage, $outputMessageResult); }); return $queueRunMethodProphecy; }
/** * @test */ public function addDataWithInlineTypeAndModifyRightsWillAddChildren() { $input = ['processedTca' => ['columns' => ['aField' => ['config' => ['type' => 'inline', 'foreign_table' => 'aForeignTableName']]]]]; $this->beUserProphecy->check('tables_modify', $input['processedTca']['columns']['aField']['config']['foreign_table'])->shouldBeCalled()->willReturn(true); $expected = $this->defaultConfig; $expected['processedTca']['columns']['aField']['children'] = []; $this->assertEquals($expected, $this->subject->addData($input)); }
public function testReturnsExpectedArrayOfUrls() { $alias = new PharAlias('phpunit', new AnyVersionConstraint()); $urls = [new Url('https://example.com/foo'), new Url('https://example.com/bar')]; $this->repositoryList->getRepositoryUrls($alias)->shouldBeCalled()->willReturn($urls); $resolver = new AliasResolver($this->repositoryList->reveal()); $this->assertEquals($urls, $resolver->resolve($alias)); }
public function testAjaxImageUploadForm() { $app = $this->prophesize('Zend\\Mvc\\Application'); $app->getMvcEvent()->willReturn($this->prophesize('Zend\\Mvc\\MvcEvent')); $this->locator->get('Application')->willReturn($app); $form = $this->ajaxImageUploadFormFactory->createService($this->controllerManager->reveal()); $this->assertInstanceOf('LearnZF2AjaxImageGallery\\Form\\AjaxImageUploadForm', $form); }
/** * @test */ public function addDataSetsPageLanguageOverlayRows() { $input = ['effectivePid' => '23']; $expected = $input; $expected['pageLanguageOverlayRows'] = [0 => ['uid' => '1', 'pid' => '42', 'sys_language_uid' => '2']]; $this->dbProphecy->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=23')->shouldBeCalled()->willReturn($expected['pageLanguageOverlayRows']); $this->assertSame($expected, $this->subject->addData($input)); }
/** * @test */ public function verboseOutputsResult() { $output = $this->prophesize(OutputInterface::class); $output->isVerbose()->willReturn(true); $output->writeln(Argument::cetera())->shouldBeCalledTimes(1); $this->blogFeedConsumer->refreshFeed()->shouldBeCalledTimes(1); $this->task->run($this->prophesize(InputInterface::class)->reveal(), $output->reveal()); }
public function testCreate() { $this->nameGenerator->generate()->willReturn('name'); $customer = $this->object->create(); $this->assertInstanceOf(Customer::class, $customer); $this->assertSame(null, $customer->getId()); $this->assertSame('name', $customer->getName()); }
protected function setupMockResponse(RequestInterface $request, $response) { // If a string is passed in, assume its a path to a HTTP representation if (is_string($response)) { $response = $this->getFixture($response); } $this->client->send(Argument::is($request))->shouldBeCalled()->willReturn($response); }
public static function configureBenchmarkMetadata(ObjectProphecy $benchmark, array $options = []) { $options = array_merge(['class' => 'Benchmark', 'beforeClassMethods' => [], 'afterClassMethods' => [], 'path' => null], $options); $benchmark->getClass()->willReturn($options['class']); $benchmark->getBeforeClassMethods()->willReturn($options['beforeClassMethods']); $benchmark->getAfterClassMethods()->willReturn($options['afterClassMethods']); $benchmark->getPath()->willReturn($options['path']); }
public function testFlushClearMessages() { $this->sqsClient->sendMessageBatch(Argument::any())->shouldBeCalledTimes(1); $queue = new MessageQueue('https://queue-url.aws.com', $this->sqsClient->reveal()); $queue->push(new Message('message-name', ['id' => 1])); $queue->flush(); $queue->flush(); }