Пример #1
0
 public function testNonSerializableExceptionIsReproducable()
 {
     $object = new NotSerializableException("testmessage", 42);
     $filename = $this->getFixturePath() . '/not_serializable_exception.fix';
     $fixture = new FileFixture($filename);
     $fixture->setResult($object);
     $fixture->save();
     $result = $fixture->getResult();
     $this->assertInstanceOf('TestTools\\Tests\\Fixture\\NotSerializableException', $result);
     $this->assertEquals("testmessage", $result->getMessage());
     $this->assertEquals(42, $result->getCode());
 }
 /**
  * Wrapper that calls the parent function with file fixtures (if enabled)
  *
  * @param string $functionName
  * @param array $arguments
  * @param array $resultArguments
  * @throws \Exception
  * @return mixed
  */
 protected function callWithFixtures($functionName, array $arguments = array(), &$resultArguments = null)
 {
     if ($this->usesFixtures()) {
         // Determine fixture file name
         $fingerprintArguments = $this->getFixtureFingerprintArguments($arguments);
         $fixture = new FileFixture($this->_fixturePath . FileFixture::getFilename($this->getFixturePrefix() . '_' . $functionName, $fingerprintArguments));
         // Try to find existing fixture file
         try {
             $fixture->find();
             $result = $fixture->getResult();
             // Throw exception or return value?
             if (is_object($result) && $result instanceof \Exception) {
                 throw $result;
             }
             $resultArguments = $fixture->getArguments();
             return $result;
         } catch (FixtureNotFoundException $e) {
             // No fixture found, the original method has to be called
         }
     }
     if ($this->fixtureOfflineModeEnabled()) {
         throw new OfflineException('Can not create fixture for ' . $functionName . '() in offline mode');
     }
     $throwException = false;
     // Catch exceptions to be able to create fixtures for them as well
     try {
         $result = call_user_func_array(array($this->_fixtureInstance, $functionName), $arguments);
     } catch (\Exception $e) {
         $result = $e;
         $throwException = true;
     }
     // Write return value / exception to file fixture
     if ($this->usesFixtures()) {
         $resultArguments = $arguments;
         $fixture->setResult($result);
         $fixture->setArguments($arguments);
         $fixture->save();
     }
     // Throw exception or return value?
     if ($throwException) {
         throw $result;
     }
     return $result;
 }