@@ -48,12 +48,10 @@ public function testEnableHttpLoggingWithUnknownLevelUsesDefaultInfo(): void
4848 // Vérifie que le plugin ajouté utilise un logger avec Level::Info
4949 $ reflection = new \ReflectionClass ($ clientBuilder );
5050 $ pluginsProperty = $ reflection ->getProperty ('plugins ' );
51- $ pluginsProperty ->setAccessible (true );
5251 $ plugins = $ pluginsProperty ->getValue ($ clientBuilder );
5352 $ loggerPlugin = end ($ plugins );
5453 $ reflectionPlugin = new \ReflectionClass ($ loggerPlugin );
5554 $ loggerProperty = $ reflectionPlugin ->getProperty ('logger ' );
56- $ loggerProperty ->setAccessible (true );
5755 $ logger = $ loggerProperty ->getValue ($ loggerPlugin );
5856 $ handlers = $ logger ->getHandlers ();
5957 $ handler = $ handlers [0 ];
@@ -67,7 +65,7 @@ public function testEnableHttpLoggingWithUnknownLevelUsesDefaultInfo(): void
6765 protected function setUp (): void
6866 {
6967 parent ::setUp ();
70- $ this ->logger = $ this ->createMock (LoggerInterface::class);
68+ $ this ->logger = $ this ->createStub (LoggerInterface::class);
7169 $ this ->clientBuilder = new ClientBuilder (new Client ());
7270 $ this ->options = new Options ([
7371 'access_token ' => 'test-token ' ,
@@ -112,8 +110,8 @@ public function testEnableHttpLoggingWithDefaultParameters(): void
112110
113111 public function testMultipleLoggingPluginsCanBeAdded (): void
114112 {
115- $ logger1 = $ this ->createMock (LoggerInterface::class);
116- $ logger2 = $ this ->createMock (LoggerInterface::class);
113+ $ logger1 = $ this ->createStub (LoggerInterface::class);
114+ $ logger2 = $ this ->createStub (LoggerInterface::class);
117115 $ initialCount = $ this ->getPluginCount ();
118116 $ this ->options ->enableHttpLoggingWithLogger ($ logger1 );
119117 $ this ->options ->enableHttpLoggingWithLogger ($ logger2 );
@@ -150,32 +148,23 @@ private function getPlugins(): array
150148 {
151149 $ reflection = new \ReflectionClass ($ this ->clientBuilder );
152150 $ pluginsProperty = $ reflection ->getProperty ('plugins ' );
153- $ pluginsProperty ->setAccessible (true );
154151 return $ pluginsProperty ->getValue ($ this ->clientBuilder );
155152 }
156153
157154 public function testCreateConfiguredLoggerReturnsLoggerInstance (): void
158155 {
159- $ options = $ this ->getMockBuilder (Options::class)
160- ->disableOriginalConstructor ()
161- ->onlyMethods ([])
162- ->getMock ();
156+ $ options = $ this ->createStub (Options::class);
163157 $ reflection = new \ReflectionClass ($ options );
164158 $ method = $ reflection ->getMethod ('createConfiguredLogger ' );
165- $ method ->setAccessible (true );
166159 $ logger = $ method ->invoke ($ options , 'php://memory ' , 'info ' );
167160 $ this ->assertInstanceOf (Logger::class, $ logger );
168161 }
169162
170163 public function testCreateConfiguredLoggerSetsLevelAndFormat (): void
171164 {
172- $ options = $ this ->getMockBuilder (Options::class)
173- ->disableOriginalConstructor ()
174- ->onlyMethods ([])
175- ->getMock ();
165+ $ options = $ this ->createStub (Options::class);
176166 $ reflection = new \ReflectionClass ($ options );
177167 $ method = $ reflection ->getMethod ('createConfiguredLogger ' );
178- $ method ->setAccessible (true );
179168 $ customFormat = '[%level_name%] %message% ' ;
180169 $ logger = $ method ->invoke ($ options , 'php://memory ' , 'error ' , $ customFormat );
181170 $ handlers = $ logger ->getHandlers ();
@@ -187,27 +176,21 @@ public function testCreateConfiguredLoggerSetsLevelAndFormat(): void
187176 $ this ->assertInstanceOf (LineFormatter::class, $ formatter );
188177 $ reflectionFormatter = new \ReflectionClass ($ formatter );
189178 $ formatProperty = $ reflectionFormatter ->getProperty ('format ' );
190- $ formatProperty ->setAccessible (true );
191179 $ this ->assertSame ($ customFormat , $ formatProperty ->getValue ($ formatter ));
192180 }
193181
194182 public function testDefaultFormatAndLevelAreUsedWhenNotProvided (): void
195183 {
196- $ options = $ this ->getMockBuilder (Options::class)
197- ->disableOriginalConstructor ()
198- ->onlyMethods ([])
199- ->getMock ();
184+ $ options = $ this ->createStub (Options::class);
200185 $ reflection = new \ReflectionClass ($ options );
201186 $ method = $ reflection ->getMethod ('createConfiguredLogger ' );
202- $ method ->setAccessible (true );
203187 $ logger = $ method ->invoke ($ options , 'php://memory ' , 'unknownlevel ' );
204188 $ handlers = $ logger ->getHandlers ();
205189 $ handler = $ handlers [0 ];
206190 $ this ->assertSame (Level::Info, $ handler ->getLevel ());
207191 $ formatter = $ handler ->getFormatter ();
208192 $ reflectionFormatter = new \ReflectionClass ($ formatter );
209193 $ formatProperty = $ reflectionFormatter ->getProperty ('format ' );
210- $ formatProperty ->setAccessible (true );
211194 $ this ->assertSame ("[%datetime%] %channel%.%level_name%: %message% %context% \n" , $ formatProperty ->getValue ($ formatter ));
212195 }
213196
@@ -223,13 +206,9 @@ public function testAllPsr3LevelsAreSupported(): void
223206 'alert ' => Level::Alert,
224207 'emergency ' => Level::Emergency,
225208 ];
226- $ options = $ this ->getMockBuilder (Options::class)
227- ->disableOriginalConstructor ()
228- ->onlyMethods ([])
229- ->getMock ();
209+ $ options = $ this ->createStub (Options::class);
230210 $ reflection = new \ReflectionClass ($ options );
231211 $ method = $ reflection ->getMethod ('createConfiguredLogger ' );
232- $ method ->setAccessible (true );
233212 foreach ($ levels as $ levelStr => $ expectedLevel ) {
234213 $ logger = $ method ->invoke ($ options , 'php://memory ' , $ levelStr );
235214 $ handlers = $ logger ->getHandlers ();
@@ -240,19 +219,14 @@ public function testAllPsr3LevelsAreSupported(): void
240219
241220 public function testLogFormatNullUsesDefault (): void
242221 {
243- $ options = $ this ->getMockBuilder (Options::class)
244- ->disableOriginalConstructor ()
245- ->onlyMethods ([])
246- ->getMock ();
222+ $ options = $ this ->createStub (Options::class);
247223 $ reflection = new \ReflectionClass ($ options );
248224 $ method = $ reflection ->getMethod ('createConfiguredLogger ' );
249- $ method ->setAccessible (true );
250225 $ logger = $ method ->invoke ($ options , 'php://memory ' , 'info ' , null );
251226 $ handlers = $ logger ->getHandlers ();
252227 $ formatter = $ handlers [0 ]->getFormatter ();
253228 $ reflectionFormatter = new \ReflectionClass ($ formatter );
254229 $ formatProperty = $ reflectionFormatter ->getProperty ('format ' );
255- $ formatProperty ->setAccessible (true );
256230 $ this ->assertSame ("[%datetime%] %channel%.%level_name%: %message% %context% \n" , $ formatProperty ->getValue ($ formatter ));
257231 }
258232}
0 commit comments