Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Array unit tests #873

Merged
merged 8 commits into from

3 participants

@devsmt

fixed and tested 2 simple edge cases in core array functions (sorry people, this is my first pull request!)

tests/arr.php
@@ -492,6 +492,13 @@ public function test_sort_invalid_direction($data, $expected)
$this->assertEquals(Arr::sort($data, 'info.pet.type', 'downer'), $expected);
}
+ public function test_sort_empty()
+ {
+ $expected = array();
+ $output = Arr::Sort(array(), 'test', 'test');

This should be lowercase 'sort'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
devsmt added some commits
@devsmt devsmt handle empty input array in Arr::sort() e4327e5
@devsmt devsmt conflict resolved 9e10903
@devsmt devsmt Merge branch '1.1/develop' of github.com:devsmt/core into 1.1/develop
* '1.1/develop' of github.com:devsmt/core:
  handle empty input array in Arr::sort()

Conflicts:
	tests/arr.php
2cd0488
@devsmt devsmt Merge remote-tracking branch 'fuel-core/1.1/develop' into 1.1/develop
* fuel-core/1.1/develop:
  fixed a Migration flow error and a notice...
  added individual migration tracking to Migrations. Closes #843
  fixed loading config files by FQFN. Closes #825
  Changed if statement and added exception for invalid input to bring inline with coding standards.
  Fixed backslash issue in asset paths on Windows
  Added layout template and partial support to Theme
  Added ability to add and drop foreign keys after a table has been created
571100a
@devsmt

resolved

tests/arr.php
@@ -492,6 +492,17 @@ public function test_sort_invalid_direction($data, $expected)
$this->assertEquals(Arr::sort($data, 'info.pet.type', 'downer'), $expected);
}
+ public function test_sort_empty()
+ {
+ $expected = array();
+<<<<<<< HEAD
+ $output = Arr::sort(array(), 'test', 'test');
+=======
+ $output = Arr::Sort(array(), 'test', 'test');
+>>>>>>> 85988a20a4cdc8acfaa251be68aac253939f0aed

oops? :P

@devsmt
devsmt added a note

yes... any suggestion to clean it up?

It's a Git merge conflict, you need to decide which to use... (the lowercase one obviously)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
classes/arr.php
@@ -481,6 +481,11 @@ public static function sort($array, $key, $order = 'asc', $sort_flags = SORT_REG
throw new \InvalidArgumentException('Arr::sort() - $array must be an array.');
}
+ if( empty($array) )

small style fix -> if (empty))
The rest seems to be correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/format.php
@@ -151,4 +151,10 @@ public function test__from_xml()
$this->assertEquals(Format::forge($expected)->to_php(), Format::forge($xml, 'xml')->to_php());
}
+
+ function test_to_array_empty(){

and the opening bracket needs to be on a new line

@devsmt
devsmt added a note

do you use an automated tool to enforce formatting? any help with formatting issues will benefit the project of more occasional contributions from casual users used to different conventions (like me...)

I don't maybe others do. But it's just following our style guide: http://docs.fuelphp.com/general/coding_standards.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@frankdejonge frankdejonge merged commit 85c2140 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 15, 2012
  1. @devsmt
  2. @devsmt
Commits on Mar 16, 2012
  1. @devsmt
  2. @devsmt

    conflict resolved

    devsmt authored
Commits on Mar 17, 2012
  1. @devsmt

    Merge branch '1.1/develop' of github.com:devsmt/core into 1.1/develop

    devsmt authored
    * '1.1/develop' of github.com:devsmt/core:
      handle empty input array in Arr::sort()
    
    Conflicts:
    	tests/arr.php
  2. @devsmt

    Merge remote-tracking branch 'fuel-core/1.1/develop' into 1.1/develop

    devsmt authored
    * fuel-core/1.1/develop:
      fixed a Migration flow error and a notice...
      added individual migration tracking to Migrations. Closes #843
      fixed loading config files by FQFN. Closes #825
      Changed if statement and added exception for invalid input to bring inline with coding standards.
      Fixed backslash issue in asset paths on Windows
      Added layout template and partial support to Theme
      Added ability to add and drop foreign keys after a table has been created
Commits on Mar 18, 2012
  1. @devsmt

    corrected merge error

    devsmt authored
Commits on Mar 22, 2012
  1. @devsmt

    style fixes

    devsmt authored
This page is out of date. Refresh to see the latest.
View
5 classes/arr.php
@@ -481,6 +481,11 @@ public static function sort($array, $key, $order = 'asc', $sort_flags = SORT_REG
throw new \InvalidArgumentException('Arr::sort() - $array must be an array.');
}
+ if (empty($array))
+ {
+ return $array;
+ }
+
foreach ($array as $k=>$v)
{
$b[$k] = static::get($v, $key);
View
5 classes/format.php
@@ -102,6 +102,11 @@ public function to_array($data = null)
$data = get_object_vars($data);
}
+ if (empty($data))
+ {
+ return array();
+ }
+
foreach ($data as $key => $value)
{
if (is_object($value) or is_array($value))
View
7 tests/arr.php
@@ -492,6 +492,13 @@ public function test_sort_invalid_direction($data, $expected)
$this->assertEquals(Arr::sort($data, 'info.pet.type', 'downer'), $expected);
}
+ public function test_sort_empty()
+ {
+ $expected = array();
+ $output = Arr::sort(array(), 'test', 'test');
+ $this->assertEquals($expected, $output);
+ }
+
/**
* Tests Arr::filter_keys()
*
View
7 tests/format.php
@@ -151,4 +151,11 @@ public function test__from_xml()
$this->assertEquals(Format::forge($expected)->to_php(), Format::forge($xml, 'xml')->to_php());
}
+
+ function test_to_array_empty()
+ {
+ $array = null;
+ $expected = array();
+ $this->assertEquals($expected, Format::forge($array)->to_array());
+ }
}
Something went wrong with that request. Please try again.