Ejemplo n.º 1
0
    public function testXmlLoad()
    {
        $fixtures = <<<XML
<Fixtures>
    <CoolBookAuthor Namespace="Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader">
        <CoolBookAuthor_1 id="1" name="A famous one" />
    </CoolBookAuthor>
    <CoolBook Namespace="Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader">
        <CoolBook_1 id="1" name="An important one" author_id="CoolBookAuthor_1" />
    </CoolBook>
</Fixtures>
XML;
        $filename = $this->getTempFile($fixtures);
        $loader = new XmlDataLoader(__DIR__ . '/../../Fixtures/DataFixtures/Loader', array());
        $loader->load(array($filename), 'default');
        $books = \Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($this->con);
        $this->assertCount(1, $books);
        $book = $books[0];
        $this->assertInstanceOf('Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\CoolBookAuthor', $book->getCoolBookAuthor());
    }
Ejemplo n.º 2
0
    public function testLoadWithFaker()
    {
        if (!class_exists('Faker\\Factory')) {
            $this->markTestSkipped('Faker is mandatory');
        }
        $fixtures = <<<YAML
Propel\\Bundle\\PropelBundle\\Tests\\Fixtures\\DataFixtures\\Loader\\CoolBook:
    CoolBook_1:
        id: '1'
        name: <?php \$faker('word'); ?>
        description: <?php \$faker('sentence'); ?>

YAML;
        $filename = $this->getTempFile($fixtures);
        $loader = new YamlDataLoader(__DIR__ . '/../../Fixtures/DataFixtures/Loader', array(), \Faker\Factory::create());
        $loader->load(array($filename), 'default');
        $books = \Propel\Bundle\PropelBundle\Tests\Fixtures\DataFixtures\Loader\CoolBookQuery::create()->find($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());
    }