public function onStart() { $textLoader = new CacheLoader(new TextLoader()); $mustacheLoader = new MustacheLoader($textLoader); $artLoader = new ArtLoader($mustacheLoader); $loaders = new LoaderContainer([$textLoader, $mustacheLoader, $artLoader]); $factory = new FixtureContainerFactory(); $fixtures = $factory->createFromFile($this->configFile); $fixture = new FileFixture($fixtures, $loaders); $this->scope = new FileFixtureScope($fixture); return $this; }
context('when file exists', function () { beforeEach(function () { $this->container = $this->factory->createFromFile(__DIR__ . '/../fixtures/config.toml'); }); it('return FixtureContainer', function () { expect($this->container)->toBeAnInstanceOf(FixtureContainer::class); expect($this->container->get('static:loader:default:success'))->toEndWith('static.txt'); expect($this->container->get('static:loader:default:failure'))->toEndWith('static.txt'); }); }); context('when file not exists', function () { it('throw ConfigFileNotFoundException', function () { expect(function () { $this->factory->createFromFile(__DIR__ . '/not_found_config.toml'); })->toThrow(ConfigFileNotFoundException::class); }); }); }); describe('#createFromArray', function () { beforeEach(function () { $values = ['static' => ['loader' => ['default' => ['ok' => '/path/to/file.php', 'ng' => '/path/to/file.php']], 'compiler' => ['default' => ['ok' => '/path/to/file.php', 'ng' => '/path/to/file.php']]]]; $factory = new FixtureContainerFactory(); $this->container = $factory->createFromArray($values); }); it('return FixtureContainer', function () { expect($this->container)->toBeAnInstanceOf(FixtureContainer::class); expect($this->container->get('static:loader:default:ok'))->toEqual('/path/to/file.php'); expect($this->container->get('static:loader:default:ng'))->toEqual('/path/to/file.php'); }); }); });
<?php require_once __DIR__ . '/../vendor/autoload.php'; use holyshared\fixture\FileFixture; use holyshared\fixture\loader\TextLoader; use holyshared\fixture\loader\MustacheLoader; use holyshared\fixture\container\LoaderContainer; use holyshared\fixture\container\FixtureContainer; use holyshared\fixture\factory\FixtureContainerFactory; $textLoader = new TextLoader(); $loaders = new LoaderContainer([$textLoader, new MustacheLoader($textLoader)]); $factory = new FixtureContainerFactory(); $fixtures = $factory->createFromFile(__DIR__ . '/fixtures.toml'); $fixture = new FileFixture($fixtures, $loaders); $content = $fixture->load('mustache:default:successMessage', ['name' => 'build']); print $content;