@@ -161,7 +161,7 @@ public function it_should_use_default_max_length_when_max_length_is_not_provided
161161 $ logger = Log::channel ('gelf ' );
162162
163163 $ this ->assertSame (
164- GelfMessageFormatter::DEFAULT_MAX_LENGTH ,
164+ $ this -> getConstant ( GelfMessageFormatter::class, ' DEFAULT_MAX_LENGTH ' ) ,
165165 $ this ->getAttribute ($ logger ->getHandlers ()[0 ]->getFormatter (), 'maxLength ' )
166166 );
167167 }
@@ -178,21 +178,20 @@ public function it_should_use_default_max_length_when_max_length_is_null(): void
178178 $ logger = Log::channel ('gelf ' );
179179
180180 $ this ->assertSame (
181- GelfMessageFormatter::DEFAULT_MAX_LENGTH ,
181+ $ this -> getConstant ( GelfMessageFormatter::class, ' DEFAULT_MAX_LENGTH ' ) ,
182182 $ this ->getAttribute ($ logger ->getHandlers ()[0 ]->getFormatter (), 'maxLength ' )
183183 );
184184 }
185185
186186 /**
187187 * Get protected or private attribute from an object.
188- * NOTICE: This method is for testing purposes only.
189188 *
190189 * @param object $object
191190 * @param string $property
192191 * @return mixed
193192 * @throws \Exception
194193 */
195- protected function getAttribute ($ object , string $ property )
194+ protected function getAttribute (object $ object , string $ property )
196195 {
197196 try {
198197 $ reflector = new ReflectionClass ($ object );
@@ -201,7 +200,26 @@ protected function getAttribute($object, string $property)
201200
202201 return $ attribute ->getValue ($ object );
203202 } catch (Exception $ e ) {
204- throw new Exception ("Can't get attribute from the provided object " );
203+ throw new Exception ('Cannot get attribute from the provided object ' );
204+ }
205+ }
206+
207+ /**
208+ * Get protected or private constant from a class.
209+ *
210+ * @param string $class
211+ * @param string $constant
212+ * @return mixed
213+ * @throws \Exception
214+ */
215+ protected function getConstant (string $ class , string $ constant )
216+ {
217+ try {
218+ $ reflector = new ReflectionClass ($ class );
219+
220+ return $ reflector ->getConstant ($ constant );
221+ } catch (Exception $ e ) {
222+ throw new Exception ('Cannot get attribute from the provided class ' );
205223 }
206224 }
207225}
0 commit comments