Пример #1
0
 protected function tearDown()
 {
     if (class_exists('MonkeyPatch', false)) {
         if (MonkeyPatchManager::isEnabled('FunctionPatcher')) {
             try {
                 MonkeyPatch::verifyFunctionInvocations();
             } catch (Exception $e) {
                 MonkeyPatch::resetFunctions();
                 throw $e;
             }
             MonkeyPatch::resetFunctions();
         }
         if (MonkeyPatchManager::isEnabled('ConstantPatcher')) {
             MonkeyPatch::resetConstants();
         }
         if (MonkeyPatchManager::isEnabled('MethodPatcher')) {
             try {
                 MonkeyPatch::verifyMethodInvocations();
             } catch (Exception $e) {
                 MonkeyPatch::resetMethods();
                 throw $e;
             }
             MonkeyPatch::resetMethods();
         }
     }
 }
 public function test_auth()
 {
     MonkeyPatch::patchMethod('Ion_auth_model', ['login' => true]);
     MonkeyPatch::verifyInvoked('Ion_auth_model::login', ['foo', 'bar']);
     MonkeyPatch::verifyInvokedOnce('Ion_auth_model::login', ['foo', 'bar']);
     MonkeyPatch::verifyNeverInvoked('Ion_auth_model::login', ['username', 'PHS/DL1m6OMYg']);
     MonkeyPatch::verifyInvokedOnce('CI_Input::post', ['id']);
     MonkeyPatch::verifyInvokedOnce('CI_Input::post', ['password']);
     MonkeyPatch::verifyInvokedMultipleTimes('CI_Input::post', 2);
     $output = $this->request('POST', 'patching_on_method/auth', ['id' => 'foo', 'password' => 'bar']);
     $this->assertContains('Okay!', $output);
 }
 public function test_say_good_afternoon_at_13()
 {
     MonkeyPatch::patchMethod('Greeting', ['getCurrentHour' => '13']);
     $result = $this->obj->say();
     $this->assertEquals('Good Afternoon.', $result);
 }
 public function test_scope_limitation_class()
 {
     MonkeyPatch::patchFunction('function_exists', false, 'Patching_on_function');
     $output = $this->request('GET', 'patching_on_function/scope_limitation_class');
     $this->assertEquals("I don't have microtime(). I don't have microtime(). I have microtime().", $output);
 }
 /**
  * @group patcher
  */
 public function test_index_logged_in_with_method_patch()
 {
     MonkeyPatch::patchMethod('Ion_auth', ['logged_in' => TRUE]);
     $output = $this->request('GET', 'auth_check_in_construct');
     $this->assertContains('You are logged in.', $output);
 }
 /**
  * @dataProvider provide_hours
  */
 public function test_greet($hour, $msg)
 {
     MonkeyPatch::patchFunction('date', $hour, 'Greeter');
     $actual = $this->obj->greet();
     $this->assertEquals($msg, $actual);
 }