|  | 
| 5 | 5 | use NodiLabs\NodiShell\Services\ShellSessionService; | 
| 6 | 6 | 
 | 
| 7 | 7 | describe('ShellSessionService', function () { | 
| 8 |  | -    beforeEach(function () { | 
| 9 |  | -        $this->service = new ShellSessionService; | 
| 10 |  | -    }); | 
| 11 |  | - | 
| 12 | 8 |     describe('History Management', function () { | 
| 13 | 9 |         it('can add commands to history', function () { | 
| 14 |  | -            $this->service->addToHistory('command1'); | 
| 15 |  | -            $this->service->addToHistory('command2'); | 
|  | 10 | +            $service = new ShellSessionService; | 
|  | 11 | +            $service->addToHistory('command1'); | 
|  | 12 | +            $service->addToHistory('command2'); | 
| 16 | 13 | 
 | 
| 17 |  | -            expect($this->service->getHistory())->toBe(['command1', 'command2']); | 
|  | 14 | +            expect($service->getHistory())->toBe(['command1', 'command2']); | 
| 18 | 15 |         }); | 
| 19 | 16 | 
 | 
| 20 | 17 |         it('maintains history limit', function () { | 
|  | 
| 32 | 29 |         }); | 
| 33 | 30 | 
 | 
| 34 | 31 |         it('can clear history', function () { | 
| 35 |  | -            $this->service->addToHistory('command1'); | 
| 36 |  | -            $this->service->addToHistory('command2'); | 
|  | 32 | +            $service = new ShellSessionService; | 
|  | 33 | +            $service->addToHistory('command1'); | 
|  | 34 | +            $service->addToHistory('command2'); | 
| 37 | 35 | 
 | 
| 38 |  | -            $this->service->clearHistory(); | 
|  | 36 | +            $service->clearHistory(); | 
| 39 | 37 | 
 | 
| 40 |  | -            expect($this->service->getHistory())->toBe([]); | 
|  | 38 | +            expect($service->getHistory())->toBe([]); | 
| 41 | 39 |         }); | 
| 42 | 40 |     }); | 
| 43 | 41 | 
 | 
| 44 | 42 |     describe('Variable Management', function () { | 
| 45 | 43 |         it('can set and get variables', function () { | 
| 46 |  | -            $this->service->setVariable('name', 'John'); | 
| 47 |  | -            $this->service->setVariable('age', 30); | 
|  | 44 | +            $service = new ShellSessionService; | 
|  | 45 | +            $service->setVariable('name', 'John'); | 
|  | 46 | +            $service->setVariable('age', 30); | 
| 48 | 47 | 
 | 
| 49 |  | -            expect($this->service->getVariable('name'))->toBe('John'); | 
| 50 |  | -            expect($this->service->getVariable('age'))->toBe(30); | 
|  | 48 | +            expect($service->getVariable('name'))->toBe('John'); | 
|  | 49 | +            expect($service->getVariable('age'))->toBe(30); | 
| 51 | 50 |         }); | 
| 52 | 51 | 
 | 
| 53 | 52 |         it('returns null for non-existent variables', function () { | 
| 54 |  | -            expect($this->service->getVariable('non_existent'))->toBeNull(); | 
|  | 53 | +            $service = new ShellSessionService; | 
|  | 54 | +            expect($service->getVariable('non_existent'))->toBeNull(); | 
| 55 | 55 |         }); | 
| 56 | 56 | 
 | 
| 57 | 57 |         it('can check if variable exists', function () { | 
| 58 |  | -            $this->service->setVariable('name', 'John'); | 
|  | 58 | +            $service = new ShellSessionService; | 
|  | 59 | +            $service->setVariable('name', 'John'); | 
| 59 | 60 | 
 | 
| 60 |  | -            expect($this->service->hasVariable('name'))->toBeTrue(); | 
| 61 |  | -            expect($this->service->hasVariable('non_existent'))->toBeFalse(); | 
|  | 61 | +            expect($service->hasVariable('name'))->toBeTrue(); | 
|  | 62 | +            expect($service->hasVariable('non_existent'))->toBeFalse(); | 
| 62 | 63 |         }); | 
| 63 | 64 | 
 | 
| 64 | 65 |         it('can handle null values', function () { | 
| 65 |  | -            $this->service->setVariable('null_var', null); | 
|  | 66 | +            $service = new ShellSessionService; | 
|  | 67 | +            $service->setVariable('null_var', null); | 
| 66 | 68 | 
 | 
| 67 |  | -            expect($this->service->hasVariable('null_var'))->toBeTrue(); | 
| 68 |  | -            expect($this->service->getVariable('null_var'))->toBeNull(); | 
|  | 69 | +            expect($service->hasVariable('null_var'))->toBeTrue(); | 
|  | 70 | +            expect($service->getVariable('null_var'))->toBeNull(); | 
| 69 | 71 |         }); | 
| 70 | 72 | 
 | 
| 71 | 73 |         it('can remove variables', function () { | 
| 72 |  | -            $this->service->setVariable('name', 'John'); | 
| 73 |  | -            expect($this->service->hasVariable('name'))->toBeTrue(); | 
|  | 74 | +            $service = new ShellSessionService; | 
|  | 75 | +            $service->setVariable('name', 'John'); | 
|  | 76 | +            expect($service->hasVariable('name'))->toBeTrue(); | 
| 74 | 77 | 
 | 
| 75 |  | -            $this->service->removeVariable('name'); | 
| 76 |  | -            expect($this->service->hasVariable('name'))->toBeFalse(); | 
|  | 78 | +            $service->removeVariable('name'); | 
|  | 79 | +            expect($service->hasVariable('name'))->toBeFalse(); | 
| 77 | 80 |         }); | 
| 78 | 81 | 
 | 
| 79 | 82 |         it('can get all variables', function () { | 
| 80 |  | -            $this->service->setVariable('name', 'John'); | 
| 81 |  | -            $this->service->setVariable('age', 30); | 
|  | 83 | +            $service = new ShellSessionService; | 
|  | 84 | +            $service->setVariable('name', 'John'); | 
|  | 85 | +            $service->setVariable('age', 30); | 
| 82 | 86 | 
 | 
| 83 |  | -            $variables = $this->service->getAllVariables(); | 
|  | 87 | +            $variables = $service->getAllVariables(); | 
| 84 | 88 |             expect($variables)->toBe(['name' => 'John', 'age' => 30]); | 
| 85 | 89 |         }); | 
| 86 | 90 | 
 | 
| 87 | 91 |         it('can clear all variables', function () { | 
| 88 |  | -            $this->service->setVariable('name', 'John'); | 
| 89 |  | -            $this->service->setVariable('age', 30); | 
|  | 92 | +            $service = new ShellSessionService; | 
|  | 93 | +            $service->setVariable('name', 'John'); | 
|  | 94 | +            $service->setVariable('age', 30); | 
| 90 | 95 | 
 | 
| 91 |  | -            $this->service->clearVariables(); | 
|  | 96 | +            $service->clearVariables(); | 
| 92 | 97 | 
 | 
| 93 |  | -            expect($this->service->getAllVariables())->toBe([]); | 
|  | 98 | +            expect($service->getAllVariables())->toBe([]); | 
| 94 | 99 |         }); | 
| 95 | 100 | 
 | 
| 96 | 101 |         it('can handle various data types', function () { | 
| 97 |  | -            $this->service->setVariable('string', 'test'); | 
| 98 |  | -            $this->service->setVariable('integer', 42); | 
| 99 |  | -            $this->service->setVariable('float', 3.14); | 
| 100 |  | -            $this->service->setVariable('boolean', true); | 
| 101 |  | -            $this->service->setVariable('array', [1, 2, 3]); | 
| 102 |  | -            $this->service->setVariable('object', (object) ['key' => 'value']); | 
| 103 |  | - | 
| 104 |  | -            expect($this->service->getVariable('string'))->toBe('test'); | 
| 105 |  | -            expect($this->service->getVariable('integer'))->toBe(42); | 
| 106 |  | -            expect($this->service->getVariable('float'))->toBe(3.14); | 
| 107 |  | -            expect($this->service->getVariable('boolean'))->toBeTrue(); | 
| 108 |  | -            expect($this->service->getVariable('array'))->toBe([1, 2, 3]); | 
| 109 |  | -            expect($this->service->getVariable('object'))->toEqual((object) ['key' => 'value']); | 
|  | 102 | +            $service = new ShellSessionService; | 
|  | 103 | +            $service->setVariable('string', 'test'); | 
|  | 104 | +            $service->setVariable('integer', 42); | 
|  | 105 | +            $service->setVariable('float', 3.14); | 
|  | 106 | +            $service->setVariable('boolean', true); | 
|  | 107 | +            $service->setVariable('array', [1, 2, 3]); | 
|  | 108 | +            $service->setVariable('object', (object) ['key' => 'value']); | 
|  | 109 | + | 
|  | 110 | +            expect($service->getVariable('string'))->toBe('test'); | 
|  | 111 | +            expect($service->getVariable('integer'))->toBe(42); | 
|  | 112 | +            expect($service->getVariable('float'))->toBe(3.14); | 
|  | 113 | +            expect($service->getVariable('boolean'))->toBeTrue(); | 
|  | 114 | +            expect($service->getVariable('array'))->toBe([1, 2, 3]); | 
|  | 115 | +            expect($service->getVariable('object'))->toEqual((object) ['key' => 'value']); | 
| 110 | 116 |         }); | 
| 111 | 117 |     }); | 
| 112 | 118 | 
 | 
| 113 | 119 |     describe('Context Management', function () { | 
| 114 | 120 |         it('can set and get context', function () { | 
| 115 |  | -            $this->service->setContext('current_user', 123); | 
| 116 |  | -            $this->service->setContext('environment', 'testing'); | 
|  | 121 | +            $service = new ShellSessionService; | 
|  | 122 | +            $service->setContext('current_user', 123); | 
|  | 123 | +            $service->setContext('environment', 'testing'); | 
| 117 | 124 | 
 | 
| 118 |  | -            expect($this->service->getContext('current_user'))->toBe(123); | 
| 119 |  | -            expect($this->service->getContext('environment'))->toBe('testing'); | 
|  | 125 | +            expect($service->getContext('current_user'))->toBe(123); | 
|  | 126 | +            expect($service->getContext('environment'))->toBe('testing'); | 
| 120 | 127 |         }); | 
| 121 | 128 | 
 | 
| 122 | 129 |         it('returns null for non-existent context', function () { | 
| 123 |  | -            expect($this->service->getContext('non_existent'))->toBeNull(); | 
|  | 130 | +            $service = new ShellSessionService; | 
|  | 131 | +            expect($service->getContext('non_existent'))->toBeNull(); | 
| 124 | 132 |         }); | 
| 125 | 133 | 
 | 
| 126 | 134 |         it('can get all context', function () { | 
| 127 |  | -            $this->service->setContext('user', 123); | 
| 128 |  | -            $this->service->setContext('env', 'test'); | 
|  | 135 | +            $service = new ShellSessionService; | 
|  | 136 | +            $service->setContext('user', 123); | 
|  | 137 | +            $service->setContext('env', 'test'); | 
| 129 | 138 | 
 | 
| 130 |  | -            $context = $this->service->getAllContext(); | 
|  | 139 | +            $context = $service->getAllContext(); | 
| 131 | 140 |             expect($context)->toBe(['user' => 123, 'env' => 'test']); | 
| 132 | 141 |         }); | 
| 133 | 142 | 
 | 
| 134 | 143 |         it('can clear context', function () { | 
| 135 |  | -            $this->service->setContext('user', 123); | 
|  | 144 | +            $service = new ShellSessionService; | 
|  | 145 | +            $service->setContext('user', 123); | 
| 136 | 146 | 
 | 
| 137 |  | -            $this->service->clearContext(); | 
|  | 147 | +            $service->clearContext(); | 
| 138 | 148 | 
 | 
| 139 |  | -            expect($this->service->getAllContext())->toBe([]); | 
|  | 149 | +            expect($service->getAllContext())->toBe([]); | 
| 140 | 150 |         }); | 
| 141 | 151 |     }); | 
| 142 | 152 | 
 | 
| 143 | 153 |     describe('Reset Functionality', function () { | 
| 144 | 154 |         it('can reset all data', function () { | 
| 145 |  | -            $this->service->addToHistory('command1'); | 
| 146 |  | -            $this->service->setVariable('name', 'John'); | 
| 147 |  | -            $this->service->setContext('user', 123); | 
|  | 155 | +            $service = new ShellSessionService; | 
|  | 156 | +            $service->addToHistory('command1'); | 
|  | 157 | +            $service->setVariable('name', 'John'); | 
|  | 158 | +            $service->setContext('user', 123); | 
| 148 | 159 | 
 | 
| 149 |  | -            $this->service->reset(); | 
|  | 160 | +            $service->reset(); | 
| 150 | 161 | 
 | 
| 151 |  | -            expect($this->service->getHistory())->toBe([]); | 
| 152 |  | -            expect($this->service->getAllVariables())->toBe([]); | 
| 153 |  | -            expect($this->service->getAllContext())->toBe([]); | 
|  | 162 | +            expect($service->getHistory())->toBe([]); | 
|  | 163 | +            expect($service->getAllVariables())->toBe([]); | 
|  | 164 | +            expect($service->getAllContext())->toBe([]); | 
| 154 | 165 |         }); | 
| 155 | 166 |     }); | 
| 156 | 167 | }); | 
0 commit comments