File tree Expand file tree Collapse file tree 2 files changed +63
-4
lines changed Expand file tree Collapse file tree 2 files changed +63
-4
lines changed Original file line number Diff line number Diff line change @@ -116,12 +116,13 @@ public function getServer(int $id): ?array {
116116			$ this trustedServersCache  = $ this dbHandler ->getAllServer ();
117117		}
118118
119- 		$ serverarray_filter ($ this trustedServersCache , fn  ($ server$ server'id ' ] === $ id
120- 		if  (empty ($ server
121- 			throw  new  \Exception ('No server found with ID:  '  . $ id
119+ 		foreach  ($ this trustedServersCache  as  $ server
120+ 			if  ($ server'id ' ] === $ id
121+ 				return  $ server
122+ 			}
122123		}
123124
124- 		return   $ server[ 0 ] ;
125+ 		throw   new  \ Exception ( ' No  server found with ID:  '  .  $ id ) ;
125126	}
126127
127128	/** 
Original file line number Diff line number Diff line change @@ -144,6 +144,64 @@ public function testGetServers(): void {
144144		);
145145	}
146146
147+ 	public  static  function  dataTestGetServer () {
148+ 		return  [
149+ 			[
150+ 				15 ,
151+ 				[
152+ 					'id '  => 15 ,
153+ 					'otherData '  => 'first server ' ,
154+ 				]
155+ 			],
156+ 			[
157+ 				16 ,
158+ 				[
159+ 					'id '  => 16 ,
160+ 					'otherData '  => 'second server ' ,
161+ 				]
162+ 			],
163+ 			[
164+ 				42 ,
165+ 				[
166+ 					'id '  => 42 ,
167+ 					'otherData '  => 'last server ' ,
168+ 				]
169+ 			],
170+ 			[
171+ 				108 ,
172+ 				null 
173+ 			],
174+ 		];
175+ 	}
176+ 
177+ 	#[\PHPUnit \Framework \Attributes \DataProvider('dataTestGetServer ' )]
178+ 	public  function  testGetServer (int  $ idarray  $ expectedServervoid  {
179+ 		$ servers
180+ 			[
181+ 				'id '  => 15 ,
182+ 				'otherData '  => 'first server ' ,
183+ 			],
184+ 			[
185+ 				'id '  => 16 ,
186+ 				'otherData '  => 'second server ' ,
187+ 			],
188+ 			[
189+ 				'id '  => 42 ,
190+ 				'otherData '  => 'last server ' ,
191+ 			],
192+ 		];
193+ 		$ this dbHandler ->expects ($ this once ())->method ('getAllServer ' )->willReturn ($ servers
194+ 
195+ 		if  ($ expectedServernull ) {
196+ 			$ this expectException (\Exception::class);
197+ 			$ this expectExceptionMessage ('No server found with ID:  '  . $ id
198+ 		}
199+ 
200+ 		$ this assertEquals (
201+ 			$ expectedServer
202+ 			$ this trustedServers ->getServer ($ id
203+ 		);
204+ 	}
147205
148206	public  function  testIsTrustedServer (): void  {
149207		$ this dbHandler ->expects ($ this once ())
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments