-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from OxCom/develop
issue #14: check that user provider functions were called properly
- Loading branch information
Showing
6 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
imports: | ||
- { resource: config.yml } | ||
- { resource: parameters.yml } | ||
|
||
symfony_rollbar: | ||
enable: true | ||
exclude: | ||
- \Symfony\Component\Debug\Exception\FatalErrorException | ||
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException | ||
- \ParseError | ||
rollbar: | ||
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456' | ||
environment: '%kernel.environment%' | ||
person_fn: "get_awesome_person" | ||
check_ignore: "should_ignore" | ||
custom_data_method: "custom_data_provider" | ||
capture_email: true | ||
capture_username: true | ||
|
||
rollbar_js: | ||
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321' | ||
payload: | ||
environment: '%kernel.environment%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
imports: | ||
- { resource: config.yml } | ||
- { resource: parameters.yml } | ||
|
||
symfony_rollbar: | ||
enable: true | ||
exclude: | ||
- \Symfony\Component\Debug\Exception\FatalErrorException | ||
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException | ||
- \ParseError | ||
rollbar: | ||
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456' | ||
environment: '%kernel.environment%' | ||
person: | ||
id: 42 | ||
username: 'system' | ||
email: '[email protected]' | ||
check_ignore: "should_ignore" | ||
custom_data_method: "custom_data_provider" | ||
|
||
rollbar_js: | ||
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321' | ||
payload: | ||
environment: '%kernel.environment%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
imports: | ||
- { resource: config.yml } | ||
- { resource: parameters.yml } | ||
|
||
symfony_rollbar: | ||
enable: true | ||
exclude: | ||
- \Symfony\Component\Debug\Exception\FatalErrorException | ||
- \SymfonyRollbarBundle\Tests\Fixtures\MyAwesomeException | ||
- \ParseError | ||
rollbar: | ||
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_123456' | ||
environment: '%kernel.environment%' | ||
person: | ||
id: 42 | ||
username: 'system' | ||
email: '[email protected]' | ||
check_ignore: "should_ignore" | ||
custom_data_method: "custom_data_provider" | ||
capture_email: true | ||
capture_username: true | ||
|
||
rollbar_js: | ||
access_token: 'SOME_ROLLBAR_ACCESS_TOKEN_654321' | ||
payload: | ||
environment: '%kernel.environment%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
use SymfonyRollbarBundle\Provider\AbstractPersonProvider; | ||
use SymfonyRollbarBundle\Provider\RollbarHandler; | ||
use SymfonyRollbarBundle\Tests\Fixtures\AwesomePerson; | ||
use Rollbar\Rollbar as RollbarNotifier; | ||
use Rollbar\RollbarLogger; | ||
|
||
/** | ||
* Class PersonProviderTest | ||
|
@@ -36,6 +38,7 @@ public function testPersonProvider($env, $expected) | |
$this->assertNotEmpty($config['person_fn']); | ||
|
||
$call = $config['person_fn']; | ||
$this->assertTrue(is_callable($call)); | ||
$this->assertCount(2, $call, "The 'person_fn' should contains 2 elements"); | ||
|
||
/** @var AbstractPersonProvider $service */ | ||
|
@@ -84,6 +87,7 @@ public function testPersonProviderFunction() | |
$this->assertNotEmpty($config['person_fn']); | ||
|
||
$method = $config['person_fn']; | ||
$this->assertTrue(is_callable($method)); | ||
$this->assertEquals('get_awesome_person', $method); | ||
|
||
$person = call_user_func($method); | ||
|
@@ -92,4 +96,119 @@ public function testPersonProviderFunction() | |
$this->assertEquals('global_username', $person['username']); | ||
$this->assertEquals('global_email', $person['email']); | ||
} | ||
|
||
/** | ||
* @dataProvider generatePersonProviderCalls | ||
* | ||
* @param $env | ||
* @param $expected | ||
* | ||
* @throws \ReflectionException | ||
*/ | ||
public function testPersonProviderWasCalled($env, $expected) | ||
{ | ||
include_once __DIR__ . '/../../Fixtures/global_fn.php'; | ||
static::bootKernel(['environment' => $env]); | ||
|
||
$container = static::$kernel->getContainer(); | ||
$handler = new RollbarHandler($container); | ||
|
||
/** @var \Rollbar\RollbarLogger $notifier */ | ||
$logger = RollbarNotifier::logger(); | ||
$builder = $logger->getDataBuilder(); | ||
|
||
$method = new \ReflectionMethod($builder, 'getPerson'); | ||
$method->setAccessible(true); | ||
|
||
/** @var \Rollbar\Payload\Person $person */ | ||
$person = $method->invoke($builder); | ||
|
||
$this->assertEquals($expected, [ | ||
'id' => $person->getId(), | ||
'username' => $person->getUsername(), | ||
'email' => $person->getEmail(), | ||
]); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function generatePersonProviderCalls() | ||
{ | ||
return [ | ||
[ | ||
'test_if', | ||
[ | ||
'id' => 'global_id', | ||
'username' => null, | ||
'email' => null, | ||
], | ||
], | ||
[ | ||
'test_ifc', | ||
[ | ||
'id' => 'global_id', | ||
'username' => 'global_username', | ||
'email' => 'global_email', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider generateConstPersonCalls | ||
* | ||
* @param $env | ||
* @param $expected | ||
* | ||
* @throws \ReflectionException | ||
*/ | ||
public function testConstPerson($env, $expected) | ||
{ | ||
static::bootKernel(['environment' => $env]); | ||
|
||
$container = static::$kernel->getContainer(); | ||
$handler = new RollbarHandler($container); | ||
|
||
/** @var \Rollbar\RollbarLogger $notifier */ | ||
$logger = RollbarNotifier::logger(); | ||
$builder = $logger->getDataBuilder(); | ||
|
||
$method = new \ReflectionMethod($builder, 'getPerson'); | ||
$method->setAccessible(true); | ||
|
||
/** @var \Rollbar\Payload\Person $person */ | ||
$person = $method->invoke($builder); | ||
|
||
$this->assertEquals($expected, [ | ||
'id' => $person->getId(), | ||
'username' => $person->getUsername(), | ||
'email' => $person->getEmail(), | ||
]); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function generateConstPersonCalls() | ||
{ | ||
return [ | ||
[ | ||
'test_p', | ||
[ | ||
'id' => 42, | ||
'username' => null, | ||
'email' => null, | ||
], | ||
], | ||
[ | ||
'test_pc', | ||
[ | ||
'id' => 42, | ||
'username' => 'system', | ||
'email' => '[email protected]', | ||
], | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters