* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development:testing:unit_tests Wiki */ namespace VuFind\Marc\Test\Feature; use RuntimeException; /** * Trait adding functionality for loading fixtures. * * @category VuFind * @package Tests * @author Demian Katz * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link https://vufind.org/wiki/development:testing:unit_tests Wiki */ trait FixtureTrait { /** * Get the base directory containing fixtures. * * @return string */ protected function getFixtureDir() { return __DIR__ . '/../fixtures/'; } /** * Resolve fixture path. * * @param string $filename Filename relative to fixture directory. * * @return string * @throws RuntimeException */ protected function getFixturePath($filename) { $realFilename = realpath($this->getFixtureDir() . $filename); if ( !$realFilename || !file_exists($realFilename) || !is_readable($realFilename) ) { throw new RuntimeException( sprintf('Unable to resolve fixture to fixture file: %s', $filename) ); } return $realFilename; } /** * Load a fixture file. * * @param string $filename Filename relative to fixture directory. * * @return string * @throws RuntimeException */ protected function getFixture($filename) { return file_get_contents($this->getFixturePath($filename)); } }