public function testGetFilename() { $this->assertEquals('foo_barbaz.fix', FileFixture::getFilename('foo_bar.baz&*()')); $this->assertEquals('foo_barbaz.array_a_b.fix', FileFixture::getFilename('foo_bar.baz&*()', array('a' => 'b'))); $this->assertEquals('foo.bar.fix', FileFixture::getFilename('foo!', 'bar')); $this->assertEquals('foo.fix', FileFixture::getFilename('foo')); $this->assertEquals('GoOo.b7f3e6756b2ca19c4b06f5e95061e342.fix', FileFixture::getFilename('GoOo', 'e5v8snjpv0pjsev4fjp0ws4tfghsge;]-c3seecfjhisfhijjijkjmcs8jvn')); }
/** * 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; }