From ec2530ba58b88db75224aeb65a5b0f40947ece31 Mon Sep 17 00:00:00 2001 From: tranfuga25s Date: Fri, 5 Dec 2014 16:01:49 -0300 Subject: [PATCH] Fix PHPCS problems and a better comparation of schema and data --- .../TestSuite/Fixture/CakeTestFixture.php | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php index 4cad64c00..ca7363641 100644 --- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php +++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php @@ -287,25 +287,29 @@ class CakeTestFixture { $fields = array_unique($fields); $default = array_fill_keys($fields, null); foreach ($this->records as $record) { - $merge_data = array_merge( $default, $record ); - $merge = array_values( $merge_data ); + $mergeData = array_merge( $default, $record ); + $merge = array_values( $mergeData ); if (count($fields) !== count($merge)) { - $merge_fields = array_keys( $merge_data ); - $remove = array(); - - foreach( $fields as $f ) { - if( in_array( $f, $merge_fields ) ) { - $remove[] = $f; - } - } - $merge_fields = array_diff( $merge_fields, $remove ); - $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; - foreach( $merge_fields as $field ) { - $message .= "The field '".$field."' is not in the fixture used in the schema."."\n"; - } - - throw new CakeException( $message ); + $mergeFields = array_keys( $merge_data ); + $remove = array(); + + foreach ($fields as $k => $f) { + if (in_array( $f, $mergeFields )) { + $remove[] = $f; + unset( $fields[$k] ); + } + } + $mergeFields = array_diff( $mergeFields, $remove ); + $message = 'Fixture invalid: Count of fields does not match count of values in ' . get_class($this)."\n"; + foreach ($mergeFields as $field) { + $message .= "The field '" . $field . "' is in the data fixture but not in the schema." . "\n"; + } + foreach ($fields as $field) { + $message .= "The field '" . $field . "' is in the fixture but not in the data." . "\n"; + } + + throw new CakeException( $message ); } $values[] = $merge; }