diff --git a/src/ArrayHelper.php b/src/ArrayHelper.php index 9c39bf0..444931f 100644 --- a/src/ArrayHelper.php +++ b/src/ArrayHelper.php @@ -2,6 +2,10 @@ namespace adeattwood\helpers; +use Yii; +use adeattwood\helpers\ArrayObject; +use adeattwood\helpers\Enum; + /** * @category PHP * @package adeattwood\yii-helpers @@ -64,10 +68,10 @@ class ArrayHelper extends \yii\helpers\ArrayHelper throw new InvalidConfigException( 'The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"' ); } - $rawValue = ArrayHelper::getValue( $model, $matches[ 1 ] ); + $rawValue = self::getValue( $model, $matches[ 1 ] ); $format = isset( $matches[ 3 ] ) ? $matches[ 3 ] : $defalts[ 'format' ]; - $value = empty( $rawValue ) ? $defalts[ 'value' ] : Yii::$app->formatter->format( $rawValue, $format ); + $value = Enum::isEmpty( $rawValue ) ? $defalts[ 'value' ] : Yii::$app->formatter->format( $rawValue, $format ); $lable = isset( $matches[ 5 ] ) ? $matches[ 5 ] : $model->getAttributeLabel( $matches[ 1 ] ); return new ArrayObject([ diff --git a/tests/unit/ArrayHelperCest.php b/tests/unit/ArrayHelperCest.php index 7a85209..f8695d7 100644 --- a/tests/unit/ArrayHelperCest.php +++ b/tests/unit/ArrayHelperCest.php @@ -1,25 +1,49 @@ assertEquals( $array[ 2 ], 2 ); + $I->assertFalse( isset( $array[ 3 ] ) ); + $I->assertEquals( $array[ 4 ], 4 ); + } + + public function testNumberArrayWithStep( UnitTester $I ) + { + $array = ArrayHelper::numberArray( 10 ); $I->assertEquals( $array[ 0 ], 0 ); $I->assertEquals( $array[ 10 ], 10 ); - $array = ArrayHelper::numberArray( 10, 2, 2 ); - var_dump( $array ); + $I->assertFalse( isset( $array[ 11 ] ) ); + } + + public function testParseAttribute( UnitTester $I ) + { + $model = new ModelOne; + $model->propOne = "test"; + + $data = ArrayHelper::parseAttribute( $model, 'propOne' ); + + $I->assertEquals( $data->format, 'text' ); + + $I->assertEquals( $data->lable, 'Prop One' ); + + $I->assertEquals( $data->value, 'test' ); + $I->assertEquals( $data->raw, 'test' ); } }