From cfc99a176a8d566e2d4e50ccc0f8d4b4567b929a Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Wed, 2 Jan 2019 14:47:52 +0000 Subject: [PATCH 01/11] composer fix --- Factories/RollbarHandlerFactory.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Factories/RollbarHandlerFactory.php b/Factories/RollbarHandlerFactory.php index 852bdb8..5525016 100755 --- a/Factories/RollbarHandlerFactory.php +++ b/Factories/RollbarHandlerFactory.php @@ -31,10 +31,8 @@ public function __construct(ContainerInterface $container) if (!empty($config['person_fn']) && is_callable($config['person_fn'])) { $config['person'] = null; } else { - if (empty($config['person'])) { - - $config['person_fn'] = function() use ($container) { + $config['person_fn'] = function () use ($container) { try { $token = $container->get('security.token_storage')->getToken(); @@ -49,9 +47,7 @@ public function __construct(ContainerInterface $container) // Ignore } }; - } - } Rollbar::init($config, false, false, false); From dcb9ffe27d714f3352d4bb4128f34a9954ca6c11 Mon Sep 17 00:00:00 2001 From: Jozhef Date: Fri, 15 Mar 2019 11:16:06 -0700 Subject: [PATCH 02/11] Add listen new config param "minimum_level" error log. --- Factories/RollbarHandlerFactory.php | 45 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/Factories/RollbarHandlerFactory.php b/Factories/RollbarHandlerFactory.php index 852bdb8..c030bd1 100755 --- a/Factories/RollbarHandlerFactory.php +++ b/Factories/RollbarHandlerFactory.php @@ -15,6 +15,11 @@ */ class RollbarHandlerFactory { + /** + * @var string|null + */ + private $minimumLevel; + /** * RollbarHandlerFactory constructor. * @@ -30,30 +35,26 @@ public function __construct(ContainerInterface $container) if (!empty($config['person_fn']) && is_callable($config['person_fn'])) { $config['person'] = null; - } else { - - if (empty($config['person'])) { - - $config['person_fn'] = function() use ($container) { - - try { - $token = $container->get('security.token_storage')->getToken(); - - if ($token) { - $user = $token->getUser(); - $serializer = $container->get('serializer'); - $person = \json_decode($serializer->serialize($user, 'json'), true); - return $person; - } - } catch (\Exception $exception) { - // Ignore + } elseif (empty($config['person'])) { + $config['person_fn'] = function () use ($container) { + + try { + $token = $container->get('security.token_storage')->getToken(); + + if ($token) { + $user = $token->getUser(); + $serializer = $container->get('serializer'); + + return \json_decode($serializer->serialize($user, 'json'), true); } - }; - - } - + } catch (\Exception $exception) { + // Ignore + } + }; } + $this->minimumLevel = $config['minimum_level'] ?: LogLevel::ERROR; + Rollbar::init($config, false, false, false); } @@ -64,6 +65,6 @@ public function __construct(ContainerInterface $container) */ public function createRollbarHandler() { - return new RollbarHandler(Rollbar::logger(), LogLevel::ERROR); + return new RollbarHandler(Rollbar::logger(), $this->minimumLevel); } } From 1cec8e1b536066e70e94b87e8da1533eaaa71166 Mon Sep 17 00:00:00 2001 From: Jozhef Date: Mon, 18 Mar 2019 09:18:13 +0200 Subject: [PATCH 03/11] Change config name to monolog_minimum_level. --- Factories/RollbarHandlerFactory.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Factories/RollbarHandlerFactory.php b/Factories/RollbarHandlerFactory.php index c030bd1..621c833 100755 --- a/Factories/RollbarHandlerFactory.php +++ b/Factories/RollbarHandlerFactory.php @@ -18,7 +18,7 @@ class RollbarHandlerFactory /** * @var string|null */ - private $minimumLevel; + private $monologMinimumLevel; /** * RollbarHandlerFactory constructor. @@ -53,7 +53,9 @@ public function __construct(ContainerInterface $container) }; } - $this->minimumLevel = $config['minimum_level'] ?: LogLevel::ERROR; + $this->monologMinimumLevel = isset($config['monolog_minimum_level']) + ? $config['monolog_minimum_level'] + : LogLevel::ERROR; Rollbar::init($config, false, false, false); } @@ -65,6 +67,6 @@ public function __construct(ContainerInterface $container) */ public function createRollbarHandler() { - return new RollbarHandler(Rollbar::logger(), $this->minimumLevel); + return new RollbarHandler(Rollbar::logger(), $this->monologMinimumLevel); } } From 6aed6c754f3dbc827f0f07938b2d98bc95407a1e Mon Sep 17 00:00:00 2001 From: Jozhef Date: Mon, 18 Mar 2019 09:43:37 +0200 Subject: [PATCH 04/11] Change config name to monolog_minimum_level. --- Factories/RollbarHandlerFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Factories/RollbarHandlerFactory.php b/Factories/RollbarHandlerFactory.php index c030bd1..e6d719f 100755 --- a/Factories/RollbarHandlerFactory.php +++ b/Factories/RollbarHandlerFactory.php @@ -53,7 +53,7 @@ public function __construct(ContainerInterface $container) }; } - $this->minimumLevel = $config['minimum_level'] ?: LogLevel::ERROR; + $this->minimumLevel = isset($config['minimum_level']) ? $config['minimum_level'] : LogLevel::ERROR; Rollbar::init($config, false, false, false); } From 671f09a32a109cdf3e30d0210d23724202068f85 Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Sun, 24 Mar 2019 00:16:16 +0000 Subject: [PATCH 05/11] Go back to using minimum_level instead of monolog_minimum_level --- Factories/RollbarHandlerFactory.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Factories/RollbarHandlerFactory.php b/Factories/RollbarHandlerFactory.php index 621c833..cbbf20a 100755 --- a/Factories/RollbarHandlerFactory.php +++ b/Factories/RollbarHandlerFactory.php @@ -18,7 +18,7 @@ class RollbarHandlerFactory /** * @var string|null */ - private $monologMinimumLevel; + private $minimumLevel; /** * RollbarHandlerFactory constructor. @@ -53,9 +53,9 @@ public function __construct(ContainerInterface $container) }; } - $this->monologMinimumLevel = isset($config['monolog_minimum_level']) - ? $config['monolog_minimum_level'] - : LogLevel::ERROR; + $this->minimumLevel = isset($config['minimum_level']) + ? $config['minimum_level'] + : \Rollbar\Defaults::get()->minimumLevel(); Rollbar::init($config, false, false, false); } @@ -67,6 +67,6 @@ public function __construct(ContainerInterface $container) */ public function createRollbarHandler() { - return new RollbarHandler(Rollbar::logger(), $this->monologMinimumLevel); + return new RollbarHandler(Rollbar::logger(), $this->minimumLevel); } } From 702eed9924d0f30d3d23db8bec603f9fe0b00eb3 Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Sun, 24 Mar 2019 01:10:15 +0000 Subject: [PATCH 06/11] Prefer rollbar/rollbar-php:dev-master for travis builds to pull in the latest fixes to rollbar-php for CI --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index acaf364..2540bb4 100755 --- a/.travis.yml +++ b/.travis.yml @@ -32,6 +32,7 @@ matrix: before_install: - composer self-update - composer require -n --prefer-dist "symfony/symfony:${SYMFONY_VERSION}" + - composer require -n --prefer-source "rollbar/rollbar:dev-master" script: - php -v From 86628291e5ba7ec0131582d5aa3f54055a4e394b Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Sun, 24 Mar 2019 01:24:08 +0000 Subject: [PATCH 07/11] Clear composer cache before pulling rollbar/rollbar-php:dev-master --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 2540bb4..886bd3c 100755 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ matrix: before_install: - composer self-update + - composer clear-cache - composer require -n --prefer-dist "symfony/symfony:${SYMFONY_VERSION}" - composer require -n --prefer-source "rollbar/rollbar:dev-master" From b58621812264888ac595f9a3f3d1c0bc953ace69 Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Sun, 24 Mar 2019 03:57:42 +0000 Subject: [PATCH 08/11] Apparently composer is unable to pull the tip of master at all unless you specify it by a particular commit --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 886bd3c..4e46fce 100755 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,6 @@ before_install: - composer self-update - composer clear-cache - composer require -n --prefer-dist "symfony/symfony:${SYMFONY_VERSION}" - - composer require -n --prefer-source "rollbar/rollbar:dev-master" script: - php -v From 1d3041850d28fb5f59b2f6bc0622827e39d10227 Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Sun, 7 Apr 2019 23:43:34 +0000 Subject: [PATCH 09/11] test(fixture-app): Load packages/rollbar.yml instead of defining the test access_token in config_tes re #45 --- Tests/Fixtures/app/config/config_test.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Tests/Fixtures/app/config/config_test.yml b/Tests/Fixtures/app/config/config_test.yml index a445db3..fa20f9e 100755 --- a/Tests/Fixtures/app/config/config_test.yml +++ b/Tests/Fixtures/app/config/config_test.yml @@ -1,9 +1,7 @@ imports: - { resource: config.yml } - { resource: parameters.yml } - -rollbar: - access_token: ~ + - { resource: packages/rollbar.yml } monolog: handlers: @@ -12,7 +10,7 @@ monolog: id: Rollbar\Monolog\Handler\RollbarHandler services: - _defaults: - public: true - test.Rollbar\Symfony\RollbarBundle\Payload\Generator: '@Rollbar\Symfony\RollbarBundle\Payload\Generator' + test_alias.logger: + alias: 'logger' + public: true From a0ddb06e00d7a7038099ec82223d86c3d6451ceb Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Sun, 7 Apr 2019 23:44:51 +0000 Subject: [PATCH 10/11] build(dependencies): Allow for Symfony 4.0+ --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 05c63e1..4915758 100755 --- a/composer.json +++ b/composer.json @@ -29,15 +29,15 @@ "require": { "php": ">=5.6", "rollbar/rollbar": "^1", - "symfony/dependency-injection": "^3.4 | ^4.0", - "symfony/config": "^3.4 | ^4.0", - "symfony/http-kernel": "^3.4 | ^4.0", + "symfony/dependency-injection": "^3.4 | ^4", + "symfony/config": "^3.4 | ^4", + "symfony/http-kernel": "^3.4 | ^4", "symfony/monolog-bundle": "*", "symfony/serializer": "*" }, "require-dev": { "phpunit/phpunit": "^5.7", - "symfony/framework-bundle": "^3.4 | ^4.0", + "symfony/framework-bundle": "^3.4 | ^4", "squizlabs/php_codesniffer": "^2.7", "matthiasnoback/symfony-dependency-injection-test": "^1.1" }, From c94df2d50b465e8ecbec4ccba2eed8c53e3dda6e Mon Sep 17 00:00:00 2001 From: Artur Moczulski Date: Mon, 3 Jun 2019 13:26:51 +0000 Subject: [PATCH 11/11] test: test minimum level --- Tests/Factories/RollbarHandlerFactoryTest.php | 56 +++++++++++++++++++ .../Fixtures/app/config/packages/rollbar.yml | 5 ++ 2 files changed, 61 insertions(+) create mode 100755 Tests/Factories/RollbarHandlerFactoryTest.php create mode 100644 Tests/Fixtures/app/config/packages/rollbar.yml diff --git a/Tests/Factories/RollbarHandlerFactoryTest.php b/Tests/Factories/RollbarHandlerFactoryTest.php new file mode 100755 index 0000000..462f972 --- /dev/null +++ b/Tests/Factories/RollbarHandlerFactoryTest.php @@ -0,0 +1,56 @@ +setAccessible(true); + $accessToken = $getAccessTokenMethod->invoke(Rollbar::logger()); + + $mockLogger = $this->getMockBuilder('\Rollbar\RollbarLogger') + ->setConstructorArgs(array(array( + 'access_token' => $accessToken, + 'minimum_level' => LogLevel::ERROR + ))) + ->getMock(); + + $rollbarClass = new \ReflectionClass('\Rollbar\Rollbar'); + $setLoggerMethod = $rollbarClass->getMethod('setLogger'); + $setLoggerMethod->setAccessible(true); + $setLoggerMethod->invoke(null, $mockLogger); + + $logger = self::$container->get('test_alias.logger'); + + $mockLogger->expects($this->once()) + ->method('log') + ->with($this->equalTo(Level::ERROR)); + + $logger->log(Level::ERROR, "Test info from the factory test"); + + $logger->log(Level::INFO, "Test debug from the factory test"); + } +} diff --git a/Tests/Fixtures/app/config/packages/rollbar.yml b/Tests/Fixtures/app/config/packages/rollbar.yml new file mode 100644 index 0000000..293171c --- /dev/null +++ b/Tests/Fixtures/app/config/packages/rollbar.yml @@ -0,0 +1,5 @@ +rollbar: + enabled: true + access_token: ~ # pulled from phpunit.xml + environment: 'rollbar-php-symfony-test-app' + minimum_level: 'info' \ No newline at end of file