public function testCorrelationDataIsAttached() { CorrelationDataHolder::setCorrelationData(array('correlationId' => 'test')); $this->testSubject->send(new HelloCommand('Hi !!!')); \Phake::verify($this->mockCommandBus)->dispatch(\Phake::capture($command), null); $this->assertEquals(array('correlationId' => 'test'), $command->getMetaData()->all()); }
public function test_gets_the_current_user_and_checks_their_status() { Phake::when($this->wpdb)->prepare(Phake::anyParameters())->thenReturn('PREPARED QUERY'); $this->client->launchkey_still_authenticated_page_load(); Phake::inOrder(Phake::verify($this->wpdb)->prepare(Phake::capture($query), $this->user->ID), Phake::verify($this->wpdb)->get_var('PREPARED QUERY')); $this->assertEquals($query, "SELECT meta_value FROM {$this->wpdb->usermeta} WHERE user_id = %s AND meta_key = 'launchkey_authorized' LIMIT 1"); }
public function testConsentIsSkippedWhenDisabledPerSp() { $this->proxyServerMock->getRepository()->fetchIdentityProviderByEntityId('testIdP')->spsEntityIdsWithoutConsent[] = 'testSp'; $provideConsentService = $this->factoryService(); $provideConsentService->serve(null); Phake::verify($this->proxyServerMock->getBindingsModule())->send(Phake::capture($message), Phake::capture($metadata)); $this->assertEquals('urn:oasis:names:tc:SAML:2.0:consent:inapplicable', $message->getConsent()); }
public function testTranslationHandlersCompilerPass() { $containerBuilder = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); $bundle = new ModeraTranslationsBundle(); $bundle->build($containerBuilder); \Phake::verify($containerBuilder)->addCompilerPass(\Phake::capture($pass)); $this->assertInstanceOf('Modera\\TranslationsBundle\\DependencyInjection\\Compiler\\TranslationHandlersCompilerPass', $pass); }
public function testCreateUserTriggersAppropriateWhiteLabelUserCreatedEvent() { $this->whitelabelService->createUser("identifier"); $name = $event = null; \Phake::verify($this->eventDispatcher)->dispatchEvent(\Phake::capture($name), \Phake::capture($event)); $this->assertEquals("launchkey.whitelabel.user.created", $name, "Unexpected event name"); $this->assertInstanceOf('\\LaunchKey\\SDK\\Event\\WhiteLabelUserCreatedEvent', $event, "Unexpected event type"); $this->assertSame($this->whiteLabelUser, $event->getWhiteLabelUser(), "Unexpected white label user in event"); }
public function test_launchkey_logout_sets_connection_close_header() { $_COOKIE['launchkey_access_token'] = 'access token'; $this->client->launchkey_logout(); Phake::verify($this->facade)->wp_remote_get($this->anything(), Phake::capture($options)); $this->assertArrayHasKey('headers', $options); $this->assertInternalType('array', $options['headers']); $this->assertEquals($this->options[LaunchKey_WP_Options::OPTION_REQUEST_TIMEOUT], $options['timeout']); }
public function testProcess() { $routingLoaderWannaBe = \Phake::mock('Symfony\\Component\\DependencyInjection\\Definition'); $containerBuilder = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); \Phake::when($containerBuilder)->getDefinition('routing.loader')->thenReturn($routingLoaderWannaBe); $cp = new DelegatingLoaderCloningCompilerPass(); $cp->process($containerBuilder); \Phake::verify($containerBuilder)->setDefinition('modera_routing.symfony_delegating_loader', \Phake::capture($clonedDefinition)); $this->assertInstanceOf(get_class($routingLoaderWannaBe), $clonedDefinition); }
public function testContributorIsInjected() { $containerBuilder = \Phake::mock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); $bundle = new ModeraBackendDashboardBundle($containerBuilder); $bundle->build($containerBuilder); \Phake::verify($containerBuilder)->addCompilerPass(\Phake::capture($pass)); $this->assertInstanceOf('Sli\\ExpanderBundle\\DependencyInjection\\CompositeContributorsProviderCompilerPass', $pass); /* @var CompositeContributorsProviderCompilerPass $pass */ $this->assertEquals('modera_backend_dashboard.dashboard_provider', $pass->getProviderServiceId()); $this->assertEquals('modera_backend_dashboard.dashboard_provider', $pass->getContributorServiceTagName()); }
public function testMakeWithMultiLevelDefaultsMergesOverridesData() { $bp = new Blueprint($this->machinist, 'test_table', array('doc' => array('a' => 'aye', 'c' => 'see'))); Phake::when($this->store)->find(Phake::anyParameters())->thenReturn(array(new stdClass())); Phake::when($this->store)->columns(Phake::anyParameters())->thenReturn(array('doc')); $bp->make(array('doc' => array('a' => 'new aye', 'b' => 'bee'))); $expected = array('doc' => array('a' => 'new aye', 'b' => 'bee', 'c' => 'see')); $actual = null; Phake::verify($this->store)->insert('test_table', Phake::capture($actual)); $this->assertEquals($expected, $actual); }
public function test_create_admin_page_echos_form_correctly() { $this->options[LaunchKey_WP_Options::OPTION_IMPLEMENTATION_TYPE] = LaunchKey_WP_Implementation_Type::NATIVE; $this->options[LaunchKey_WP_Options::OPTION_ROCKET_KEY] = 'Expected Rocket Key'; $this->options[LaunchKey_WP_Options::OPTION_APP_DISPLAY_NAME] = 'Expected App Display Name'; $this->options[LaunchKey_WP_Options::OPTION_SSL_VERIFY] = true; $expected_context = array('rocket_key' => 'Expected Rocket Key', 'app_display_name' => 'Expected App Display Name', 'callback_url' => sprintf('AdminURL [admin-ajax.php?action=%s]', LaunchKey_WP_Native_Client::CALLBACK_AJAX_ACTION), 'sso_post_url' => 'LoginURL [ROOT]', 'ssl_verify_checked' => 'checked="checked"', 'domain' => 'Parsed URL', 'mcrypt_pass_fail' => 'fail', 'openssl_pass_fail' => 'fail', 'curl_pass_fail' => 'fail', 'dom_pass_fail' => 'fail', 'show_sso_next' => 'hide', 'show_sso_back' => 'show', 'wp_username' => 'login', 'sso_entity_id' => null, 'sso_public_key' => null, 'sso_login_url' => null, 'sso_logout_url' => null, 'sso_error_url' => null, 'settings-sso-visible' => 'hide', 'settings-standard-visible' => null); $this->admin->create_launchkey_settings_page(); Phake::verify($this->template)->render_template('admin/settings', Phake::capture($actual_context)); Phake::verify($this->facade)->_echo('Rendered [admin/settings]'); $this->assertEquals($expected_context, $actual_context); }
public function testOnKernelException() { $event = $this->createMockEvent(true, '/mega-backend', new AccessDeniedException()); $lnr = new AjaxAuthenticationValidatingListener('/mega-backend'); $lnr->onKernelException($event); \Phake::verify($event, \Phake::times(2))->getRequest(); \Phake::verify($event)->getException(); \Phake::verify($event)->setResponse(\Phake::capture($response)); \Phake::verifyNoOtherInteractions($event); /* @var JsonResponse $response */ $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $response); $content = json_decode($response->getContent(), true); $this->assertTrue(is_array($content)); $this->assertArrayHasKey('success', $content); $this->assertFalse($content['success']); $this->assertArrayHasKey('message', $content); $this->assertTrue('' != $content['message']); }
public function test_headers_are_passed_to_request() { $_SERVER['HTTP_MY_HEADER'] = 'Expected Header Value'; $this->client->launchkey_callback(); Phake::verify($this->sdk_sse)->handleEvent(Phake::capture($request), $this->anything()); $this->assertEquals(array('Expected Header Value'), $request->getHeader('my-header')); }
public function test_deorbit_callback_searches_for_user_by_user_hash() { Phake::when($this->deorbit_callback)->getUserHash()->thenReturn('User hash'); Phake::when($this->sdk_auth)->handleCallback(Phake::anyParameters())->thenReturn($this->deorbit_callback); $this->client->launchkey_callback(); Phake::verify($this->facade)->get_users(Phake::capture($actual)); $this->assertEquals(array('meta_key' => 'launchkey_user', 'meta_value' => 'User hash'), $actual); }
/** * Make sure arguments are captured with no issues */ public function testArgumentCapturingWorksOnStubbing() { $mock = Phake::mock('PhakeTest_MockedClass'); $obj = new stdClass(); Phake::when($mock)->fooWithArgument(Phake::capture($toArgument))->thenReturn(true); $mock->fooWithArgument($obj); $this->assertSame($obj, $toArgument); }
public function test_when_launchkey_meta_data_and_no_password_paired_without_password_template_shown_with_the_correct_context() { $this->user->ID = 1; $this->user->user_pass = null; $this->client->launchkey_personal_options($this->user); Phake::verify($this->template)->render_template('personal-options/paired-without-password', Phake::capture($actual_context)); Phake::verify($this->facade)->_echo('Rendered [personal-options/paired-without-password]'); $expected_context = array('app_display_name' => 'App Display Name'); $this->assertEquals($expected_context, $actual_context); }
public function test_verify_action_create_user_error_sends_json_response() { $_REQUEST['nonce'] = 'not empty'; $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['verify_action'] = 'pair'; $this->user->user_login = $expected_login = '******'; Phake::when($this->white_label_service)->createUser(Phake::anyParameters())->thenThrow(new Exception('message', 999)); $this->wizard->verify_configuration_callback(); Phake::verify($this->white_label_service)->createUser($expected_login); Phake::verify($this->facade)->wp_send_json(Phake::capture($response)); return $response; }
/** * @param string $notificationMessage * @param string $result * * @since Method available since Release 4.0.0 * * @test * @dataProvider emptyNotificationMessages */ public function notifiesTheSpecialMessageIfTheNotificationMessageIsEmpty($notificationMessage, $result) { $this->setComponent('output_buffering', \Phake::mock('Stagehand\\TestRunner\\Util\\OutputBuffering')); $this->setComponent('phpunit.preparer', \Phake::mock('Stagehand\\TestRunner\\Preparer\\Preparer')); $collector = \Phake::mock('Stagehand\\TestRunner\\Collector\\Collector'); \Phake::when($collector)->collect()->thenReturn(new \stdClass()); $this->setComponent('phpunit.collector', $collector); $notification = \Phake::mock('Stagehand\\TestRunner\\Notification\\Notification'); \Phake::when($notification)->getMessage()->thenReturn($notificationMessage); if ($result == Notification::RESULT_PASSED) { \Phake::when($notification)->isPassed()->thenReturn(true); \Phake::when($notification)->isFailed()->thenReturn(false); } elseif ($result == Notification::RESULT_FAILED) { \Phake::when($notification)->isPassed()->thenReturn(false); \Phake::when($notification)->isFailed()->thenReturn(true); } $runner = \Phake::mock('Stagehand\\TestRunner\\Runner\\Runner'); \Phake::when($runner)->shouldNotify()->thenReturn(true); \Phake::when($runner)->getNotification()->thenReturn($notification); $this->setComponent('phpunit.runner', $runner); $notifier = \Phake::mock('Stagehand\\TestRunner\\Notification\\Notifier'); $this->setComponent('notifier', $notifier); $this->createComponent('test_runner')->run(); \Phake::verify($notifier)->notifyResult(\Phake::capture($newNotification)); if ($result == Notification::RESULT_PASSED) { \Phake::when($notification)->isPassed(); \Phake::when($notification, \Phake::times(0))->isFailed(); } elseif ($result == Notification::RESULT_FAILED) { \Phake::when($notification)->isPassed(); \Phake::when($notification)->isFailed(); } }
/** * Tests that verifier calls that are not given an argument matcher will generate an equals matcher * with the given value. */ public function testProxyTransformsNonMatchersToEqualsMatcher() { $argumentMatcher = new Phake_Matchers_EqualsMatcher('test'); Phake::when($this->verifier)->verifyCall(Phake::anyParameters())->thenReturn(new Phake_CallRecorder_VerifierResult(true, array(Phake::mock('Phake_CallRecorder_CallInfo')))); $this->proxy->foo('test'); Phake::verify($this->verifier)->verifyCall(Phake::capture($expectation)); $this->assertEquals(array($argumentMatcher), $expectation->getArgumentMatchers()); }
public function test_remote_get_query_is_made_for_access_token() { $this->options[LaunchKey_WP_Options::OPTION_ROCKET_KEY] = 12345; $this->options[LaunchKey_WP_Options::OPTION_SECRET_KEY] = 'secret key'; $this->client->launchkey_callback(); Phake::verify($this->facade)->wp_remote_get(Phake::capture($query), $this->anything()); return $query; }
/** * @test * @since Method available since Release 2.0.0 */ public function invokesTheActionAndTriggersTheNextEvent() { $actionInvoker = \Phake::mock('Piece\\Flow\\PageFlow\\ActionInvokerInterface'); \Phake::when($actionInvoker)->invoke($this->anything(), $this->anything())->thenReturn('foo'); $event = \Phake::mock('Stagehand\\FSM\\Event\\EventInterface'); $state = \Phake::mock('Stagehand\\FSM\\State\\StateInterface'); \Phake::when($state)->getEvent($this->anything())->thenReturn($event); $fsm = \Phake::mock('Stagehand\\FSM\\StateMachine\\StateMachine'); \Phake::when($fsm)->getCurrentState()->thenReturn($state); $pageFlow = \Phake::mock('Piece\\Flow\\PageFlow\\PageFlowInterface'); \Phake::when($pageFlow)->getActionInvoker()->thenReturn($actionInvoker); $payload = new \stdClass(); $eventHandler = new EventHandler('my_controller:onRegister', $pageFlow); $eventHandler->invokeActionAndTriggerEvent($event, $payload, $fsm); \Phake::verify($actionInvoker)->invoke($this->equalTo('my_controller:onRegister'), \Phake::capture($eventContext)); /* @var $eventContext \Piece\Flow\PageFlow\EventContext */ $this->assertThat($eventContext->getEvent(), $this->identicalTo($event)); $this->assertThat($eventContext->getPageFlow(), $this->identicalTo($pageFlow)); $this->assertThat($eventContext->getPayload(), $this->identicalTo($payload)); \Phake::verify($fsm)->getCurrentState(); \Phake::verify($state)->getEvent($this->equalTo('foo')); \Phake::verify($fsm)->queueEvent('foo'); }
public function test_when_token_invalid_and_refresh_token_exists_query_is_made_for_access_token() { $this->client->launchkey_admin_callback(); Phake::verify($this->facade)->wp_remote_post('https://oauth.launchkey.com/access_token', Phake::capture($options)); return $options; }
public function testCorrelationDataReadFromProvider() { $correlationDataProvider = \Phake::mock(CorrelationDataProviderInterface::class); \Phake::when($correlationDataProvider)->correlationDataFor(\Phake::anyParameters())->thenReturn(array()); $this->manager->setCorrelationDataProvider($correlationDataProvider); $this->manager->handle(new GenericEventMessage(new StartingEvent("12", new MetaData(array('key' => 'val'))))); \Phake::verify($correlationDataProvider)->correlationDataFor(\Phake::capture($message)); $this->assertInstanceOf(EventMessageInterface::class, $message); }
public function test_register_session_index_writes_data_to_the_table() { $start = time(); $this->service->register_session_index(); $end = time(); $expected = "INSERT INTO prefix_launchkey_sso_sessions VALUES (%s, %s) ON DUPLICATE KEY UPDATE seen = %s"; Phake::inOrder(Phake::verify($this->wpdb)->prepare($expected, Phake::equalTo("id-b4373c87a6f18f97862c931744fd799f"), Phake::capture($insert_date_string), Phake::capture($update_date_string)), Phake::verify($this->wpdb)->query(static::PREPARED_STARTEMENT)); $this->assertEquals($insert_date_string, $update_date_string, "Insert and update date strings were expected to be the same but were not"); $this->assertRegExp('/[12][0-9]{3}-[0-9]{2}-[0-9]{2} [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/', $insert_date_string, "Date strings are not in MYSQL date format"); $sql_time = strtotime($insert_date_string); $this->assertGreaterThanOrEqual($start, $sql_time, sprintf("Date string of %s is not on or after recorded start time of %s", $insert_date_string, date('Y-m-d H:i:s', $start))); $this->assertLessThanOrEqual($end, $sql_time, sprintf("Date string of %s is not on or after recorded start time of %s", $insert_date_string, date('Y-m-d H:i:s', $end))); }
public function test_sends_json_response() { $this->wizard->wizard_easy_setup_qr_code(); Phake::verify($this->facade)->wp_send_json(Phake::capture($json)); return $json; }
public function test_login_url_in_context() { $this->options[LaunchKey_WP_Options::OPTION_ROCKET_KEY] = 12345; Phake::when($this->facade)->admin_url(Phake::anyParameters())->thenReturn('admin url'); $this->client->launchkey_form(); Phake::verify($this->template)->render_template('launchkey-form', Phake::capture($context)); Phake::verify($this->facade)->_echo('Rendered [launchkey-form]'); $this->assertArrayHasKey('login_url', $context); return $context['login_url']; }
public function test_sends_response_as_ajax() { Phake::when($this->white_label_user)->getQrCodeUrl()->thenReturn('Expected QR Code URL'); Phake::when($this->white_label_user)->getCode()->thenReturn('Expected Code'); Phake::when($this->facade)->wp_create_nonce(Phake::anyParameters())->thenReturn('Expected Nonce'); $this->client->white_label_pair_callback(); Phake::verify($this->facade)->wp_create_nonce(LaunchKey_WP_User_Profile::NONCE_KEY); Phake::verify($this->facade)->wp_send_json(Phake::capture($response)); return $response; }
/** * @depends test_user_login_creates_user_when_none_found */ public function test_when_user_login_creates_user_sets_role_to_administrator_when_role_is_admin() { Phake::when($this->facade)->get_user_by(Phake::anyParameters())->thenReturn(null); Phake::when($this->saml_response_service)->get_attribute(Phake::anyParameters())->thenReturn(array("admin")); $this->client->authenticate(null, null, null); Phake::verify($this->saml_response_service)->get_attribute("role"); Phake::verify($this->facade)->wp_insert_user(Phake::capture($user_data)); $this->assertArrayHasKey("role", $user_data, "No role value in user data"); $this->assertEquals("administrator", $user_data["role"]); }
public function testVerifierChecksVerificationMode() { $expectation = new Phake_CallRecorder_CallExpectation($this->obj, 'foo', null, $this->verifierMode); $return = new Phake_CallRecorder_CallInfo($this->callArray[1], new Phake_CallRecorder_Position(0)); Phake::when($this->recorder)->getCallInfo(Phake::anyParameters())->thenReturn($return); Phake::when($this->verifierMode)->verify(Phake::anyParameters())->thenReturn(new Phake_CallRecorder_VerifierMode_Result(true, '')); $this->verifier->verifyCall($expectation); Phake::verify($this->verifierMode)->verify(Phake::capture($verifyCallInfo)); $this->assertEquals(array($return, $return), $verifyCallInfo); }