public function setUp() { $this->factory = new RendererFactory(); $this->container = $this->prophesize(ContainerInterface::class); $this->container->get('translator')->willReturn(Translator::factory([])); $this->container->get('config')->willReturn(['navigation' => [], 'recaptcha' => []]); $this->container->get(RouteAssembler::class)->willReturn($this->prophesize(RouteAssembler::class)->reveal()); }
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); }
public function testReturnIndexControllerFromFactory() { $formElementManager = $this->prophesize('Zend\\Form\\FormElementManager'); $ajaxImageUploadForm = $this->prophesize('LearnZF2AjaxImageGallery\\Form\\AjaxImageUploadForm'); $formElementManager->get('LearnZF2AjaxImageGallery\\Form\\AjaxImageUploadForm')->willReturn($ajaxImageUploadForm); $this->serviceLocator->get('FormElementManager')->willReturn($formElementManager); $controller = $this->indexControllerFactory->__invoke($this->indexControllerManager->reveal()); $this->assertInstanceOf('LearnZF2AjaxImageGallery\\Controller\\IndexController', $controller); }
/** * @expectedException \PharIo\Phive\DownloadFailedException */ public function testThrowsExceptionIfKeyWasNotFound() { $response = $this->prophesize(CurlResponse::class); $response->getHttpCode()->willReturn(404); $response->getErrorMessage()->willReturn('Not Found'); $this->curl->get(Argument::any(), Argument::any())->willReturn($response); $downloader = new GnupgKeyDownloader($this->curl->reveal(), [new Url('https://example.com')], $this->output->reveal()); $downloader->download('12345678'); }
/** * @covers ::normalize */ public function testNormalizeWithNoEntity() { $entity_reference = $this->prophesize(TypedDataInterface::class); $entity_reference->getValue()->willReturn(NULL)->shouldBeCalled(); $this->fieldItem->get('entity')->willReturn($entity_reference->reveal())->shouldBeCalled(); $normalized = $this->normalizer->normalize($this->fieldItem->reveal()); $expected = ['target_id' => ['value' => 'test']]; $this->assertSame($expected, $normalized); }
/** * @dataProvider isGrantedMaskComparisonProvider */ public function testIsGrantedMaskComparison($action, $requiredMask, $mask, $result) { $this->maskBuilder->resolveMask(Argument::exact($action))->willReturn($requiredMask); $this->maskBuilder->get()->willReturn($mask); if ($result) { $this->assertTrue($this->permission->isGranted($action)); } else { $this->assertfalse($this->permission->isGranted($action)); } }
public function let() { $this->prophet = new Prophet(); $this->routes = $this->prophet->prophesize('Symfony\\Component\\Routing\\RouteCollection'); $this->formatNegotiator = $this->prophet->prophesize('FOS\\Rest\\Util\\FormatNegotiator'); $this->route = $this->prophet->prophesize('Symfony\\Component\\Routing\\Route'); $this->route->getOption(RouteOptions::REST)->willReturn(true); $this->routes->get(Argument::any())->willReturn($this->route->reveal()); $this->beConstructedWith($this->routes->reveal(), $this->formatNegotiator->reveal()); }
public function let() { $this->prophet = new Prophet(); $this->route = $this->prophet->prophesize('Symfony\\Component\\Routing\\Route'); $this->routes = $this->prophet->prophesize('Symfony\\Component\\Routing\\RouteCollection'); $this->event = $this->prophet->prophesize('Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent'); $this->route->getOption(RouteOptions::REST)->willReturn(true); $this->routes->get(Argument::any())->willReturn($this->route->reveal()); $this->beConstructedWith($this->routes->reveal()); }
public function let() { $this->prophet = new Prophet(); $this->route = $this->prophet->prophesize('Symfony\\Component\\Routing\\Route'); $this->routes = $this->prophet->prophesize('Symfony\\Component\\Routing\\RouteCollection'); $this->decoderProvider = $this->prophet->prophesize('SDispatcher\\Common\\FOSDecoderProvider'); $this->route->getOption(RouteOptions::REST)->willReturn(true); $this->routes->get(Argument::any())->willReturn($this->route->reveal()); $this->beConstructedWith($this->routes->reveal(), $this->decoderProvider->reveal()); }
public function let() { $this->prophet = new Prophet(); $this->route = $this->prophet->prophesize('Symfony\\Component\\Routing\\Route'); $this->routes = $this->prophet->prophesize('Symfony\\Component\\Routing\\RouteCollection'); $this->response = $this->prophet->prophesize('SDispatcher\\DataResponse'); $this->encoder = $this->prophet->prophesize('Symfony\\Component\\Serializer\\Encoder\\EncoderInterface'); $this->route->getOption(RouteOptions::REST)->willReturn(true); $this->routes->get(Argument::any())->willReturn($this->route->reveal()); $this->beConstructedWith($this->routes->reveal(), $this->encoder->reveal()); }
public function testEnumLabel() { $enum = $this->prophesize('EnumBundle\\Enum\\EnumInterface'); $enum->getChoices()->willReturn(['foo' => 'FOO', 'bar' => 'BAR']); $this->registry->get('test')->willReturn($enum->reveal()); $twig = $this->createEnvironment(); $this->assertSame('FOO', $twig->createTemplate("{{ 'foo'|enum_label('test') }}")->render([])); $this->assertSame('BAR', $twig->createTemplate("{{ enum_label('bar', 'test') }}")->render([])); $this->assertSame('not_exist', $twig->createTemplate("{{ 'not_exist'|enum_label('test') }}")->render([])); $this->assertSame('not_exist', $twig->createTemplate("{{ enum_label('not_exist', 'test') }}")->render([])); }
/** * @expectedException \PSU\Exception\HttpClientException */ public function testGetJsonResponseFailure() { // test values $url = 'http://foo.com'; //mock methods $this->responseInterface->getStatusCode()->willReturn(500)->shouldBeCalledTimes(1); $this->clientInterface->get(Argument::exact($url))->willReturn($this->responseInterface->reveal())->shouldBeCalledTimes(1); // init object $guzzlAdapter = new GuzzlApapter($this->clientInterface->reveal()); // test $this->assertNull($guzzlAdapter->getJsonResponse($url)); }
public function testWithConfig() { $paths = ['ns1' => [__DIR__ . '/partials'], 'ns2' => [__DIR__ . '/templates']]; $config = ['extension' => 'handlebars', 'separator' => '.', 'paths' => $paths]; $factory = new ResolverFactory(); $this->container->get(HandlebarsRendererFactory::CONFIG_KEY)->willReturn($config); /* @var AggregateResolver $resolver */ $resolver = $factory($this->container->reveal()); /* @var FilesystemResolver $filesystemResolver */ $filesystemResolver = $resolver->fetchByType(FilesystemResolver::class); $this->assertEquals('handlebars', $filesystemResolver->getExtension()); $this->assertEquals('.', $filesystemResolver->getSeparator()); $paths = $filesystemResolver->getPaths(); $this->assertArrayHasKey('ns1', $paths); $this->assertArrayHasKey('ns2', $paths); }
/** * Creates repository connector. * * @param string $username Username. * @param string $password Password. * @param string $last_revision_cache_duration Last revision cache duration. * * @return Connector */ private function _createRepositoryConnector($username, $password, $last_revision_cache_duration = '10 minutes') { $this->_configEditor->get('repository-connector.username')->willReturn($username)->shouldBeCalled(); $this->_configEditor->get('repository-connector.password')->willReturn($password)->shouldBeCalled(); $this->_configEditor->get('repository-connector.last-revision-cache-duration')->willReturn($last_revision_cache_duration)->shouldBeCalled(); return new Connector($this->_configEditor->reveal(), $this->_processFactory->reveal(), $this->_io->reveal(), $this->_cacheManager->reveal(), $this->_revisionListParser->reveal()); }
/** * @test */ public function processReturnsEmptyStringIfSpecifiedPostProcessorDoesNotImplementTheInterface() { $typoScript = array(10 => $this->getUniqueId('postprocess'), 20 => PostProcessorWithoutInterfaceFixture::class); $this->objectManagerProphecy->get(Argument::cetera())->will(function ($arguments) { return new $arguments[0]($arguments[1], $arguments[2]); }); $subject = $this->createSubject($typoScript); $this->assertEquals('', $subject->process()); }
function testMethodNotAllowedMatch() { $this->cache->get("router")->shouldBeCalled()->willReturn(TestResource::expectedTable()); $router = new Router($this->cache->reveal(), new UrlTools()); $resources = array(__NAMESPACE__ . "\\TestResource"); $match = $router->match($resources, "POST", "/this/is/static"); $this->assertEquals(Router::METHOD_NOT_ALLOWED, $match->status, "Match"); $this->assertEquals(array("GET"), $match->allowed, "Allowed"); }
/** * testGeocodingWillReturnAnArray */ public function testGeocodingWillReturnAnArray() { $responseMock = $this->prophesize(StreamInterface::class); $responseMock->getContents()->willReturn('[ { "foo": "bar" }, { "123": 456 } ]'); $this->httpAdapterMock->get(Argument::type('string'))->willReturn($responseMock->reveal()); $googleMapsGeoCoder = new GoogleMaps($this->httpAdapterMock->reveal(), false, 'xoxo'); $results = $googleMapsGeoCoder->geocode('Schützenstraße 8, 10117 Berlin, Deutschland'); $this->assertInternalType('array', $results); }
public function testPhpHelper() { $config = ['paths' => [__DIR__ . '/templates'], 'php-helpers' => [__DIR__ . '/php/helper.php']]; $this->container->get(HandlebarsRendererFactory::CONFIG_KEY)->willReturn($config); $factory = new HandlebarsRendererFactory(); $renderer = $factory($this->container->reveal()); $result = $renderer->render('with_helper'); $this->assertEquals("Helper: Hello World", $result); }
public function testIsGrantedCachedExistentPermission() { $expectedPermission = new Permission($this->aliceRequester, $this->fooResource, new BasicMaskBuilder(1)); $expectedPermission->setPersistent(true); $this->permissionBuffer->get(Argument::exact($this->aliceRequester), Argument::exact($this->fooResource))->willReturn($expectedPermission)->shouldBeCalledTimes(1); $this->databaseProvider->insertPermission()->shouldNotBeCalled(); $this->databaseProvider->updatePermission()->shouldNotBeCalled(); $this->databaseProvider->deletePermission()->shouldNotBeCalled(); $this->assertTrue($this->acl->isGranted($this->aliceRequester, $this->fooResource, 'view')); }
/** * Helper function for the bound property * * @param $formObject */ protected function stubVariableContainer($formObject) { $this->viewHelperVariableContainer->exists(Argument::cetera())->willReturn(true); $this->viewHelperVariableContainer->get(Argument::any(), 'formObjectName')->willReturn('objectName'); $this->viewHelperVariableContainer->get(Argument::any(), 'fieldNamePrefix')->willReturn('fieldPrefix'); $this->viewHelperVariableContainer->get(Argument::any(), 'formFieldNames')->willReturn([]); $this->viewHelperVariableContainer->get(Argument::any(), 'formObject')->willReturn($formObject); $this->viewHelperVariableContainer->get(Argument::any(), 'renderedHiddenFields')->willReturn([]); $this->viewHelperVariableContainer->addOrUpdate(Argument::cetera())->willReturn(null); }
public function testChoose() { $question_helper = $this->prophesize('Symfony\\Component\\Console\\Helper\\QuestionHelper'); $this->helperSet->get('question')->willReturn($question_helper)->shouldBeCalled(); $question_helper->ask($this->input->reveal(), $this->output->reveal(), Argument::that(function ($question) { // TODO: The proper error message isn't tested. return $question instanceof ChoiceQuestion && $question->getQuestion() === '<question>text</question> ' && $question->getChoices() === array('option_1', 'option_2') && $question->getDefault() === 'option_2'; }))->shouldBeCalled(); $this->io->choose('text', array('option_1', 'option_2'), 'option_2', 'error msg'); }
public function testSetWorkingCopySetting() { $this->configEditor->get('global-settings.sample_name', '')->willReturn('global_value'); $setting_name = 'path-settings[svn://localhost].sample_name'; $this->configEditor->get($setting_name)->willReturn('old_value'); $this->configEditor->set($setting_name, 'new_value')->will(function (array $args, $object) { $object->get($args[0])->willReturn($args[1]); }); $this->command->getConfigSettings()->willReturn(array(new StringConfigSetting('sample_name', '', AbstractConfigSetting::SCOPE_WORKING_COPY))); $this->workingCopyResolver->getWorkingCopyUrl('/path/to/working-copy')->willReturn('svn://localhost'); $this->commandConfig->setSettingValue('sample_name', $this->command->reveal(), '/path/to/working-copy', 'new_value'); $this->assertEquals('new_value', $this->commandConfig->getSettingValue('sample_name', $this->command->reveal(), '/path/to/working-copy')); }
public function testShouldCallMultipleByRedirect() { $this->curlProphecy = $this->prophesize('\\Curl\\Curl'); $this->curlProphecy->setOpt(Argument::type('integer'), Argument::any())->shouldBeCalled(); $this->curlProphecy->get(Argument::exact('http://some.dummy.url/foo'), Argument::type('array'))->will(function () { $this->http_status_code = 301; $this->response_headers = ['Location' => 'http://other.location/']; }); $this->curlProphecy->get('http://other.location/foo', [])->shouldBeCalled()->will(function () { $this->http_status_code = 200; $this->response_headers = null; }); $this->restClient = $this->getRestClient(); $this->restClient->send('foo', 'get'); }
public function setUp() { $this->factory = new RendererFactory(); $this->container = $this->prophesize(ContainerInterface::class); $this->container->get('translator')->willReturn(Translator::factory([])); $this->container->get('config')->willReturn(['navigation' => [], 'recaptcha' => []]); $this->container->get('Acelaya\\Website\\FeedCache')->willReturn(new ArrayCache()); $this->container->get(BlogOptions::class)->willReturn(new BlogOptions()); $this->container->get(RouteAssembler::class)->willReturn($this->prophesize(RouteAssembler::class)->reveal()); }
/** * @test * @expectedException \Shlinkio\Shlink\Common\Exception\WrongIpException */ public function guzzleExceptionThrowsShlinkException() { $this->client->get('http://freegeoip.net/json/1.2.3.4')->willThrow(new TransferException())->shouldBeCalledTimes(1); $this->ipResolver->resolveIpLocation('1.2.3.4'); }
/** * Creates repository connector. * * @param string $username Username. * @param string $password Password. * * @return Connector */ private function _createRepositoryConnector($username, $password) { $this->_configEditor->get('repository-connector.username')->willReturn($username)->shouldBeCalled(); $this->_configEditor->get('repository-connector.password')->willReturn($password)->shouldBeCalled(); return new Connector($this->_configEditor->reveal(), $this->_processFactory->reveal(), $this->_io->reveal(), $this->_cacheManager->reveal()); }
/** * @covers ::retrieveDependency * @covers ::__construct * * @expectedException \BartFeenstra\DependencyRetriever\Exception\UnknownDependencyException */ public function testRetrieveDependencyWithUnknownDependency() { $this->container->get('known_dependency')->willThrow(new ServiceNotFoundException('known_dependency')); $this->sut->retrieveDependency('known_dependency'); }
public static function containerHasService(ObjectProphecy $container, $service, $instance) { $container->has($service)->willReturn(true); $container->get($service)->willReturn($instance); }
/** * @dataProvider storageDataProvider */ public function testDefaultValueIsConvertedToScalar($default_value, $stored_value) { $this->configEditor->get(new ConfigStorageNameToken('name', AbstractConfigSetting::SCOPE_GLOBAL), $stored_value)->willReturn(null)->shouldBeCalled(); $config_setting = $this->createConfigSetting(AbstractConfigSetting::SCOPE_GLOBAL, $default_value); $config_setting->getValue(AbstractConfigSetting::SCOPE_GLOBAL); }
public function setUp() { $this->httpClient = $this->prophesize(ClientInterface::class); $this->httpClient->get(Argument::any())->willReturn(new Response(200, <<<EOF <feed xmlns="http://www.w3.org/2005/Atom"> <title> <![CDATA[ Alejandro Celaya | Blog ]]> </title> <link href="https://blog.alejandrocelaya.com/atom.xml" rel="self"/> <link href="https://blog.alejandrocelaya.com/"/> <updated>2016-08-16T20:17:20+02:00</updated> <id>https://blog.alejandrocelaya.com/</id> <generator uri="http://sculpin.io/">Sculpin</generator> <entry> <title type="html"> <![CDATA[ Entry one ]]> </title> <link href="https://blog.alejandrocelaya.com/entry-one/"/> <updated>2016-08-16T00:00:00+02:00</updated> <id> https://blog.alejandrocelaya.com/entry-one/ </id> <content type="html"> <![CDATA[ Something ]]> </content> </entry> <entry> <title type="html"> <![CDATA[ Entry two ]]> </title> <link href="https://blog.alejandrocelaya.com/entry-two/"/> <updated>2016-08-16T00:00:00+02:00</updated> <id> https://blog.alejandrocelaya.com/entry-two/ </id> <content type="html"> <![CDATA[ Something ]]> </content> </entry> <entry> <title type="html"> <![CDATA[ Entry three ]]> </title> <link href="https://blog.alejandrocelaya.com/entry-three/"/> <updated>2016-08-16T00:00:00+02:00</updated> <id> https://blog.alejandrocelaya.com/entry-three/ </id> <content type="html"> <![CDATA[ Something ]]> </content> </entry> </feed> EOF ))->shouldBeCalledTimes(1); $this->feedCache = new ArrayCache(); $this->templatesCache = new ArrayCache(); $this->options = new BlogOptions(['url' => 'foo', 'feed' => 'bar', 'elements_to_display' => 2]); $this->service = new BlogFeedConsumer($this->httpClient->reveal(), $this->feedCache, $this->templatesCache, $this->options); }