55use Monolog \Handler \StreamHandler ;
66use Monolog \Logger ;
77use PHPUnit \Framework \TestCase ;
8- use Psr \Log \LoggerInterface ;
98use Typesense \Exceptions \ConfigError ;
109use Typesense \Lib \Configuration ;
1110
@@ -33,7 +32,6 @@ public function testConfigurationWithDefaultLogger(): void
3332
3433 $ logger = $ config ->getLogger ();
3534
36- $ this ->assertInstanceOf (LoggerInterface::class, $ logger );
3735 $ this ->assertInstanceOf (Logger::class, $ logger );
3836 }
3937
@@ -53,7 +51,6 @@ public function testConfigurationWithCustomLogger(): void
5351 $ logger = $ config ->getLogger ();
5452
5553 // Assert that the logger is the same instance we passed
56- $ this ->assertInstanceOf (LoggerInterface::class, $ logger );
5754 $ this ->assertSame ($ customLogger , $ logger );
5855 $ this ->assertEquals ('custom-test-logger ' , $ logger ->getName ());
5956 }
@@ -68,66 +65,36 @@ public function testConfigurationWithCustomLogLevel(): void
6865 $ config = new Configuration ($ configWithLogLevel );
6966
7067 $ logger = $ config ->getLogger ();
71-
72- $ this ->assertInstanceOf (LoggerInterface::class, $ logger );
7368 $ this ->assertInstanceOf (Logger::class, $ logger );
7469 }
7570
76- public function testConfigurationWithCustomLoggerOverridesLogLevel (): void
71+ public function testConfigurationWithCustomLoggerThrowsExceptionWhenLogLevelIsAlsoProvided (): void
7772 {
78- // Create a custom logger
73+ $ this ->expectException (\InvalidArgumentException::class);
74+ $ this ->expectExceptionMessage ('Setting log_level is not allowed when a custom logger is provided. ' );
75+
7976 $ customLogger = new Logger ('custom-logger-with-level ' );
8077 $ customLogger ->pushHandler (new StreamHandler ('php://stdout ' , Logger::ERROR ));
8178
82- // Add both custom logger and log level to config (logger should win)
8379 $ configWithBoth = array_merge ($ this ->baseConfig , [
8480 'logger ' => $ customLogger ,
85- 'log_level ' => Logger::DEBUG , // This should be ignored
81+ 'log_level ' => Logger::DEBUG ,
8682 ]);
8783
88- $ config = new Configuration ($ configWithBoth );
89-
90- $ logger = $ config ->getLogger ();
91-
92- // Assert that the custom logger is used, not a new one with log_level
93- $ this ->assertSame ($ customLogger , $ logger );
94- $ this ->assertEquals ('custom-logger-with-level ' , $ logger ->getName ());
84+ new Configuration ($ configWithBoth );
9585 }
9686
97- public function testConfigurationWithMockLogger (): void
87+ public function testConfigurationWithInvalidLoggerThrowsException (): void
9888 {
99- // Create a mock logger for testing
100- $ mockLogger = $ this ->createMock (LoggerInterface::class);
101-
102- // Add mock logger to config
103- $ configWithMockLogger = array_merge ($ this ->baseConfig , [
104- 'logger ' => $ mockLogger ,
105- ]);
106-
107- $ config = new Configuration ($ configWithMockLogger );
89+ $ this ->expectException (\InvalidArgumentException::class);
90+ $ this ->expectExceptionMessage ('Logger must implement Psr\Log\LoggerInterface ' );
10891
109- $ logger = $ config ->getLogger ();
110-
111- // Assert that the logger is the same instance we passed
112- $ this ->assertInstanceOf (LoggerInterface::class, $ logger );
113- $ this ->assertSame ($ mockLogger , $ logger );
114- }
115-
116- public function testConfigurationWithInvalidLoggerIgnored (): void
117- {
118- // Try to pass a non-logger object (should fall back to default)
92+ // Try to pass a non-logger object (should throw exception)
11993 $ configWithInvalidLogger = array_merge ($ this ->baseConfig , [
12094 'logger ' => 'not-a-logger-instance ' ,
12195 ]);
12296
123- $ config = new Configuration ($ configWithInvalidLogger );
124-
125- $ logger = $ config ->getLogger ();
126-
127- // Should fall back to default logger
128- $ this ->assertInstanceOf (LoggerInterface::class, $ logger );
129- $ this ->assertInstanceOf (Logger::class, $ logger );
130- $ this ->assertEquals ('typesense ' , $ logger ->getName ());
97+ new Configuration ($ configWithInvalidLogger );
13198 }
13299
133100 public function testConfigurationThrowsErrorWhenNodesAreMissing (): void
0 commit comments