/** * @test */ public function parseNormal() { \Phake::when($this->parser)->parse(\Phake::anyParameters())->thenReturn(null); $path = __DIR__ . '/../fixtures/1'; $this->projectParser->parse($path); \Phake::verify($this->parser, \Phake::times(3))->parse(\Phake::anyParameters()); }
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; }
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; }
/** * @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')); }
public function testConfigureCustomAggregateFactory() { $this->fixture->registerAggregateFactory($this->mockAggregateFactory); $this->fixture->registerAnnotatedCommandHandler(new MyCommandHandler($this->fixture->getRepository(), $this->fixture->getEventBus())); $this->fixture->given([new MyEvent("id1", 1)])->when(new TestCommand("id1")); \Phake::verify($this->mockAggregateFactory, \Phake::atLeast(1))->createAggregate(\Phake::equalTo("id1"), \Phake::anyParameters()); }
/** * @test */ public function parseClassComment() { \Phake::when($this->annotationsParser)->parse(\Phake::anyParameters())->thenReturn([]); $stmts = (include __DIR__ . '/../fixtures/1/Model/Product.php.class.cache'); $class = $this->parser->parse($stmts, '', ''); $this->assertThat($class->comment, $this->equalTo('商品エンティティ')); }
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); }
/** @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); }
/** * @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()); }
protected function setUp() { parent::setUp(); Phake::when($this->facade)->is_user_logged_in()->thenReturn(true); Phake::when($this->facade)->wp_get_current_user()->thenReturn($this->user); Phake::when($this->wpdb)->get_var(Phake::anyParameters())->thenReturn('true'); }
protected function setUp() { Phake::initAnnotations($this); Phake::when($this->wpdb)->get_var(Phake::anyParameters())->thenReturn('true'); $this->wpdb->usermeta = 'usermeta_table_name'; $this->user->ID = 'User ID'; $this->client = new LaunchKey_WP_SSO_Client($this->facade, $this->template, static::ENTITY_ID, $this->saml_response_service, $this->saml_request_service, $this->wpdb, static::LOGIN_URL, static::LOGOUT_URL, static::ERROR_URL, false); }
public function testExecuteNoResultNoParameter() { \Phake::when($this->target)->getAffectedRows()->thenReturn(0); \Phake::when($this->connection)->prepare('DROP TABLE')->thenReturn($this->statement); $this->target->executeNoResult('DROP TABLE'); \Phake::verify($this->statement, \Phake::never())->bind_param(\Phake::anyParameters()); \Phake::verify($this->statement)->close(); }
public function testReadOkNothing() { \Phake::when($this->connection)->prepare(\Phake::anyParameters())->thenReturn($this->statement); \Phake::when($this->statement)->fetch()->thenReturn(false); $this->assertSame('', $this->target->read('1234')); \Phake::verify($this->statement)->bind_param('s', '1234'); \Phake::verify($this->statement)->close(); }
protected function setUp() { Phake::initAnnotations($this); Phake::when($this->container)->generateId(Phake::anyParameters())->thenReturn(static::UNIQUE_ID); SAML2_Compat_ContainerSingleton::setContainer($this->container); $this->service = new LaunchKey_WP_SAML2_Request_Service(self::$key); $this->service->load_saml_request(self::$request_data); }
/** * Registers a factory which returns mocked consents */ protected function registerConsentFactory() { $this[self::CONSENT_FACTORY] = function (EngineBlock_Application_DiContainer $container) { $consentFactoryMock = Phake::mock('EngineBlock_Corto_Model_Consent_Factory'); Phake::when($consentFactoryMock)->create(Phake::anyParameters())->thenReturn(Phake::mock('EngineBlock_Corto_Model_Consent')); return $consentFactoryMock; }; }
public function testWork() { \Phake::when($this->scraper)->scrape(\Phake::anyParameters())->thenReturn(array(new Entity(), new Entity())); $result = $this->target->work(array($this->entity1, $this->entity2)); $this->assertCount(2, $result); $this->assertSame('url', $result[0]->getUrl()); $this->assertSame('url', $result[1]->getUrl()); }
protected function setUp() { Phake::initAnnotations($this); $this->template = new LaunchKey_WP_Template(__DIR__ . '/__fixtures', $this->facade, 'test-language-domain'); Phake::when($this->facade)->__(Phake::anyParameters())->thenReturnCallback(function ($method, $parameters) { return sprintf('Translated [%s]', $parameters[0]); }); }
public function test_non_login_with_loggedin_user_that_is_paired_and_was_authorized_by_launchkey_logs_out_user_when_authenticated_is_false() { Phake::when($this->facade)->wp_get_current_user(Phake::anyParameters())->thenReturn($this->user); $this->user->launchkey_username = '******'; $this->user->launchkey_authorized = 'false'; $this->client->authentication_controller(null, null, null); Phake::verify($this->facade)->wp_logout(); }
/** * @test */ public function it_fowards() { $request = new Request(); $this->container->set('request', $request); $kernel = $this->mockContainerService('http_kernel', 'Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $this->helper->forward('ctrl'); \Phake::verify($kernel)->handle(\Phake::anyParameters()); }
public function test_exceptions_log_when_debug() { $this->user->launchkey_auth = 'auth_request_id'; Phake::when($this->facade)->is_debug_log()->thenReturn(true); Phake::when($this->sdk_auth)->deOrbit(Phake::anyParameters())->thenThrow(new Exception('Expected Message')); $this->client->logout(); Phake::verify($this->facade)->error_log($this->stringContains('Expected Message')); }
public function testChainWithDifferentProceedCalls() { $interceptor1 = new Interceptor1(); $interceptor2 = new Interceptor2(); \Phake::when($this->mockCommandHandler)->handle(\Phake::anyParameters())->thenReturn('Result'); $testSubject = new DefaultInterceptorChain(GenericCommandMessage::asCommandMessage(new Payload("original")), $this->mockUnitOfWork, $this->mockCommandHandler, array($interceptor1, $interceptor2)); $actual = $testSubject->proceed(); $this->assertSame("Result", $actual); }
/** * Sets up test fixture */ public function setUp() { $this->client = new Phake_Client_Default(); $this->matcher1 = Phake::mock('Phake_Matchers_IArgumentMatcher'); $this->obj = new Phake_CallRecorder_Recorder(); $this->mockReader = Phake::mock('Phake_MockReader'); Phake::when($this->mockReader)->getCallRecorder(Phake::anyParameters())->thenReturn($this->obj); $this->proxy = new Phake_Proxies_CallVerifierProxy(array(new Phake_Matchers_EqualsMatcher('foo'), new Phake_Matchers_EqualsMatcher(array())), $this->mockReader, $this->client); }
public function setUp() { $this->mockMethod = Phake::mock('ReflectionMethod'); Phake::when($this->mockMethod)->isAbstract()->thenReturn(true); $mock = Phake::mock('ReflectionClass'); Phake::when($mock)->getMethod(Phake::anyParameters())->thenReturn($this->mockMethod); Phake::when($mock)->hasMethod(Phake::anyParameters())->thenReturn(true); $this->matcher = new Phake_Matchers_AbstractMethodMatcher($mock); }
protected function setUp() { parent::setUp(); $_POST['launchkey_username'] = '******'; $_POST['launchkey_nonce'] = 'expected nonce'; Phake::when($this->facade)->wp_get_current_user()->thenReturn($this->user); Phake::when($this->facade)->wp_verify_nonce(Phake::anyParameters())->thenReturn(true); Phake::when($this->wpdb)->get_var(Phake::anyParameters())->thenReturn('true'); }
public function createClient(array $parameters = array()) { throw new \Exception('createClient not implemented'); // TODO: refactor to use PhpUnit $mockedClient = \Phake::mock('\\Predis\\Client'); \Phake::when($mockedClient)->isMaster()->thenReturn(false); \Phake::when($mockedClient)->getMaster(\Phake::anyParameters())->thenReturn($mockedClient); return $mockedClient; }
public function testItGetsFunctionList() { $logger = \Phake::mock('Symfony\\Bridge\\Monolog\\Logger'); \Phake::when($logger)->error(\Phake::anyParameters())->thenReturn(true); $SUT = new LicenseButtonExtension('FAKE_BASE_URL', 'FAKE_BASE_IMAGE_URL', array(), $logger); $expectedFunctionList = array('getButtonUrl', 'getButtonImageUrl'); $functionList = array_keys($SUT->getFunctions()); $this->assertEquals($expectedFunctionList, $functionList); }
public function testTranslateIsNotLoadedFromCacheIfResultIsInvalid() { $applicationCacheMock = Phake::mock('Zend_Cache_Backend_Apc'); Phake::when($applicationCacheMock)->test(Phake::anyParameters())->thenReturn(time()); Phake::when($applicationCacheMock)->load(Phake::anyParameters())->thenReturn('incorrectResult'); $cacheProxy = new EngineBlock_Translate_CacheProxy($this->files, $applicationCacheMock); /** @var $translate Zend_Translate */ $translate = $cacheProxy->load(); $this->assertEquals('overschreven', $translate->getAdapter()->translate('override')); }
public function createRedisClient(array $parameters = array()) { $mockedConnectionException = \Phake::mock('Predis\\Connection\\ConnectionException'); $mockedRedisClient = \Phake::mock('\\PSRedis\\Client'); \Phake::when($mockedRedisClient)->isMaster()->thenReturn(false); \Phake::when($mockedRedisClient)->getMaster(\Phake::anyParameters())->thenReturn($mockedRedisClient); \Phake::when($mockedRedisClient)->set(\Phake::anyParameters())->thenThrow($mockedConnectionException); \Phake::when($mockedRedisClient)->get(\Phake::anyParameters())->thenThrow($mockedConnectionException); return $mockedRedisClient; }
public function testValidPostStore() { $rawpost = new Model\RawPost(); $rawpost->setMethod('GET'); $rawpost->setUrl('http://google.com'); $rawpost->setData([1, 2]); $this->poststore->setRawPost($rawpost); $this->assertTrue($this->poststore->storePosts()); \Phake::verify($this->storage, \Phake::times(1))->pipeline(\Phake::anyParameters()); }
public function testItGetSongRecords() { $rawSongArray = array(0 => array('download_url' => NULL, 'key_signature' => '', 'user_favorite' => false, 'likes_count' => 291612, 'release' => '', 'attachments_uri' => 'https://api.soundcloud.com/tracks/114419538/attachments', 'waveform_url' => 'https://w1.sndcdn.com/efdrjZctZysl_m.png', 'purchase_url' => 'https://www.hive.co/l/27m8', 'video_url' => NULL, 'streamable' => true, 'artwork_url' => 'https://i1.sndcdn.com/artworks-000059639237-djo455-large.jpg', 'comment_count' => 21790, 'commentable' => true, 'description' => 'sadasdasdasd', 'download_count' => 694306, 'downloadable' => false, 'embeddable_by' => 'all', 'favoritings_count' => 291612, 'genre' => 'SINEAD ', 'isrc' => '', 'label_id' => NULL, 'label_name' => '', 'license' => 'cc-by', 'original_content_size' => 10667404, 'original_format' => 'mp3', 'playback_count' => 18199988, 'purchase_title' => NULL, 'release_day' => NULL, 'release_month' => NULL, 'release_year' => NULL, 'reposts_count' => 114148, 'state' => 'finished', 'tag_list' => '', 'track_type' => 'remix', 'user' => array('avatar_url' => 'https://i1.sndcdn.com/avatars-000157362167-q7jatm-large.jpg', 'id' => 46182209, 'kind' => 'user', 'permalink_url' => 'http://soundcloud.com/eatdatcake', 'uri' => 'https://api.soundcloud.com/users/46182209', 'username' => 'CAKED UP', 'permalink' => 'eatdatcake', 'last_modified' => '2015/10/06 21:32:55 +0000'), 'bpm' => NULL, 'user_playback_count' => NULL, 'id' => 114419538, 'kind' => 'track', 'created_at' => '2013/10/08 18:08:00 +0000', 'last_modified' => '2015/11/20 00:45:35 +0000', 'permalink' => 'wrecking-ball-caked-up-remix', 'permalink_url' => 'https://soundcloud.com/eatdatcake/wrecking-ball-caked-up-remix', 'title' => 'WRECKING BALL (CAKED UP REMIX) FREE DOWNLOAD', 'duration' => 262841, 'sharing' => 'public', 'stream_url' => 'https://api.soundcloud.com/tracks/114419538/stream', 'uri' => 'https://api.soundcloud.com/tracks/114419538', 'user_id' => 46182209), 1 => array('download_url' => NULL, 'key_signature' => '', 'user_favorite' => false, 'likes_count' => 118830, 'release' => '', 'attachments_uri' => 'https://api.soundcloud.com/tracks/112987097/attachments', 'waveform_url' => 'https://w1.sndcdn.com/I5poXecJTSll_m.png', 'purchase_url' => 'https://www.hive.co/l/27kr', 'video_url' => NULL, 'streamable' => true, 'artwork_url' => 'https://i1.sndcdn.com/artworks-000058880412-u4r5lr-large.jpg', 'comment_count' => 8238, 'commentable' => true, 'description' => 'sadasdasdasda', 'download_count' => 402963, 'downloadable' => false, 'embeddable_by' => 'all', 'favoritings_count' => 118830, 'genre' => 'jon stark ', 'isrc' => '', 'label_id' => NULL, 'label_name' => '', 'license' => 'cc-by', 'original_content_size' => 9070418, 'original_format' => 'mp3', 'playback_count' => 7973353, 'purchase_title' => NULL, 'release_day' => NULL, 'release_month' => NULL, 'release_year' => NULL, 'reposts_count' => 49360, 'state' => 'finished', 'tag_list' => '', 'track_type' => 'remix', 'user' => array('avatar_url' => 'https://i1.sndcdn.com/avatars-000157362167-q7jatm-large.jpg', 'id' => 46182209, 'kind' => 'user', 'permalink_url' => 'http://soundcloud.com/eatdatcake', 'uri' => 'https://api.soundcloud.com/users/46182209', 'username' => 'CAKED UP', 'permalink' => 'eatdatcake', 'last_modified' => '2015/10/06 21:32:55 +0000'), 'bpm' => NULL, 'user_playback_count' => NULL, 'id' => 112987097, 'kind' => 'track', 'created_at' => '2013/09/29 01:22:28 +0000', 'last_modified' => '2015/11/14 15:52:39 +0000', 'permalink' => 'royals-caked-up-remix', 'permalink_url' => 'https://soundcloud.com/eatdatcake/royals-caked-up-remix', 'title' => 'ROYALS-(CAKED UP REMIX) **FREE DOWNLOAD**', 'duration' => 220911, 'sharing' => 'public', 'stream_url' => 'https://api.soundcloud.com/tracks/112987097/stream', 'uri' => 'https://api.soundcloud.com/tracks/112987097', 'user_id' => 46182209)); $expectedArray = array(0 => array('author' => 'CAKED UP', 'title' => 'WRECKING BALL (CAKED UP REMIX) FREE DOWNLOAD', 'duration' => '04.22', 'date' => new \DateTime('2013-10-08 18:08:00 +0000'), 'link' => 'https://soundcloud.com/eatdatcake/wrecking-ball-caked-up-remix', 'license' => 'cc-by', 'service' => 'soundcloud'), 1 => array('author' => 'CAKED UP', 'title' => 'ROYALS-(CAKED UP REMIX) **FREE DOWNLOAD**', 'duration' => '03.40', 'date' => new \DateTime('2013-09-29 01:22:28 +0000'), 'link' => 'https://soundcloud.com/eatdatcake/royals-caked-up-remix', 'license' => 'cc-by', 'service' => 'soundcloud')); $apiClient = \Phake::mock('CCMusicSearchBundle\\Service\\ApiClient'); \Phake::when($apiClient)->performRequest(\Phake::anyParameters())->thenReturn($rawSongArray); $SUT = new SoundcloudApiService($apiClient, 'fake_uri', 'fake_key', 10, array('by')); $resultArray = $SUT->getSongRecords(array('tag' => 'fake_tag')); $this->assertEquals($expectedArray, $resultArray); }