public function testFindInTrans()
 {
     $this->target->begin();
     $this->target->find('hoge', 'ssd', array('a', 'b', 3), 'fuga');
     \Phake::verify($this->write)->find('hoge', 'ssd', array('a', 'b', 3), 'fuga');
     \Phake::verify($this->read, \Phake::never())->find('hoge', 'ssd', array('a', 'b', 3), 'fuga');
 }
 public function test_does_not_update_option_when_check_option_returns_errors()
 {
     $_POST['nonce'] = 'not empty';
     Phake::when($this->admin)->check_option(Phake::anyParameters())->thenReturn(array(array(), array('error')));
     $this->wizard->wizard_submit_ajax();
     Phake::verify($this->facade, Phake::never())->update_option(Phake::anyParameters());
 }
 public function test_enqueue_verifier_native_script_does_not_enqueue_script_if_user_cannot_manage_options()
 {
     Phake::when($this->facade)->current_user_can('manage_options')->thenReturn(false);
     $this->wizard->enqueue_verify_configuration_script();
     Phake::verify($this->facade)->current_user_can('manage_options');
     Phake::verify($this->facade, Phake::never())->wp_enqueue_script(Phake::anyParameters());
 }
 public function test_when_authenticate_throws_exception_it_does_not_log_when_not_debug()
 {
     Phake::when($this->facade)->is_debug_log()->thenReturn(false);
     Phake::when($this->sdk_auth)->authenticate(Phake::anyParameters())->thenThrow(new Exception());
     $this->client->launchkey_user_authentication('user', 'username');
     Phake::verify($this->facade, Phake::never())->error_log(Phake::anyParameters());
 }
 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();
 }
 /**
  * @depends test_gets_the_current_user_and_checks_their_status
  */
 public function test_does_not_logoout_or_redirect_if_user_authed_with_launchkey_and_still_authenticated()
 {
     Phake::when($this->facade)->is_user_logged_in()->thenReturn(true);
     Phake::when($this->wpdb)->get_var(Phake::anyParameters())->thenReturn('true');
     $this->client->launchkey_still_authenticated_heartbeat();
     Phake::verify($this->facade, Phake::never())->update_user_meta(Phake::anyParameters());
     Phake::verify($this->facade, Phake::never())->wp_logout(Phake::anyParameters());
 }
 public function test_exceptions_do_not_log_when_not_debug()
 {
     $this->user->launchkey_auth = 'auth_request_id';
     Phake::when($this->facade)->is_debug_log()->thenReturn(false);
     Phake::when($this->sdk_auth)->deOrbit(Phake::anyParameters())->thenThrow(new Exception());
     $this->client->logout();
     Phake::verify($this->facade, Phake::never())->error_log(Phake::anyParameters());
 }
 public function test_non_login_with_loggedin_user_that_is_paired_and_was_authorized_by_launchkey_does_nothing_when_authenticated_is_true()
 {
     Phake::when($this->facade)->wp_get_current_user(Phake::anyParameters())->thenReturn($this->user);
     $this->user->launchkey_username = '******';
     $this->user->launchkey_authorized = 'true';
     $this->client->authentication_controller(null, null, null);
     Phake::verify($this->facade, Phake::never())->remove_all_filters(Phake::anyParameters());
     Phake::verify($this->facade, Phake::never())->add_filter(Phake::anyParameters());
     Phake::verify($this->facade, Phake::never())->wp_logout(Phake::anyParameters());
 }
 public function test_does_not_update_user_meta_on_authorize_exception()
 {
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST['username'] = '******';
     $_REQUEST['nonce'] = 'not empty';
     Phake::when($this->auth)->authorize(Phake::anyParameters())->thenThrow(new Exception());
     $this->wizard->verify_configuration_callback();
     Phake::verify($this->facade, Phake::never())->update_user_meta(Phake::anyParameters());
 }
 public function testShouldNotBindEventListenerWhenJsonFormatOptionIsFalse()
 {
     $builder = \Phake::mock('Symfony\\Component\\Form\\FormBuilderInterface');
     $this->formTypeJsonExtension->buildForm($builder, ['json_format' => false]);
     \Phake::verify($builder, \Phake::never())->addEventSubscriber(new JsonExtensionListener());
 }
 /**
  * @dataProvider provider_admin_actions
  *
  * @param $action
  * @param $callback
  */
 public function test_register_actions_does_not_register_admin_actions_when_not_admin($action, $callback)
 {
     Phake::when($this->facade)->is_admin()->thenReturn(false);
     $this->client->register_actions();
     Phake::verify($this->facade, Phake::never())->add_action($action, array($this->client, $callback));
 }
 public function test_launchkey_admin_callback_admin_pair_does_nothing_when_launchkey_user_cookie_is_set_but_not_valid()
 {
     $_GET['launchkey_admin_pair'] = '1';
     $_COOKIE['launchkey_user'] = '******';
     $this->client->launchkey_admin_callback();
     Phake::verify($this->facade, Phake::never())->update_user_meta(Phake::anyParameters());
 }
 public function test_launchkey_logout_without_access_token_cookie_does_not_set_cookie()
 {
     $this->client->launchkey_logout();
     Phake::verify($this->facade, Phake::never())->setcookie(Phake::anyParameters());
 }
 /**
  * @dataProvider provider_non_native_implementations
  *
  * @param $type
  */
 public function test_auth_response_callback_does_not_set_launchkey_username_for_non_native_implementations($type)
 {
     Phake::when($this->facade)->get_option(Phake::anyParameters())->thenReturn(array(LaunchKey_WP_Options::OPTION_IMPLEMENTATION_TYPE => $type));
     Phake::when($this->sdk_sse)->handleEvent(Phake::anyParameters())->thenReturn($this->auth_response);
     Phake::when($this->auth_response)->getUserPushId()->thenReturn($expected = 'Expceted User Push ID');
     $this->client->launchkey_callback();
     Phake::verify($this->facade, Phake::never())->update_user_meta($this->user->ID, 'launchkey_username', $this->anything());
 }
 public function test_remove_password_handler_without_verified_nonce_does_not_remove_password()
 {
     $_GET['launchkey_remove_password'] = '******';
     $_GET['launchkey_nonce'] = 'nonce value';
     $this->client->remove_password_handler();
     Phake::verify($this->facade)->wp_verify_nonce('nonce value', LaunchKey_WP_User_Profile::NONCE_KEY);
     Phake::verify($this->facade, Phake::never())->wp_update_user(Phake::anyParameters());
 }
 public function test_launchkey_pair_does_not_show_launch_key_form()
 {
     $_GET['launchkey_pair'] = 'Yup';
     $this->client->launchkey_form();
     Phake::verify($this->facade, Phake::never())->render_template('launchkey-form', $this->anything());
 }
 public function testUnitOfWorkCleanupDelayedUntilOuterUnitOfWorkIsCleanedUp_InnerCommit_OuterRollback()
 {
     $outerListener = \Phake::mock(UnitOfWorkListenerInterface::class);
     $innerListener = \Phake::mock(UnitOfWorkListenerInterface::class);
     $outer = DefaultUnitOfWork::startAndGet();
     $inner = DefaultUnitOfWork::startAndGet();
     $inner->registerListener($innerListener);
     $outer->registerListener($outerListener);
     $inner->commit();
     \Phake::verify($innerListener, \Phake::never())->afterCommit(\Phake::anyParameters());
     \Phake::verify($innerListener, \Phake::never())->onCleanup(\Phake::anyParameters());
     $outer->rollback();
     \Phake::verify($outerListener, \Phake::never())->onPrepareCommit(\Phake::anyParameters());
     \Phake::inOrder(\Phake::verify($innerListener)->onPrepareCommit(\Phake::anyParameters()), \Phake::verify($innerListener)->onRollback(\Phake::anyParameters()), \Phake::verify($outerListener)->onRollback(\Phake::anyParameters()), \Phake::verify($innerListener)->onCleanup(\Phake::anyParameters()), \Phake::verify($outerListener)->onCleanup(\Phake::anyParameters()));
 }
 public function test_hide_when_true_does_not_show_form()
 {
     $this->client->launchkey_shortcode(array('hide' => 'true'));
     Phake::verify($this->client, Phake::never())->launchkey_form(Phake::anyParameters());
 }
 /**
  * @dataProvider debug_methods_data_provider
  * @param $method
  */
 public function test_debug_methods_do_not_log_when_not_debug($method)
 {
     Phake::when($this->facade)->is_debug_log(Phake::anyParameters())->thenReturn(false);
     call_user_func(array($this->logger, $method), null);
     Phake::verify($this->facade, Phake::never())->error_log(Phake::anyParameters());
 }
 public function testMatch_ExcessEventsIgnored()
 {
     $this->assertTrue($this->testSubject->matches(array($this->stubEvent1, $this->stubEvent2, $this->stubEvent3, new StubEvent())));
     \Phake::verify($this->mockMatcher1, \Phake::times(1))->matches($this->stubEvent1);
     \Phake::verify($this->mockMatcher1, \Phake::never())->matches($this->stubEvent2);
     \Phake::verify($this->mockMatcher2, \Phake::never())->matches($this->stubEvent1);
     \Phake::verify($this->mockMatcher2, \Phake::times(1))->matches($this->stubEvent2);
     \Phake::verify($this->mockMatcher3, \Phake::never())->matches($this->stubEvent1);
     \Phake::verify($this->mockMatcher3, \Phake::never())->matches($this->stubEvent2);
     \Phake::verify($this->mockMatcher3, \Phake::times(1))->matches($this->stubEvent3);
 }
 /**
  * @test
  * @dataProvider notificationDecisions
  *
  * @param bool $notify
  */
 public function runsATest($notify)
 {
     $outputBuffering = \Phake::mock('Stagehand\\TestRunner\\Util\\OutputBuffering');
     \Phake::when($outputBuffering)->clearOutputHandlers()->thenReturn(null);
     $this->setComponent('output_buffering', $outputBuffering);
     $preparer = \Phake::mock('Stagehand\\TestRunner\\Preparer\\Preparer');
     \Phake::when($preparer)->prepare()->thenReturn(null);
     $this->setComponent('phpunit.preparer', $preparer);
     $collector = \Phake::mock('Stagehand\\TestRunner\\Collector\\Collector');
     $testSuite = new \stdClass();
     \Phake::when($collector)->collect()->thenReturn($testSuite);
     $this->setComponent('phpunit.collector', $collector);
     $runner = \Phake::mock('Stagehand\\TestRunner\\Runner\\Runner');
     \Phake::when($runner)->run($this->anything())->thenReturn(null);
     \Phake::when($runner)->shouldNotify()->thenReturn($notify);
     if ($notify) {
         $notification = new Notification(Notification::RESULT_PASSED, 'MESSAGE');
         \Phake::when($runner)->getNotification()->thenReturn($notification);
     }
     $this->setComponent('phpunit.runner', $runner);
     $notifier = \Phake::mock('Stagehand\\TestRunner\\Notification\\Notifier');
     if ($notify) {
         \Phake::when($notifier)->notifyResult($this->anything())->thenReturn(null);
     }
     $this->setComponent('notifier', $notifier);
     $this->createComponent('test_runner')->run();
     \Phake::verify($preparer)->prepare();
     \Phake::verify($collector)->collect();
     \Phake::verify($runner)->run($this->identicalTo($testSuite));
     \Phake::verify($runner)->shouldNotify();
     \Phake::verify($runner, \Phake::times($notify ? 1 : 0))->getNotification();
     if ($notify) {
         \Phake::verify($notifier)->notifyResult($this->identicalTo($notification));
     } else {
         \Phake::verify($notifier, \Phake::never())->notifyResult();
     }
 }
Exemple #22
0
 /**
  * Tests that never catches an invocation
  * @expectedException Phake_Exception_VerificationException
  */
 public function testNeverMismatch()
 {
     $mock = Phake::mock('PhakeTest_MockedClass');
     $mock->foo();
     Phake::verify($mock, Phake::never())->foo();
 }
 public function testEventReceivedDuringReplay()
 {
     $concurrentMessage = new GenericEventMessage(new Payload("Concurrent MSG"));
     $self = $this;
     \Phake::when($this->mockEventStore)->visitEvents(\Phake::anyParameters())->thenGetReturnByLambda(function ($visitor, $criteria) use($concurrentMessage, $self) {
         $self->assertTrue($self->testSubject->isInReplayMode());
         $self->testSubject->publish(array($concurrentMessage));
         foreach ($self->messages as $message) {
             $visitor->doWithEvent($message);
         }
     });
     $listener = \Phake::mock(ReplayAwareListenerInterface::class);
     $this->testSubject->getEventListenerRegistry()->subscribe($listener);
     $this->testSubject->startReplay();
     \Phake::inOrder(\Phake::verify($this->mockMessageHandler)->prepareForReplay(\Phake::anyParameters()), \Phake::verify($listener)->beforeReplay(), \Phake::verify($this->mockEventStore)->visitEvents(\Phake::anyParameters()), \Phake::verify($this->mockMessageHandler)->onIncomingMessages(\Phake::anyParameters()), \Phake::verify($this->delegate, \Phake::times(10))->publish(\Phake::anyParameters()), \Phake::verify($listener)->afterReplay(), \Phake::verify($this->mockMessageHandler)->processBacklog(\Phake::anyParameters()));
     \Phake::verify($this->delegate, \Phake::never())->publish($concurrentMessage);
     //   \Phake::verify($this->delegate)->subscribe($listener);
 }
 public function testHandleUnrelatedEvent()
 {
     $this->manager->handle(new GenericEventMessage(new \stdClass()));
     \Phake::verify($this->sagaRepository, \Phake::never())->find($this->any());
 }
Exemple #25
0
 public function testMatcherChainReturnsAMatcherChain()
 {
     $matcher1 = Phake::mock('Phake_Matchers_IChainableArgumentMatcher');
     $matcher2 = Phake::mock('Phake_Matchers_IChainableArgumentMatcher');
     $matcher3 = Phake::mock('Phake_Matchers_IChainableArgumentMatcher');
     $matcherChain = $this->factory->createMatcherChain(array($matcher1, $matcher2, $matcher3));
     $this->assertSame($matcher1, $matcherChain);
     Phake::verify($matcher1)->setNextMatcher($this->equalTo($matcher2));
     Phake::verify($matcher2)->setNextMatcher($this->equalTo($matcher3));
     Phake::verify($matcher3, Phake::never())->setNextMatcher(Phake::anyParameters());
 }
 /**
  * @dataProvider provider_notice_hook_suffixes
  *
  * @param $hook_suffix
  */
 public function test_activate_notice_shows_correct_template_on_correct_pages_when_secret_key($hook_suffix)
 {
     $this->options[LaunchKey_WP_Options::OPTION_SECRET_KEY] = 'Not Empty';
     Phake::when($this->facade)->get_hook_suffix()->thenReturn($hook_suffix);
     $this->admin->activate_notice();
     Phake::verify($this->template, Phake::never())->render_template('admin/activate-plugin', $this->anything());
 }
 public function testMatch_NoMatches()
 {
     \Phake::when($this->mockMatcher1)->matches(\Phake::anyParameters())->thenReturn(false);
     \Phake::when($this->mockMatcher2)->matches(\Phake::anyParameters())->thenReturn(false);
     \Phake::when($this->mockMatcher3)->matches(\Phake::anyParameters())->thenReturn(false);
     $this->assertFalse($this->testSubject->matches(array($this->stubEvent1, $this->stubEvent2)));
     \Phake::verify($this->mockMatcher1)->matches($this->stubEvent1);
     \Phake::verify($this->mockMatcher1)->matches($this->stubEvent2);
     \Phake::verify($this->mockMatcher2, \Phake::never())->matches($this->stubEvent1);
     \Phake::verify($this->mockMatcher2, \Phake::never())->matches($this->stubEvent2);
     \Phake::verify($this->mockMatcher3, \Phake::never())->matches($this->stubEvent1);
     \Phake::verify($this->mockMatcher3, \Phake::never())->matches($this->stubEvent2);
 }
 public function test_does_not_register_session_index_on_unsuccessful_auth()
 {
     Phake::when($this->saml_response_service)->is_session_index_registered()->thenReturn(true);
     $this->client->authenticate(null, null, null);
     Phake::verify($this->saml_response_service, Phake::never())->register_session_index();
 }
 public function testSendMessageWithPublisherAck_UnitOfWorkCommitted()
 {
     $this->testSubject->setTransactional(false);
     $this->testSubject->setWaitForPublisherAck(true);
     $this->testSubject->setPublisherAckTimeout(123);
     $channel = \Phake::mock(AMQPChannel::class);
     \Phake::when($channel)->wait_for_pending_acks()->thenReturn(null);
     \Phake::when($this->connection)->channel()->thenReturn($channel);
     $message = new GenericEventMessage(new Payload("Message"));
     \Phake::when($this->serializer)->serialize(\Phake::equalTo($message->getPayload()))->thenReturn(new SimpleSerializedObject(json_encode($message->getPayload()), new SimpleSerializedType(Payload::class)));
     \Phake::when($this->serializer)->serialize(\Phake::equalTo($message->getMetaData()))->thenReturn(new SimpleSerializedObject(json_encode(array('metadata' => array())), new SimpleSerializedType(MetaData::class)));
     $uow = DefaultUnitOfWork::startAndGet();
     $this->testSubject->publish(array($message));
     \Phake::verify($channel, \Phake::never())->wait_for_pending_acks();
     $uow->commit();
     \Phake::verify($channel)->confirm_select();
     \Phake::verify($channel)->basic_publish(\Phake::anyParameters());
     \Phake::verify($channel)->wait_for_pending_acks(123);
 }