NameNode example

use Symfony\Component\ExpressionLanguage\Node\ArrayNode;
use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
use Symfony\Component\ExpressionLanguage\Node\GetAttrNode;
use Symfony\Component\ExpressionLanguage\Node\NameNode;

class GetAttrNodeTest extends AbstractNodeTestCase
{
    public static function getEvaluateData(): array
    {
        return [
            ['b', new GetAttrNode(new NameNode('foo')new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)['foo' => ['b' => 'a', 'b']]],
            ['a', new GetAttrNode(new NameNode('foo')new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)['foo' => ['b' => 'a', 'b']]],

            ['bar', new GetAttrNode(new NameNode('foo')new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL)['foo' => new Obj()]],

            ['baz', new GetAttrNode(new NameNode('foo')new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL)['foo' => new Obj()]],
            ['a', new GetAttrNode(new NameNode('foo')new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)['foo' => ['b' => 'a', 'b'], 'index' => 'b']],
        ];
    }

    public static function getCompileData(): array
    {
        
public function testEvaluateMatchesWithInvalidRegexp()
    {
        $node = new BinaryNode('matches', new ConstantNode('abc')new ConstantNode('this is not a regexp'));

        $this->expectException(SyntaxError::class);
        $this->expectExceptionMessage('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric');
        $node->evaluate([][]);
    }

    public function testEvaluateMatchesWithInvalidRegexpAsExpression()
    {
        $node = new BinaryNode('matches', new ConstantNode('abc')new NameNode('regexp'));

        $this->expectException(SyntaxError::class);
        $this->expectExceptionMessage('Regexp "this is not a regexp" passed to "matches" is not valid: Delimiter must not be alphanumeric');
        $node->evaluate([]['regexp' => 'this is not a regexp']);
    }

    public function testCompileMatchesWithInvalidRegexp()
    {
        $node = new BinaryNode('matches', new ConstantNode('abc')new ConstantNode('this is not a regexp'));

        $this->expectException(SyntaxError::class);
        


namespace Symfony\Component\ExpressionLanguage\Tests\Node;

use Symfony\Component\ExpressionLanguage\Node\NameNode;

class NameNodeTest extends AbstractNodeTestCase
{
    public static function getEvaluateData(): array
    {
        return [
            ['bar', new NameNode('foo')['foo' => 'bar']],
        ];
    }

    public static function getCompileData(): array
    {
        return [
            ['$foo', new NameNode('foo')],
        ];
    }

    public static function getDumpData(): array
    {


                                // is the name used in the compiled code different                                 // from the name used in the expression?                                 if (\is_int($name = array_search($token->value, $this->names))) {
                                    $name = $token->value;
                                }
                            } else {
                                $name = $token->value;
                            }

                            $node = new Node\NameNode($name);
                        }
                }
                break;

            case Token::NUMBER_TYPE:
            case Token::STRING_TYPE:
                $this->stream->next();

                return new Node\ConstantNode($token->value);

            default:
                
$this->assertEquals($node$parser->parse($lexer->tokenize($expression)$names));
    }

    public static function getParseData()
    {
        $arguments = new Node\ArgumentsNode();
        $arguments->addElement(new Node\ConstantNode('arg1'));
        $arguments->addElement(new Node\ConstantNode(2));
        $arguments->addElement(new Node\ConstantNode(true));

        $arrayNode = new Node\ArrayNode();
        $arrayNode->addElement(new Node\NameNode('bar'));

        return [
            [
                new Node\NameNode('a'),
                'a',
                ['a'],
            ],
            [
                new Node\ConstantNode('a'),
                '"a"',
            ],
            [
Home | Imprint | This part of the site doesn't use cookies.