-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests & Travis & sentry/sdk ^3.0 (#4)
* Added tests, Makefile and Travis CI definition. * `setUser` is called only for logged user. * Fix other types of log value, than string. * Library `sentry/sdk` was bumped to `3.0`
- Loading branch information
Showing
8 changed files
with
208 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
tests/cases/**/output | ||
tests/tmp | ||
vendor | ||
coverage.xml | ||
composer.lock |
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,52 @@ | ||
language: php | ||
php: | ||
- 7.2 | ||
- 7.3 | ||
- 7.4 | ||
|
||
before_install: | ||
# Turn off XDebug | ||
- phpenv config-rm xdebug.ini || return 0 | ||
|
||
install: | ||
# Composer | ||
- travis_retry composer install --no-interaction --no-progress --prefer-dist | ||
|
||
script: | ||
# Tests | ||
- composer test | ||
|
||
after_failure: | ||
# Print *.actual content | ||
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done | ||
|
||
jobs: | ||
include: | ||
- env: title="Lowest Dependencies 7.2" | ||
php: 7.2 | ||
install: | ||
- travis_retry composer update --no-interaction --no-progress --prefer-dist --prefer-lowest | ||
script: | ||
- composer test | ||
|
||
- stage: cs | ||
php: 7.4 | ||
script: | ||
- composer cs | ||
|
||
# - stage: Test Coverage | ||
# if: branch = master AND type = push | ||
# script: | ||
# - composer coverage | ||
# after_script: | ||
# - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.2.0/php-coveralls.phar | ||
# - php php-coveralls.phar --verbose --config .coveralls.yml | ||
# | ||
# allow_failures: | ||
# - stage: Test Coverage | ||
|
||
sudo: false | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache |
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
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
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,10 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Ninjify\Nunjuck\Environment; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
// Configure environment | ||
Environment::setupTester(); | ||
Environment::setupTimezone(); | ||
Environment::setupVariables(__DIR__); |
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,99 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Nette\Bridges\HttpDI\HttpExtension; | ||
use Nette\Bridges\HttpDI\SessionExtension; | ||
use Nette\Bridges\SecurityDI\SecurityExtension; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerLoader; | ||
use Nette\Http\Session; | ||
use Nette\Security\Identity; | ||
use Nette\Security\IIdentity; | ||
use Nette\Security\User; | ||
use Rootpd\NetteSentry\DI\SentryExtension; | ||
use Rootpd\NetteSentry\SentryLogger; | ||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
// simple config | ||
test(function (): void { | ||
$config = [ | ||
'dsn' => 'https://[email protected]/3', | ||
]; | ||
|
||
$loader = new ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Compiler $compiler) use ($config): void { | ||
$compiler->addExtension('sentry', new SentryExtension()) | ||
->addConfig([ | ||
'sentry' => $config, | ||
]); | ||
}, 1); | ||
|
||
/** @var Container $container */ | ||
$container = new $class(); | ||
|
||
/** @var SentryLogger $logger */ | ||
$logger = $container->getService('sentry.logger'); | ||
|
||
Assert::type(SentryLogger::class, $logger); | ||
|
||
Assert::with($logger, function () use ($config): void { | ||
Assert::null($this->session); | ||
|
||
Assert::null($this->identity); | ||
|
||
Assert::same([], $this->userFields); | ||
|
||
Assert::same([], $this->priorityMapping); | ||
}); | ||
}); | ||
|
||
// complex config | ||
test(function (): void { | ||
$config = [ | ||
'dsn' => 'https://[email protected]/3', | ||
'environment' => 'test', | ||
'user_fields' => [ | ||
'email', | ||
], | ||
'priority_mapping' => [ | ||
'mypriority' => 'warning', | ||
] | ||
]; | ||
|
||
$loader = new ContainerLoader(TEMP_DIR, true); | ||
$class = $loader->load(function (Compiler $compiler) use ($config): void { | ||
$compiler->addExtension('http', new HttpExtension()); | ||
$compiler->addExtension('security', new SecurityExtension()); | ||
$compiler->addExtension('session', new SessionExtension()); | ||
|
||
$compiler->addExtension('sentry', new SentryExtension()) | ||
->addConfig([ | ||
'sentry' => $config, | ||
]); | ||
}, 2); | ||
|
||
/** @var Container $container */ | ||
$container = new $class(); | ||
|
||
$user = $container->getByType(User::class); | ||
$identity = new Identity(1, null, ['email' => '']); | ||
$user->login($identity); | ||
|
||
/** @var SentryLogger $logger */ | ||
$logger = $container->getService('sentry.logger'); | ||
|
||
Assert::type(SentryLogger::class, $logger); | ||
|
||
Assert::with($logger, function () use ($config, $identity): void { | ||
Assert::type(Session::class, $this->session); | ||
|
||
Assert::type(IIdentity::class, $this->identity); | ||
Assert::same($identity, $this->identity); | ||
|
||
Assert::same($config['user_fields'], $this->userFields); | ||
|
||
Assert::same($config['priority_mapping'], $this->priorityMapping); | ||
}); | ||
}); |