diff --git a/src/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParser.php b/src/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParser.php index 21bd61aa3..21c0fc829 100644 --- a/src/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParser.php +++ b/src/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParser.php @@ -13,6 +13,8 @@ namespace Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\Chainable; +use Nelmio\Alice\Definition\Value\ArrayValue; +use Nelmio\Alice\Definition\ValueInterface; use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\ParserInterface; use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Token; use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\TokenType; @@ -36,7 +38,7 @@ public function canParse(Token $token): bool * * {@inheritdoc} */ - public function parse(Token $token): array + public function parse(Token $token): ValueInterface { parent::parse($token); @@ -44,7 +46,7 @@ public function parse(Token $token): array try { $elements = substr($value, 1, strlen($value) - 2); - return $this->parseElements($this->parser, $elements); + return new ArrayValue($this->parseElements($this->parser, $elements)); } catch (\TypeError $error) { throw ExpressionLanguageExceptionFactory::createForUnparsableToken($token, 0, $error); } diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php index 3e8467c02..3a24df89a 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/ParserIntegrationTest.php @@ -392,7 +392,7 @@ public function provideValues() new FunctionCallValue( 'function', [ - ['foo', 'bar'], + new ArrayValue(['foo', 'bar']), ] ), ]; @@ -607,7 +607,7 @@ public function provideValues() '10x [@user->name, @group->getName()]', new DynamicArrayValue( 10, - [ + new ArrayValue([ new FixturePropertyValue( new FixtureReferenceValue('user'), 'name' @@ -616,7 +616,7 @@ public function provideValues() new FixtureReferenceValue('group'), new FunctionCallValue('getName') ), - ] + ]) ), ]; yield '[Array] escaped array' => [ @@ -645,7 +645,7 @@ public function provideValues() ]; yield '[Array] simple string array' => [ '[@user->name, @group->getName()]', - [ + new ArrayValue([ new FixturePropertyValue( new FixtureReferenceValue('user'), 'name' @@ -654,7 +654,7 @@ public function provideValues() new FixtureReferenceValue('group'), new FunctionCallValue('getName') ), - ], + ]), ]; // Optional diff --git a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParserTest.php b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParserTest.php index 4a3feb9ad..aa3ba459e 100644 --- a/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParserTest.php +++ b/tests/FixtureBuilder/ExpressionLanguage/Parser/TokenParser/Chainable/StringArrayTokenParserTest.php @@ -13,6 +13,7 @@ namespace Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\TokenParser\Chainable; +use Nelmio\Alice\Definition\Value\ArrayValue; use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\ChainableTokenParserInterface; use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\Parser\FakeParser; use Nelmio\Alice\FixtureBuilder\ExpressionLanguage\ParserInterface; @@ -88,7 +89,7 @@ public function testParsesEachArrayElementAndReturnsTheConstructedArray() /** @var ParserInterface $decoratedParser */ $decoratedParser = $decoratedParserProphecy->reveal(); - $expected = ['parsed_val1', 'parsed_val2']; + $expected = new ArrayValue(['parsed_val1', 'parsed_val2']); $parser = new StringArrayTokenParser($decoratedParser); $actual = $parser->parse($token); @@ -107,7 +108,7 @@ public function testIsAbleToParseEmptyArrays() /** @var ParserInterface $decoratedParser */ $decoratedParser = $decoratedParserProphecy->reveal(); - $expected = []; + $expected = new ArrayValue([]); $parser = new StringArrayTokenParser($decoratedParser); $actual = $parser->parse($token); @@ -125,7 +126,7 @@ public function testTrimsEachArgumentValueBeforePassingThemToTheDecoratedParser( /** @var ParserInterface $decoratedParser */ $decoratedParser = $decoratedParserProphecy->reveal(); - $expected = ['parsed_val1', 'parsed_val2']; + $expected = new ArrayValue(['parsed_val1', 'parsed_val2']); $parser = new StringArrayTokenParser($decoratedParser); $actual = $parser->parse($token); diff --git a/tests/Loader/LoaderIntegrationTest.php b/tests/Loader/LoaderIntegrationTest.php index 354cc4693..892467e90 100644 --- a/tests/Loader/LoaderIntegrationTest.php +++ b/tests/Loader/LoaderIntegrationTest.php @@ -2632,6 +2632,30 @@ public function provideFixturesToGenerate() ], ]; + yield 'string array value' => [ + [ + stdClass::class => [ + 'dummy' => [ + 'foo' => 'bar', + ], + 'another_dummy' => [ + 'dummies' => '[@dummy, @dummy, @dummy]', + ], + ], + ], + [ + 'parameters' => [], + 'objects' => [ + 'dummy' => $dummy = StdClassFactory::create([ + 'foo' => 'bar', + ]), + 'another_dummy' => StdClassFactory::create([ + 'dummies' => [$dummy, $dummy, $dummy] + ]), + ], + ], + ]; + yield 'array value' => [ [ stdClass::class => [