@@ -664,6 +664,72 @@ describe('PHP Debug Adapter', () => {
664664 }
665665 } )
666666
667+ describe ( 'setVariables' , ( ) => {
668+ const program = path . join ( TEST_PROJECT , 'variables.php' )
669+
670+ let localScope : DebugProtocol . Scope | undefined
671+ let localVariables : DebugProtocol . Variable [ ]
672+ let variables : { [ name : string ] : string } = Object . create ( null )
673+
674+ beforeEach ( async ( ) => {
675+ client . launch ( { program } )
676+ await client . waitForEvent ( 'initialized' )
677+ await client . setBreakpointsRequest ( { source : { path : program } , breakpoints : [ { line : 19 } ] } )
678+ const [ , event ] = await Promise . all ( [
679+ client . configurationDoneRequest ( ) ,
680+ client . waitForEvent ( 'stopped' ) as Promise < DebugProtocol . StoppedEvent > ,
681+ ] )
682+ const stackFrame = ( await client . stackTraceRequest ( { threadId : event . body . threadId ! } ) ) . body . stackFrames [ 0 ]
683+ const scopes = ( await client . scopesRequest ( { frameId : stackFrame . id } ) ) . body . scopes
684+ localScope = scopes . find ( scope => scope . name === 'Locals' )
685+ } )
686+
687+ async function getLocals ( ) {
688+ localVariables = ( await client . variablesRequest ( { variablesReference : localScope ! . variablesReference } ) )
689+ . body . variables
690+ variables = Object . create ( null )
691+ for ( const variable of localVariables ) {
692+ variables [ variable . name ] = variable . value
693+ }
694+ }
695+
696+ it ( 'should set the value of an integer' , async ( ) => {
697+ await getLocals ( )
698+ assert . propertyVal ( variables , '$anInt' , '123' )
699+ await client . setVariableRequest ( {
700+ variablesReference : localScope ! . variablesReference ,
701+ name : '$anInt' ,
702+ value : '100' ,
703+ } )
704+ await getLocals ( )
705+ assert . propertyVal ( variables , '$anInt' , '100' )
706+ } )
707+ it ( 'should set the value of a string' , async ( ) => {
708+ await getLocals ( )
709+ assert . propertyVal ( variables , '$aString' , '"123"' )
710+ await client . setVariableRequest ( {
711+ variablesReference : localScope ! . variablesReference ,
712+ name : '$aString' ,
713+ value : '"aaaa"' ,
714+ } )
715+ await getLocals ( )
716+ assert . propertyVal ( variables , '$aString' , '"aaaa"' )
717+ } )
718+ it ( 'should set the value of an nested property' , async ( ) => {
719+ await getLocals ( )
720+ let anArray = localVariables . find ( variable => variable . name === '$anArray' )
721+ assert . propertyVal ( anArray ! , 'value' , 'array(3)' )
722+ await client . setVariableRequest ( {
723+ variablesReference : localScope ! . variablesReference ,
724+ name : '$anArray' ,
725+ value : 'array(1,2)' ,
726+ } )
727+ await getLocals ( )
728+ anArray = localVariables . find ( variable => variable . name === '$anArray' )
729+ assert . propertyVal ( anArray ! , 'value' , 'array(2)' )
730+ } )
731+ } )
732+
667733 describe ( 'virtual sources' , ( ) => {
668734 it ( 'should break on an exception inside eval code' )
669735 it ( 'should return the eval code with a source request' )
0 commit comments