public function testSetArguments() { $object = new NotSerializable(); $result = 123; $arguments = array('bar', $object); $filename = $this->getFixturePath() . '/not_serializable_argument.fix'; $fixture = new FileFixture($filename); $fixture->setArguments($arguments); $fixture->setResult($result); $fixture->save(); $serializedObject = 'Argument could not be serialized: TestTools\\Tests\\Fixture\\NotSerializable Object' . "\n(\n)\n"; $expected = array('bar', $serializedObject); $this->assertEquals($expected, $fixture->getArguments()); }
/** * 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; }