Skip to content

Commit

Permalink
Add support for Laravel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
hedii committed Mar 3, 2020
1 parent ffc1c26 commit 824432e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,8 +1,8 @@
language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4
before_script:
- composer self-update
- composer install
Expand Down
9 changes: 4 additions & 5 deletions composer.json
Expand Up @@ -26,13 +26,12 @@
"source": "https://github.com/hedii/laravel-gelf-logger"
},
"require": {
"php": "^7.1.3",
"illuminate/log": "5.6.*|5.7.*|5.8.*|^6.0",
"graylog2/gelf-php": "^1.5"
"php": "^7.2.5",
"illuminate/log": "^7.0",
"graylog2/gelf-php": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"orchestra/testbench": "^3.7"
"orchestra/testbench": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down
28 changes: 23 additions & 5 deletions tests/GelfLoggerTest.php
Expand Up @@ -161,7 +161,7 @@ public function it_should_use_default_max_length_when_max_length_is_not_provided
$logger = Log::channel('gelf');

$this->assertSame(
GelfMessageFormatter::DEFAULT_MAX_LENGTH,
$this->getConstant(GelfMessageFormatter::class, 'DEFAULT_MAX_LENGTH'),
$this->getAttribute($logger->getHandlers()[0]->getFormatter(), 'maxLength')
);
}
Expand All @@ -178,21 +178,20 @@ public function it_should_use_default_max_length_when_max_length_is_null(): void
$logger = Log::channel('gelf');

$this->assertSame(
GelfMessageFormatter::DEFAULT_MAX_LENGTH,
$this->getConstant(GelfMessageFormatter::class, 'DEFAULT_MAX_LENGTH'),
$this->getAttribute($logger->getHandlers()[0]->getFormatter(), 'maxLength')
);
}

/**
* Get protected or private attribute from an object.
* NOTICE: This method is for testing purposes only.
*
* @param object $object
* @param string $property
* @return mixed
* @throws \Exception
*/
protected function getAttribute($object, string $property)
protected function getAttribute(object $object, string $property)
{
try {
$reflector = new ReflectionClass($object);
Expand All @@ -201,7 +200,26 @@ protected function getAttribute($object, string $property)

return $attribute->getValue($object);
} catch (Exception $e) {
throw new Exception("Can't get attribute from the provided object");
throw new Exception('Cannot get attribute from the provided object');
}
}

/**
* Get protected or private constant from a class.
*
* @param string $class
* @param string $constant
* @return mixed
* @throws \Exception
*/
protected function getConstant(string $class, string $constant)
{
try {
$reflector = new ReflectionClass($class);

return $reflector->getConstant($constant);
} catch (Exception $e) {
throw new Exception('Cannot get attribute from the provided class');
}
}
}

0 comments on commit 824432e

Please sign in to comment.