/** * Load fixture(s) data into the database. * * <code> * <?php * ... * // single * $this->fixtures('briefcases'); * * // multiple * $this->fixtures(array('briefcases', 'md_metadata')); * * // 'only' for given test methods * $this->fixtures('briefcases', array('only' => array('testMethod1', 'testMethod2'))); * * // all test methods 'except' given * $this->fixtures('briefcases', array('except' => array('testMethod1', 'testMethod2'))); * ... * ?> * </code> * * @param string|array $ymlFiles * @param array $options */ public function fixtures($args) { $ymlFiles = func_get_args(); $last = end($ymlFiles); $options = is_array($last) ? array_pop($ymlFiles) : array(); // don't load fixtures for these methods if (isset($options['except'])) { if (in_array($this->getName(), $options['except'])) { return; } } // only load fixtures for these methods if (isset($options['only'])) { if (!in_array($this->getName(), $options['only'])) { return; } } // Add fixtures to the existing fixtures when called more than once if (empty($this->_fixtures)) { $this->_fixtures = new Mad_Test_Fixture_Collection($this->_conn, $ymlFiles); } else { $this->_fixtures->addFixture($ymlFiles); } // Build models from fixture records foreach ($this->_fixtures->getFixtures() as $fixture) { $name = $fixture->getYmlName(); if (isset($this->_fixtureClassNames[$name])) { $class = $this->_fixtureClassNames[$name]; } else { $table = $fixture->getTableName(); $class = Mad_Support_Inflector::classify($table); } // skip building model if class doesn't exist if (!Mad_Support_Base::modelExists($class)) { break; } $model = new $class(); $this->_records[$name] = array(); foreach ($fixture->getRecords() as $recordName => $attrs) { $this->_records[$name][$recordName] = $model->instantiate($attrs); } } // @deprecated - assign public properties based on fixture names foreach ($this->_fixtures->getRecords() as $recordName => $values) { if (isset($this->{$recordName})) { $this->{$recordName} = array_merge($this->{$recordName}, $values); } else { $this->{$recordName} = $values; } // make all values strings foreach ($this->{$recordName} as &$value) { $value = (string) $value; } } }
public function testGetRecords() { $fixtures = new Mad_Test_Fixture_Collection($this->_conn, 'unit_tests_more'); $this->assertEquals(11, count($fixtures->getRecords())); }