當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Phake::when方法代碼示例

本文整理匯總了PHP中Phake::when方法的典型用法代碼示例。如果您正苦於以下問題:PHP Phake::when方法的具體用法?PHP Phake::when怎麽用?PHP Phake::when使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phake的用法示例。


在下文中一共展示了Phake::when方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: simpleStubWithPhake

 /** @test */
 public function simpleStubWithPhake()
 {
     $service = \Phake::mock('\\Acme\\ServiceInterface');
     \Phake::when($service)->readTemp()->thenReturn(10)->thenReturn(12)->thenReturn(14);
     $temperature = new Temperature($service);
     $this->assertEquals(12, $temperature->average());
 }
開發者ID:isidromerayo,項目名稱:simple_php_skeleton,代碼行數:8,代碼來源:TemperatureStubTest.php

示例2: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     \Phake::when($this->container)->get('modera_server_crud.persistence.default_handler')->thenReturn(new DummyDoctrinePersistenceHandler());
     \Phake::when($this->container)->get('doctrine.orm.entity_manager')->thenReturn(new DummyDoctrineEntityManager());
 }
開發者ID:modera,項目名稱:foundation,代碼行數:7,代碼來源:FilterTest.php

示例3: createIUT

 private function createIUT(array $cssAssets = array(), array $jsAssets = array())
 {
     $container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     \Phake::when($container)->get('modera_mjr_integration.css_resources_provider')->thenReturn($this->createMockProvider($cssAssets));
     \Phake::when($container)->get('modera_mjr_integration.js_resources_provider')->thenReturn($this->createMockProvider($jsAssets));
     return new AssetsProvider($container);
 }
開發者ID:modera,項目名稱:foundation,代碼行數:7,代碼來源:AssetsProviderTest.php

示例4: setUp

 protected function setUp()
 {
     $this->paginUrl = \Phake::mock('Behoimi\\Pager\\PagingUrl');
     \Phake::when($this->paginUrl)->getPrev()->thenReturn('hoge');
     \Phake::when($this->paginUrl)->getNext()->thenReturn('fuga');
     $this->target = new ListResult(true, array((object) array('id' => 1, 'name' => 'name')), $this->paginUrl, null);
 }
開發者ID:aainc,項目名稱:Behoimi,代碼行數:7,代碼來源:ListResultTest.php

示例5: testGetUrl

 public function testGetUrl()
 {
     $container = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     \Phake::when($container)->getParameter(ModeraFileRepositoryExtension::CONFIG_KEY . '.default_url_generator')->thenReturn('default_url_generator');
     \Phake::when($container)->getParameter(ModeraFileRepositoryExtension::CONFIG_KEY . '.url_generators')->thenReturn(array('foo' => 'foo_url_generator', 'bar' => 'bar_url_generator'));
     $defaultUrlGenerator = \Phake::mock('Modera\\FileRepositoryBundle\\StoredFile\\UrlGeneratorInterface');
     \Phake::when($container)->get('default_url_generator')->thenReturn($defaultUrlGenerator);
     $fooUrlGenerator = \Phake::mock('Modera\\FileRepositoryBundle\\StoredFile\\UrlGeneratorInterface');
     \Phake::when($container)->get('foo_url_generator')->thenReturn($fooUrlGenerator);
     \Phake::when($container)->get('bar_url_generator')->thenReturn('not_url_generator');
     $context = array();
     $splFile = new \SplFileInfo(__FILE__);
     $repository = \Phake::mock('Modera\\FileRepositoryBundle\\Entity\\Repository');
     \Phake::when($repository)->generateStorageKey($splFile, $context)->thenReturn('storage-key');
     $storedFile = new StoredFile($repository, $splFile, $context);
     $storedFile->init($container);
     \Phake::when($defaultUrlGenerator)->generateUrl($storedFile)->thenReturn('default_url');
     \Phake::when($fooUrlGenerator)->generateUrl($storedFile)->thenReturn('foo_url');
     \Phake::when($repository)->getConfig()->thenReturn(array('filesystem' => 'foo'));
     $this->assertEquals('foo_url', $storedFile->getUrl());
     \Phake::when($repository)->getConfig()->thenReturn(array('filesystem' => 'bar'));
     $this->assertEquals('default_url', $storedFile->getUrl());
     \Phake::when($repository)->getConfig()->thenReturn(array('filesystem' => 'baz'));
     $this->assertEquals('default_url', $storedFile->getUrl());
 }
開發者ID:modera,項目名稱:foundation,代碼行數:25,代碼來源:StoredFileTest.php

示例6: testEventWithoutStringShouldThrowInvalidArgumentExceptionError

 public function testEventWithoutStringShouldThrowInvalidArgumentExceptionError()
 {
     $this->setExpectedExceptionRegExp('InvalidArgumentException', '/^Invalid argument: the submitted variable must be a string when you enable the json_format option.$/');
     $json = ['invalid json'];
     \Phake::when($this->formEvent)->getData()->thenReturn($json);
     $this->jsonExtensionListener->onPreSubmit($this->formEvent);
 }
開發者ID:LinkValue,項目名稱:JsonFormExtension-dev,代碼行數:7,代碼來源:JsonExtensionListenerTest.php

示例7: should_convert_segment_to_string

 /** @test */
 public function should_convert_segment_to_string()
 {
     $segment = new Segment('XXX');
     $segment->var = 'value';
     $segmentMapping = new SegmentMapping('XXX');
     $segmentMapping->addDataElement(1, new DataElementMapping(2345, true, DataElementType::A, 'var'));
     $message = new Message();
     $message->setReferenceNumber(34834);
     $message->setIdentifier(["type" => 'TEST', "version" => 'S', "release" => '404', "controllingAgency" => 'PG']);
     $message->addSegment($segment);
     //        $messageMapping = new MessageMapping();
     //        $messageMapping->setDefaults(["0065" => 'TEST', "0052" => 'S', "0054" => '404', "0051" => 'PG']);
     //        $messageMapping->addSegment(new MessageSegmentMapping('UNH', 1, true));
     //        $messageMapping->addSegment(new MessageSegmentMapping('XXX', 99, true));
     //        $messageMapping->addSegment(new MessageSegmentMapping('UNT', 1, true));
     $interchange = new Interchange();
     $interchange->setSyntax(["name" => 'UNOC', "version" => 3]);
     $interchange->setSender(['id' => 'zenon']);
     $interchange->setRecipient(['id' => 'stefan']);
     $interchange->setTime(['date' => '20150101', 'time' => '1034']);
     $interchange->setControlReference('17');
     $interchange->setMessages([$message]);
     $mappingLoader = \Phake::mock(MappingLoader::class);
     \Phake::when($mappingLoader)->loadSegments(\Phake::anyParameters())->thenReturn(['XXX' => $segmentMapping]);
     $encoder = new Encoder(new AnnotationPrinter(new AnnotationReader()), new SegmentPrinter(), $mappingLoader);
     $result = $encoder->encode($interchange);
     $this->assertEquals("UNB+UNOC:3+zenon+stefan+20150101:1034+17'UNH+34834+TEST:S:404:PG'XXX+value'UNT+1+34834'UNZ+1+17'", $result);
 }
開發者ID:progrupa,項目名稱:edifact,代碼行數:29,代碼來源:EncoderTest.php

示例8: setUp

 public function setUp()
 {
     $this->mock = $this->getMock('Phake_IMock');
     $this->mockReader = Phake::mock('Phake_MockReader');
     Phake::when($this->mockReader)->getName($this->mock)->thenReturn('Phake_IMock');
     $this->call = new Phake_CallRecorder_Call($this->mock, 'someMethod', array('foo', 'bar'), $this->mockReader);
 }
開發者ID:ngyuki,項目名稱:phake,代碼行數:7,代碼來源:CallTest.php

示例9: parseNormal

 /**
  * @test
  */
 public function parseNormal()
 {
     \Phake::when($this->commentsParser)->parse(\Phake::anyParameters())->thenReturn(null);
     $stmts = (include __DIR__ . '/../fixtures/1/Model/Product.php.property_base.cache');
     $this->parser->parse($stmts, $this->property, $this->class);
     \Phake::verify($this->commentsParser)->parse(\Phake::anyParameters());
 }
開發者ID:domaincoder,項目名稱:code-metamodel-php,代碼行數:10,代碼來源:PropertyAnnotationsParserTest.php

示例10: setUp

 public function setUp()
 {
     $this->mockReader = Phake::mock('Phake_MockReader');
     $this->callRecorder = Phake::mock('Phake_CallRecorder_Recorder');
     Phake::when($this->mockReader)->getCallRecorder($this->anything())->thenReturn($this->callRecorder);
     $this->handler = new Phake_ClassGenerator_InvocationHandler_MagicCallRecorder($this->mockReader);
 }
開發者ID:ngyuki,項目名稱:phake,代碼行數:7,代碼來源:MagicCallRecorderTest.php

示例11: it_grants_access_from_token_roles

 /**
  * @test
  */
 public function it_grants_access_from_token_roles()
 {
     $user = \Phake::mock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
     \Phake::when($user)->getRoles()->thenReturn(array('ROLE_USER', 'ROLE_ADMIN'));
     $context = new MockTokenContext($user);
     $this->assertTrue($context->isGranted('ROLE_USER'));
 }
開發者ID:wakermahmud,項目名稱:QafooLabsNoFrameworkBundle,代碼行數:10,代碼來源:MockTokenContextTest.php

示例12: createRedisClient

 public function createRedisClient(array $parameters = array())
 {
     $mockedRedisClient = \Phake::mock('\\PSRedis\\Client');
     \Phake::when($mockedRedisClient)->isMaster()->thenReturn(false);
     \Phake::when($mockedRedisClient)->getMaster(\Phake::anyParameters())->thenReturn($mockedRedisClient);
     return $mockedRedisClient;
 }
開發者ID:hemingw,項目名稱:PSRedis,代碼行數:7,代碼來源:MockedPredisClientCreatorWithNoMasterAddress.php

示例13: parseMethodComment

 /**
  * @test
  */
 public function parseMethodComment()
 {
     \Phake::when($this->annotationsParser)->parse(\Phake::anyParameters())->thenReturn([]);
     $stmts = (include __DIR__ . '/../fixtures/1/Model/Product.php.method.cache');
     $method = $this->parser->parse($stmts, $this->class);
     $this->assertThat($method->comment, $this->equalTo('Sets updated datetimedetailed description here'));
 }
開發者ID:domaincoder,項目名稱:code-metamodel-php,代碼行數:10,代碼來源:MethodParserTest.php

示例14: callProtectedMusicAPI

 protected function callProtectedMusicAPI($call_fn, $expected_url_extension, $expected_params = [], $sample_response = null)
 {
     if ($sample_response === null) {
         $sample_response = ['foo' => 'bar'];
     }
     $generator = new Generator();
     // set up the mock to check headers generated
     $tokenly_api = Phake::partialMock('Tokenly\\APIClient\\TokenlyAPI', 'https://127.0.0.1/api/v1', $generator, 'MY_CLIENT_ID', 'MY_CLIENT_SECRET');
     $called_vars = [];
     Phake::when($tokenly_api)->callRequest(Phake::anyParameters())->thenReturnCallback(function ($url, $headers, $request_params, $method, $request_options) use($sample_response, &$called_vars) {
         $called_vars = [];
         $response = new Requests_Response();
         $response->body = json_encode($sample_response);
         $called_vars['headers'] = $headers;
         $called_vars['url'] = $url;
         $called_vars['params'] = $request_params;
         return $response;
     });
     $music_api = new MusicAPI($tokenly_api);
     // check API call
     $result = $call_fn($music_api);
     PHPUnit::assertEquals($sample_response, $result);
     // check called URL
     PHPUnit::assertEquals('https://127.0.0.1/api/v1/' . $expected_url_extension, $called_vars['url']);
     // check headers
     $headers_generated = $called_vars['headers'];
     PHPUnit::assertNotEmpty($headers_generated);
     $nonce = $headers_generated['X-TOKENLY-AUTH-NONCE'];
     PHPUnit::assertGreaterThanOrEqual(time(), $nonce);
     PHPUnit::assertEquals('MY_CLIENT_ID', $headers_generated['X-TOKENLY-AUTH-API-TOKEN']);
     $expected_signature = $this->expectedSignature($nonce, 'https://127.0.0.1/api/v1/' . $expected_url_extension, $expected_params);
     PHPUnit::assertEquals($expected_signature, $headers_generated['X-TOKENLY-AUTH-SIGNATURE']);
     // return the called vars
     return $called_vars;
 }
開發者ID:tokenly,項目名稱:music-api-client,代碼行數:35,代碼來源:MusicAPITest.php

示例15: testWork

 public function testWork()
 {
     \Phake::when($this->scraper)->scrape(\Phake::anyParameters())->thenReturn(array(new Entity(), new Entity()));
     $result = $this->target->work(null);
     \Phake::verify($this->scraper)->scrape($this->definition);
     $this->assertCount(2, $result);
 }
開發者ID:t-ishida,項目名稱:Moshas,代碼行數:7,代碼來源:StartTest.php


注:本文中的Phake::when方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。