コード例 #1
0
 private function handleCaughtException(\Exception $exception, $expectedError)
 {
     $reflect = new ReflectionClass($exception);
     $caught = $reflect->getShortName();
     $passed = false;
     if ($caught === 'Missing404Exception' && $expectedError === 'missing') {
         $passed = true;
     } elseif ($caught === 'Conflict409Exception' && $expectedError === 'conflict') {
         $passed = true;
     } elseif ($caught === 'Missing404Exception' && $expectedError === 'missing') {
         $passed = true;
     } elseif ($caught === 'Forbidden403Exception' && $expectedError === 'forbidden') {
         $passed = true;
     } elseif ($caught === 'RequestTimeout408Exception' && $expectedError === 'request_timeout') {
         $passed = true;
     } elseif ($caught === 'BadRequest400Exception' && $expectedError === 'request') {
         $passed = true;
     } elseif ($caught === 'ServerErrorResponseException' && $expectedError === 'request') {
         $passed = true;
     } elseif ($caught === 'RuntimeException' && $expectedError === 'param') {
         $passed = true;
     } elseif ($caught === 'Missing404Exception' && $expectedError === 'missing') {
         $passed = true;
     }
     if ($passed === false) {
         if (YamlRunnerTest::checkExceptionRegex($expectedError, $exception)) {
             $passed = true;
         } elseif ($exception->getPrevious() !== null) {
             // try second level
             if (YamlRunnerTest::checkExceptionRegex($expectedError, $exception->getPrevious())) {
                 $passed = true;
             }
         }
     }
     if ($passed === true) {
         $this->assertTrue(true);
         return json_decode($exception->getMessage(), true);
     }
     //$this->fail("Tried to match exception, failed.  Exception: ".$exception->getMessage());
     throw $exception;
 }