Skip to content

Commit

Permalink
Lithium 0.11 compatibility
Browse files Browse the repository at this point in the history
Also, making the Fixture::file method merge default options
rather than require redefining all options.
  • Loading branch information
rmarscher committed Nov 1, 2012
1 parent 19f68e0 commit 78430e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 40 deletions.
18 changes: 8 additions & 10 deletions test/Fixture.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Fixture extends \lithium\core\Adaptable {


/** /**
* A list of common classes to wrap your fixture data. * A list of common classes to wrap your fixture data.
* *
* @var array * @var array
*/ */
protected static $_classes = array( protected static $_classes = array(
Expand All @@ -92,7 +92,7 @@ class Fixture extends \lithium\core\Adaptable {
* @param string $name Class name of adapter to load. * @param string $name Class name of adapter to load.
* @return object Adapter object. * @return object Adapter object.
*/ */
public static function adapter($name = null) { public static function adapter($name = 'default') {
if (!isset(static::$_configurations[$name])) { if (!isset(static::$_configurations[$name])) {
$config = array( $config = array(
'adapter' => strpos($name, '\\') === false ? ucfirst($name) : $name 'adapter' => strpos($name, '\\') === false ? ucfirst($name) : $name
Expand Down Expand Up @@ -120,7 +120,7 @@ public static function adapter($name = null) {
* @param array $options Additional options can be specified here. Possible options are: * @param array $options Additional options can be specified here. Possible options are:
* - `adapter`: the adapter to use to load the fixture * - `adapter`: the adapter to use to load the fixture
* - `class` : a class to wrap the data in * - `class` : a class to wrap the data in
* - `library` : look for the fixtures in a different library * - `library` : look for the fixtures in a different library
* - `path` : String-insert style file path * - `path` : String-insert style file path
* - `sources`: add more parsing sources. Out of the box Json is used. * - `sources`: add more parsing sources. Out of the box Json is used.
* @return array|object The array of data, optionally wrapped in a class such as * @return array|object The array of data, optionally wrapped in a class such as
Expand Down Expand Up @@ -161,16 +161,16 @@ public static function load($file, array $options = array()) {
* *
* @param string $file The name of the file. It will be lowercased and slugified * @param string $file The name of the file. It will be lowercased and slugified
* by the inflector. Directory separators will be preserved. * by the inflector. Directory separators will be preserved.
* @param object|array $data If an instance of a Collection, data will * @param object|array $data If an instance of a Collection, data will
* @param array $options Additional options can be specified here. Possible options are: * @param array $options Additional options can be specified here. Possible options are:
* - `adapter`: the adapter to use to load the fixture * - `adapter`: the adapter to use to load the fixture
* - `cast` : set to false to prevent `Collection` being converted to arrays. * - `cast` : set to false to prevent `Collection` being converted to arrays.
* - `library` : save the fixtures in a different library * - `library` : save the fixtures in a different library
* - `path`: can be an absolute or relative path to the fixture file. * - `path`: can be an absolute or relative path to the fixture file.
* @return boolean Returns whether the file saving was successful or not. * @return boolean Returns whether the file saving was successful or not.
*/ */
public static function save($file, $data, array $options = array()) { public static function save($file, $data, array $options = array()) {
$options = $options + static::$_defaults; $options += static::$_defaults;


$options['adapter'] = $adapter = static::adapter($options['adapter']); $options['adapter'] = $adapter = static::adapter($options['adapter']);
$file = static::file($file, $options); $file = static::file($file, $options);
Expand Down Expand Up @@ -203,10 +203,8 @@ public static function save($file, $data, array $options = array()) {
* @see li3_fixtures\test\Fixture::load() * @see li3_fixtures\test\Fixture::load()
*/ */
public static function file($file, array $options = array()) { public static function file($file, array $options = array()) {
if (empty($options)) { $options += static::$_defaults;
$options = static::$_defaults; if (isset($options['adapter']) && !is_object($options['adapter'])) {
}
if (!isset($options['adapter']) || !is_object($options['adapter'])) {
$options['adapter'] = static::adapter($options['adapter']); $options['adapter'] = static::adapter($options['adapter']);
} }
$adapter = $options['adapter']; $adapter = $options['adapter'];
Expand Down
41 changes: 11 additions & 30 deletions tests/cases/test/FixtureTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ public function testLoadWithDocumentSet() {
$this->_testLoad($posts); $this->_testLoad($posts);
} }


/**
* Also test with DocumentArray instead of Collection.
*/
public function testLoadWithDocumentArray() {
$options = $this->_loadOptions;
$options['collection'] = 'DocumentArray';
$posts = Fixture::load('models/Posts', $options);
$this->_testLoad($posts);
}

/** /**
* Also test with RecordSet instead of Collection. * Also test with RecordSet instead of Collection.
* *
Expand Down Expand Up @@ -171,44 +161,35 @@ protected function _testLoad($posts) {
*/ */
public function testLoadResultClass() { public function testLoadResultClass() {
$options = array( $options = array(
'path' => dirname(dirname(__DIR__)).'/fixtures' 'library' => 'li3_fixtures'
); );
$ships = Fixture::load('Pirate', $options); $ships = Fixture::load('models/Pirates', $options);
$expected = 'lithium\util\Collection'; $expected = 'lithium\util\Collection';
$this->assertEqual($expected, get_class($ships)); $this->assertEqual($expected, get_class($ships));


$options = array( $options = array(
'path' => dirname(dirname(__DIR__)).'/fixtures', 'collection' => 'Collection',
'collection' => 'Collection' 'library' => 'li3_fixtures'
); );
$ships = Fixture::load('Pirate', $options); $ships = Fixture::load('models/Pirates', $options);
$expected = 'lithium\util\Collection'; $expected = 'lithium\util\Collection';
$this->assertEqual($expected, get_class($ships)); $this->assertEqual($expected, get_class($ships));


$options = array( $options = array(
'path' => dirname(dirname(__DIR__)).'/fixtures', 'collection' => 'DocumentSet',
'collection' => 'DocumentSet' 'library' => 'li3_fixtures'
); );
$ships = Fixture::load('Pirate', $options); $ships = Fixture::load('models/Pirates', $options);
$expected = 'lithium\data\collection\DocumentSet'; $expected = 'lithium\data\collection\DocumentSet';
$this->assertEqual($expected, get_class($ships)); $this->assertEqual($expected, get_class($ships));


$options = array( $options = array(
'path' => dirname(dirname(__DIR__)).'/fixtures', 'collection' => 'RecordSet',
'collection' => 'DocumentArray' 'library' => 'li3_fixtures'
);
$ships = Fixture::load('Pirate', $options);
$expected = 'lithium\data\collection\DocumentArray';
$this->assertEqual($expected, get_class($ships));

$options = array(
'path' => dirname(dirname(__DIR__)).'/fixtures',
'collection' => 'RecordSet'
); );
$ships = Fixture::load('Pirate', $options); $ships = Fixture::load('models/Pirates', $options);
$expected = 'lithium\data\collection\RecordSet'; $expected = 'lithium\data\collection\RecordSet';
$this->assertEqual($expected, get_class($ships)); $this->assertEqual($expected, get_class($ships));

} }
} }


Expand Down

0 comments on commit 78430e6

Please sign in to comment.