Exemplo n.º 1
0
 /**
  * @test
  */
 public function getValidIpAddress()
 {
     $ip = '127.0.0.1';
     $exception = parent::throwException(new CouldNotResolveIpAddressException());
     $ipProvider = $this->getIpProviderMock($exception, 'foobar', $ip);
     $currentIpAddress = $ipProvider->getCurrentIpAddress();
     parent::assertEquals($ip, $currentIpAddress);
 }
Exemplo n.º 2
0
 private function createUndeclaredMethods()
 {
     foreach (array_keys($this->originClassMethods) as $originalMethodName) {
         if (false == array_key_exists($originalMethodName, $this->mockMethods)) {
             $method = $this->mock->expects($this->testCase->any());
             $method->method($originalMethodName);
             $method->will($this->testCase->throwException(new UndeclaredMethodInvocationException($originalMethodName)));
         }
     }
 }
Exemplo n.º 3
0
 /** @return array */
 protected function parseMockMethodArgs($method, array $args)
 {
     $expects = TestCase::any();
     $with = null;
     $will = TestCase::returnValue(null);
     if (count($args) == 1) {
         if ($args[0] instanceof InvokedRecorder || $args[0] instanceof InvokedAtIndex) {
             $expects = $args[0];
         } else {
             $will = $args[0];
         }
     } elseif (count($args) == 2) {
         if ($args[1] instanceof InvokedRecorder || $args[1] instanceof InvokedAtIndex) {
             if (is_array($args[0])) {
                 list($with, $expects) = $args;
             } else {
                 list($will, $expects) = $args;
             }
         } elseif (is_array($args[0])) {
             list($with, $will) = $args;
         } else {
             throw new \InvalidArgumentException();
         }
     } elseif (count($args) == 3) {
         if (is_array($args[0]) && ($args[2] instanceof InvokedRecorder || $args[2] instanceof InvokedAtIndex)) {
             list($with, $will, $expects) = $args;
         } else {
             throw new \InvalidArgumentException();
         }
     }
     if ($will instanceof \Exception) {
         $will = PhpUnitTestCase::throwException($will);
     } elseif (!$will instanceof Stub && !$will instanceof \Closure && !is_null($will)) {
         $will = PhpUnitTestCase::returnValue($will);
     }
     return array('method' => $method, 'expects' => $expects, 'with' => $with, 'will' => $will);
 }
Exemplo n.º 4
0
/**
 *
 *
 * @param  Exception $exception
 * @return PHPUnit_Framework_MockObject_Stub_Exception
 * @since  Method available since Release 3.1.0
 */
function throwException(Exception $exception)
{
    return PHPUnit_Framework_TestCase::throwException($exception);
}