public function testClear()
 {
     $factory = new FixtureFactory();
     $obj1Id = $factory->createRaw('FixtureFactoryTest_DataObject', 'one', array('Name' => 'My Name'));
     $obj2 = $factory->createObject('FixtureFactoryTest_DataObject', 'two');
     $factory->clear();
     $this->assertFalse($factory->getId('FixtureFactoryTest_DataObject', 'one'));
     $this->assertNull(FixtureFactoryTest_DataObject::get()->byId($obj1Id));
     $this->assertFalse($factory->getId('FixtureFactoryTest_DataObject', 'two'));
     $this->assertNull(FixtureFactoryTest_DataObject::get()->byId($obj2->ID));
 }
Beispiel #2
0
 /**
  * Persists the YAML data in a FixtureFactory,
  * which in turn saves them into the database.
  * Please use the passed in factory to access the fixtures afterwards.
  * 
  * @param  FixtureFactory $factory
  */
 public function writeInto(FixtureFactory $factory)
 {
     $parser = new Spyc();
     if (isset($this->fixtureString)) {
         $fixtureContent = $parser->load($this->fixtureString);
     } else {
         $fixtureContent = $parser->loadFile($this->fixtureFile);
     }
     foreach ($fixtureContent as $class => $items) {
         foreach ($items as $identifier => $data) {
             if (ClassInfo::exists($class)) {
                 $factory->createObject($class, $identifier, $data);
             } else {
                 $factory->createRaw($class, $identifier, $data);
             }
         }
     }
 }
 /**
  * Persists the YAML data in a FixtureFactory,
  * which in turn saves them into the database.
  * Please use the passed in factory to access the fixtures afterwards.
  *
  * @param  FixtureFactory $factory
  */
 public function writeInto(FixtureFactory $factory)
 {
     $parser = new Parser();
     if (isset($this->fixtureString)) {
         $fixtureContent = $parser->parse($this->fixtureString);
     } else {
         if (!file_exists($this->fixtureFile)) {
             return;
         }
         $contents = file_get_contents($this->fixtureFile);
         $fixtureContent = $parser->parse($contents);
         if (!$fixtureContent) {
             return;
         }
     }
     foreach ($fixtureContent as $class => $items) {
         foreach ($items as $identifier => $data) {
             if (ClassInfo::exists($class)) {
                 $factory->createObject($class, $identifier, $data);
             } else {
                 $factory->createRaw($class, $identifier, $data);
             }
         }
     }
 }