Refactored Unit_test in order to remove redundant code. #1962

Merged
merged 1 commit into from Nov 4, 2012

Conversation

Projects
None yet
2 participants
Contributor

squaresurf commented Nov 3, 2012

The Unit_test::run method was adding another dimension to the
Unit_test::$results array. For example:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [test_name] => first_test
                    [test_datatype] => integer
                    [res_datatype] => integer
                    [result] => passed
                    [file] => ########################################
                    [line] => 60
                    [notes] => Im expecting this test to pass!
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [test_name] => second_test
                    [test_datatype] => integer
                    [res_datatype] => boolean
                    [result] => failed
                    [file] => #######################################
                    [line] => 65
                    [notes] => Im expecting this to fail.
                )

        )

)

The above unneeded dimension created a need to loop through an array in the
Unit_test::result method if the method was looping through all results.

Signed-off-by: Daniel Paul Searles daniel.paul.searles@gmail.com

Refactored Unit_test in order to remove redundant code.
The Unit_test::run method was adding another dimension to the
Unit_test::$results array. For example:

Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [test_name] => first_test
                    [test_datatype] => integer
                    [res_datatype] => integer
                    [result] => passed
                    [file] => ########################################
                    [line] => 60
                    [notes] => Im expecting this test to pass!
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [test_name] => second_test
                    [test_datatype] => integer
                    [res_datatype] => boolean
                    [result] => failed
                    [file] => #######################################
                    [line] => 65
                    [notes] => Im expecting this to fail.
                )

        )

)

The above unneeded dimension created a need to loop through an array in the
Unit_test::result method if the method was looping through all results.

Signed-off-by: Daniel Paul Searles <daniel.paul.searles@gmail.com>
{
- foreach ($val as $k => $v)
- {
- if ( ! in_array($k, $this->_test_items_visible))
@narfbg

narfbg Nov 3, 2012

Contributor

You need to preserve this check.

@squaresurf

squaresurf Nov 3, 2012

Contributor

There is no need for that check, because that foreach shouldn't ever be entered. The results array will only ever be two dimensions deep.

@narfbg

narfbg Nov 3, 2012

Contributor

I'm not saying that it should be in the same dimension/level, you can do the following, prior to line 287:

if ( ! in_array($val, $this->_test_items_visible))
{
    continue;
}

The Unit_test class provides a way to set which items should be visible in the report and with that check removed - you're removing that functionality.

@squaresurf

squaresurf Nov 3, 2012

Contributor

That check does still exist above my diff. I only removed the redundant check. The fact that the Unit_test::set_test_items method feature does not work with the Unit_test::results method in the latest stable version of CI led me to this fix.

narfbg added a commit that referenced this pull request Nov 4, 2012

Merge pull request #1962 from squaresurf/d2ae1d1d7fdc4b8a21369a25487c…
…2c42e5a496bf

Refactored Unit_test in order to remove redundant code.

@narfbg narfbg merged commit b1b1528 into bcit-ci:develop Nov 4, 2012

1 check passed

default The Travis build passed
Details

nonchip pushed a commit to nonchip/CodeIgniter that referenced this pull request Jun 29, 2013

Merge pull request #1962 from squaresurf/d2ae1d1d7fdc4b8a21369a25487c…
…2c42e5a496bf

Refactored Unit_test in order to remove redundant code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment