public function setUp()
 {
     parent::setUp();
     $this->kernel = new AppKernel('test', true);
     $this->kernel->boot();
     $dataProvider = new FakerDataProvider();
     $guesser = new DataGuesser($dataProvider);
     $this->generator = new ConfigGenerator($this->em, $guesser, $this->kernel);
 }
 /** @test */
 public function it_generates_config_files()
 {
     $kernel = new AppKernel('test', true);
     $kernel->boot();
     $kernel->getContainer()->set('doctrine.orm.default_entity_manager', $this->em);
     $configGenerator = $kernel->getContainer()->get('factrine.config_provider.config_generator');
     $cmd = $this->getMockBuilder(FactrineGenerateFilesCommand::class)->setConstructorArgs([$configGenerator, $kernel])->setMethods(['getDirectory'])->getMock();
     $root = vfsStream::setup();
     $cmd->method('getDirectory')->willReturn($root->url() . '/factrine/');
     $application = new Application($kernel);
     $application->add($cmd);
     $commandTester = new CommandTester($cmd);
     $commandTester->execute(array('command' => $cmd->getName()));
     $fi = new FilesystemIterator($root->url() . '/factrine', FilesystemIterator::SKIP_DOTS);
     $this->assertEquals(11, iterator_count($fi));
     $this->assertTrue(file_exists($root->url() . '/factrine/Address.yml'));
     $addressConfig = Yaml::parse(file_get_contents($root->url() . '/factrine/Address.yml'));
     $this->assertTrue(key($addressConfig) === Address::class);
     $this->assertTrue(isset($addressConfig[Address::class]['street']));
     $userConfig = Yaml::parse(file_get_contents($root->url() . '/factrine/User.yml'));
     $this->assertTrue(isset($userConfig[User::class]['address']));
     $this->assertEquals(Address::class, $userConfig[User::class]['address']);
 }
示例#3
0
 /** @test */
 public function it_allows_to_set_another_entity_manager()
 {
     $kernel = new AppKernel('test', true);
     $kernel->boot();
     $anotherEntityManager = $kernel->getContainer()->get('doctrine.orm.entity_manager');
     $tool = new SchemaTool($anotherEntityManager);
     $tool->createSchema($anotherEntityManager->getMetadataFactory()->getAllMetadata());
     $this->factory->setEntityManager($anotherEntityManager);
     $address = $this->factory->create(Address::class);
     $this->assertFalse($this->em->contains($address));
     $this->assertTrue($anotherEntityManager->contains($address));
 }