/** * @cover ::__construct */ public function testConstruct() { $processorChain = $this->prophesize('Hautelook\\AliceBundle\\Alice\\ProcessorChain'); $processorChain->getProcessors()->willReturn(['dummyProcessor']); $providerChain = $this->prophesize('Hautelook\\AliceBundle\\Faker\\Provider\\ProviderChain'); $providerChain->getProviders()->willReturn(['dummyProvider']); $loader = new Loader($processorChain->reveal(), $providerChain->reveal(), 'en', 10, false); $this->assertEquals(['dummyProcessor'], $loader->getProcessors()); $this->assertEquals(['providers' => ['dummyProvider'], 'locale' => 'en', 'seed' => 10, 'persist_once' => false], $loader->getOptions()); $this->assertEquals(4, count($loader->getOptions())); $this->assertEquals(['dummyProvider'], $loader->getOptions()['providers']); $this->assertEquals('en', $loader->getOptions()['locale']); $this->assertEquals(10, $loader->getOptions()['seed']); $this->assertFalse($loader->getOptions()['persist_once']); $logger = $this->prophesize('Psr\\Log\\LoggerInterface')->reveal(); $loader = new Loader($processorChain->reveal(), $providerChain->reveal(), 'en', 10, false, $logger); $this->assertEquals(['dummyProcessor'], $loader->getProcessors()); $this->assertEquals(['providers' => ['dummyProvider'], 'locale' => 'en', 'seed' => 10, 'persist_once' => false, 'logger' => $logger], $loader->getOptions()); }
/** * @covers ::load() * @covers ::registerErrorMessage() */ public function testLoaderLimitWithMessages() { $this->setExpectedException('\\Hautelook\\AliceBundle\\Alice\\DataFixtures\\LoadingLimitException', 'Loading files limit of 3 reached. Could not load the following files:' . PHP_EOL . 'another/file:' . PHP_EOL . ' - That is a failed' . PHP_EOL . 'empty/message' . PHP_EOL . 'random/file:' . PHP_EOL . ' - Some dummy message'); $persisterProphecy = $this->prophesize('Nelmio\\Alice\\PersisterInterface'); $persisterProphecy->persist()->shouldNotBeCalled(); $fixturesLoaderProphecy = $this->prophesize('Hautelook\\AliceBundle\\Alice\\DataFixtures\\Fixtures\\LoaderInterface'); $fixturesLoaderProphecy->load('random/file', [])->willThrow(new \UnexpectedValueException('Some dummy message')); $fixturesLoaderProphecy->load('another/file', [])->willThrow(new \UnexpectedValueException('That is a failed')); $fixturesLoaderProphecy->load('empty/message', [])->willThrow(new \UnexpectedValueException()); $loader = new Loader($fixturesLoaderProphecy->reveal(), new ProcessorChain([]), false, 3); $loader->load($persisterProphecy->reveal(), ['random/file', 'another/file', 'empty/message']); }
/** * @expectedException \Hautelook\AliceBundle\Alice\DataFixtures\LoadingLimitException */ public function testLoaderWithCustomLimit() { $persisterProphecy = $this->prophesize('Nelmio\\Alice\\PersisterInterface'); $persisterProphecy->persist()->shouldNotBeCalled(); $fixturesLoaderProphecy = $this->prophesize('Hautelook\\AliceBundle\\Alice\\DataFixtures\\Fixtures\\LoaderInterface'); $fixturesLoaderProphecy->load('random/file', [])->willThrow(new \UnexpectedValueException()); $fixturesLoaderProphecy->load('random/file', [])->shouldBeCalledTimes(11); $loader = new Loader($fixturesLoaderProphecy->reveal(), [], false); $loader->setLoadingLimit(10); $loader->load($persisterProphecy->reveal(), ['random/file']); }
public function testLoaderInterface() { $object = new \stdClass(); $persisterProphecy = $this->prophesize('Nelmio\\Alice\\PersisterInterface'); $persisterProphecy->persist([$object])->shouldBeCalled(); $fixturesLoaderProphecy = $this->prophesize('Hautelook\\AliceBundle\\Alice\\DataFixtures\\Fixtures\\LoaderInterface'); $fixturesLoaderProphecy->load('random/file')->willReturn([$object]); $loader = new Loader($fixturesLoaderProphecy->reveal(), [], false); $objects = $loader->load($persisterProphecy->reveal(), ['random/file']); $this->assertEquals([$object], $objects); }