Ejemplo n.º 1
0
    public function testXmlLoad()
    {
        $fixtures = <<<XML
<Fixtures>
    <BookAuthor Namespace="Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader">
        <BookAuthor_1 id="1" name="A famous one" />
    </BookAuthor>
    <Book Namespace="Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader">
        <Book_1 id="1" name="An important one" author_id="BookAuthor_1" />
    </Book>
</Fixtures>
XML;
        $filename = $this->getTempFile($fixtures);
        $loader = new XmlDataLoader(__DIR__ . '/../../Fixtures/DataFixtures/Loader');
        $loader->load(array($filename), 'default');
        $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
        $this->assertCount(1, $books);
        $book = $books[0];
        $this->assertInstanceOf('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor', $book->getBookAuthor());
    }
Ejemplo n.º 2
0
 public function testWipesExistingData()
 {
     $author = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthor();
     $author->setName('Some famous author');
     $book = new \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\Book();
     $book->setName('Armageddon is near')->setBookAuthor($author)->save($this->con);
     $savedBook = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelectOne(new \Criteria(), $this->con);
     $this->assertInstanceOf('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book', $savedBook, 'The fixture has been saved correctly.');
     $builder = $this->getMockBuilder('Propel\\PropelBundle\\DataFixtures\\Loader\\DataWiper');
     $wipeout = $builder->setMethods(array('loadMapBuilders'))->disableOriginalConstructor()->getMock();
     $dbMap = new \DatabaseMap('default');
     $dbMap->addTableFromMapClass('Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\map\\BookTableMap');
     $reflection = new \ReflectionObject($wipeout);
     $property = $reflection->getProperty('dbMap');
     $property->setAccessible(true);
     $property->setValue($wipeout, $dbMap);
     $wipeout->expects($this->once())->method('loadMapBuilders');
     $wipeout->load(array(), 'default');
     $this->assertCount(0, \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con));
 }
Ejemplo n.º 3
0
    public function testLoadSelfReferencing()
    {
        $fixtures = <<<YAML
Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\BookAuthor:
    BookAuthor_1:
        id: '1'
        name: 'to be announced'
    BookAuthor_2:
        id: BookAuthor_1
        name: 'A famous one'

YAML;
        $filename = $this->getTempFile($fixtures);
        $loader = new YamlDataLoader(__DIR__ . '/../../Fixtures/DataFixtures/Loader');
        $loader->load(array($filename), 'default');
        $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
        $this->assertCount(0, $books);
        $authors = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookAuthorPeer::doSelect(new \Criteria(), $this->con);
        $this->assertCount(1, $authors);
        $author = $authors[0];
        $this->assertEquals('A famous one', $author->getName());
    }
    public function testLoadWithFaker()
    {
        if (!class_exists('Faker\\Factory')) {
            $this->markTestSkipped('Faker is mandatory');
        }
        $fixtures = <<<YAML
Propel\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\Book:
    Book_1:
        id: '1'
        name: <?php \$faker('word'); ?>
        description: <?php \$faker('sentence'); ?>

YAML;
        $filename = $this->getTempFile($fixtures);
        $container = $this->getContainer();
        $container->set('faker.generator', \Faker\Factory::create());
        $loader = new YamlDataLoader(__DIR__ . '/../../Fixtures/DataFixtures/Loader', $container);
        $loader->load(array($filename), 'default');
        $books = \Propel\PropelBundle\Tests\Fixtures\DataFixtures\Loader\BookPeer::doSelect(new \Criteria(), $this->con);
        $this->assertCount(1, $books);
        $book = $books[0];
        $this->assertNotNull($book->getName());
        $this->assertNotEquals('null', strtolower($book->getName()));
        $this->assertRegexp('#[a-z]+#', $book->getName());
        $this->assertNotNull($book->getDescription());
        $this->assertNotEquals('null', strtolower($book->getDescription()));
        $this->assertRegexp('#[\\w ]+#', $book->getDescription());
    }