Permalink
Browse files

Merge pull request #9 from Affinitive/master

Lithium 0.11 compatibility
  • Loading branch information...
2 parents 19f68e0 + 78430e6 commit 4b1243dd1cea07a8d89a5a6af828e19b30c6a4ab @daschl committed Nov 6, 2012
Showing with 19 additions and 40 deletions.
  1. +8 −10 test/Fixture.php
  2. +11 −30 tests/cases/test/FixtureTest.php
View
18 test/Fixture.php
@@ -76,7 +76,7 @@ class Fixture extends \lithium\core\Adaptable {
/**
* A list of common classes to wrap your fixture data.
- *
+ *
* @var array
*/
protected static $_classes = array(
@@ -92,7 +92,7 @@ class Fixture extends \lithium\core\Adaptable {
* @param string $name Class name of adapter to load.
* @return object Adapter object.
*/
- public static function adapter($name = null) {
+ public static function adapter($name = 'default') {
if (!isset(static::$_configurations[$name])) {
$config = array(
'adapter' => strpos($name, '\\') === false ? ucfirst($name) : $name
@@ -120,7 +120,7 @@ public static function adapter($name = null) {
* @param array $options Additional options can be specified here. Possible options are:
* - `adapter`: the adapter to use to load the fixture
* - `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
* - `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
@@ -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
* 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:
* - `adapter`: the adapter to use to load the fixture
* - `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.
* @return boolean Returns whether the file saving was successful or not.
*/
public static function save($file, $data, array $options = array()) {
- $options = $options + static::$_defaults;
+ $options += static::$_defaults;
$options['adapter'] = $adapter = static::adapter($options['adapter']);
$file = static::file($file, $options);
@@ -203,10 +203,8 @@ public static function save($file, $data, array $options = array()) {
* @see li3_fixtures\test\Fixture::load()
*/
public static function file($file, array $options = array()) {
- if (empty($options)) {
- $options = static::$_defaults;
- }
- if (!isset($options['adapter']) || !is_object($options['adapter'])) {
+ $options += static::$_defaults;
+ if (isset($options['adapter']) && !is_object($options['adapter'])) {
$options['adapter'] = static::adapter($options['adapter']);
}
$adapter = $options['adapter'];
View
41 tests/cases/test/FixtureTest.php
@@ -66,16 +66,6 @@ public function testLoadWithDocumentSet() {
}
/**
- * 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.
*
*/
@@ -171,44 +161,35 @@ protected function _testLoad($posts) {
*/
public function testLoadResultClass() {
$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';
$this->assertEqual($expected, get_class($ships));
$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';
$this->assertEqual($expected, get_class($ships));
$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';
$this->assertEqual($expected, get_class($ships));
$options = array(
- 'path' => dirname(dirname(__DIR__)).'/fixtures',
- 'collection' => 'DocumentArray'
- );
- $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'
+ 'collection' => 'RecordSet',
+ 'library' => 'li3_fixtures'
);
- $ships = Fixture::load('Pirate', $options);
+ $ships = Fixture::load('models/Pirates', $options);
$expected = 'lithium\data\collection\RecordSet';
$this->assertEqual($expected, get_class($ships));
-
}
}

0 comments on commit 4b1243d

Please sign in to comment.