Skip to content

Commit

Permalink
Check the code style of tests and fix violations
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
nkovacs committed Dec 2, 2016
1 parent 6bcbf43 commit b685350
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 36 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -28,6 +28,7 @@ before_script:
script:
- php ./vendor/bin/phpcs --standard=vendor/mito/yii2-coding-standards/Application src
- php ./vendor/bin/phpcs --standard=vendor/mito/yii2-coding-standards/Application -s --exclude=PSR1.Files.SideEffects,PSR1.Classes.ClassDeclaration --extensions=php tests
- php ./vendor/bin/codecept run unit -d $PHPUNIT_FLAGS

after_success:
Expand Down
2 changes: 1 addition & 1 deletion tests/_bootstrap.php
Expand Up @@ -9,6 +9,6 @@
require_once dirname(__FILE__) . '/../vendor/sentry/sentry/test/Raven/Tests/ClientTest.php';
Raven_Autoloader::register();

$_SERVER['SCRIPT_FILENAME'] = '/' . dirname(__DIR__) .'/web';
$_SERVER['SCRIPT_FILENAME'] = '/' . dirname(__DIR__) . '/web';
$_SERVER['SCRIPT_NAME'] = __DIR__ . '/web';
Yii::setAlias('@mitosentry', dirname(__DIR__));
4 changes: 1 addition & 3 deletions tests/config/acceptance.php
Expand Up @@ -5,7 +5,5 @@
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/config.php'),
[

]
[]
);
6 changes: 3 additions & 3 deletions tests/config/config.php
Expand Up @@ -3,9 +3,9 @@
* Application configuration shared by all test types
*/

$dbDsn = getenv("CI_DB_DSN");
$dbUsername = getenv("CI_DB_USERNAME");
$dbPassword = getenv("CI_DB_PASSWORD");
$dbDsn = getenv('CI_DB_DSN');
$dbUsername = getenv('CI_DB_USERNAME');
$dbPassword = getenv('CI_DB_PASSWORD');

$dbConfig = [
'dsn' => 'mysql:host=localhost;dbname=yii2_basic_tests',
Expand Down
4 changes: 1 addition & 3 deletions tests/config/console.php
Expand Up @@ -5,7 +5,5 @@
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../config/console.php'),
require(__DIR__ . '/config.php'),
[

]
[]
);
4 changes: 1 addition & 3 deletions tests/config/unit.php
Expand Up @@ -5,7 +5,5 @@
return yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../../../config/web.php'),
require(__DIR__ . '/config.php'),
[

]
[]
);
3 changes: 2 additions & 1 deletion tests/unit/DummyRavenClient.php
Expand Up @@ -7,7 +7,8 @@ class DummyRavenClient
public $tags = [];
public $dsn;

public function __construct($dsn, $options) {
public function __construct($dsn, $options)
{
if (isset($options['tags'])) {
$this->tags = $options['tags'];
}
Expand Down
16 changes: 9 additions & 7 deletions tests/unit/SentryComponentTest.php
Expand Up @@ -137,15 +137,17 @@ public function testCapture()

private function assertAssetRegistered($asset)
{
if (Yii::$app->view instanceof \yii\web\View) {
$this->assertArrayHasKey($asset, Yii::$app->view->assetBundles);
}
if (Yii::$app->view instanceof \yii\web\View) {
$this->assertArrayHasKey($asset, Yii::$app->view->assetBundles);
}
private function assertAssetNotRegistered($asset) {
if (Yii::$app->view instanceof \yii\web\View) {
$this->assertArrayNotHasKey($asset, Yii::$app->view->assetBundles);
}
}

private function assertAssetNotRegistered($asset)
{
if (Yii::$app->view instanceof \yii\web\View) {
$this->assertArrayNotHasKey($asset, Yii::$app->view->assetBundles);
}
}

public function testJsNotifierEnabledIfPublicDsnSet()
{
Expand Down
27 changes: 13 additions & 14 deletions tests/unit/SentryTargetTest.php
Expand Up @@ -75,9 +75,9 @@ public function testFilter($filter, $expected)
$logger = $this->mockLogger($target);
foreach ($expected as $message) {
$target->sentry->shouldReceive('capture')
->with(Mockery::on(function($data) use ($message) {
->with(Mockery::on(function ($data) use ($message) {
return $data['message'] === $message;
}), Mockery::on(function($traces) {
}), Mockery::on(function ($traces) {
return true;
}))->once();
}
Expand Down Expand Up @@ -111,16 +111,16 @@ public function testFilterExceptions($except, $exceptionClass, $exceptionCode, $
if ($expectLogged) {
if ($type === self::EXCEPTION_TYPE_OBJECT) {
$target->sentry->shouldReceive('captureException')
->with(Mockery::on(function($exception) {
->with(Mockery::on(function ($exception) {
return ($exception instanceof \Throwable || $exception instanceof \Exception) && $exception->getMessage() === self::DEFAULT_ERROR_MESSAGE;
}), Mockery::on(function($data) {
}), Mockery::on(function ($data) {
return true;
}))->once();
} else {
$target->sentry->shouldReceive('capture')
->with(Mockery::on(function($data) {
->with(Mockery::on(function ($data) {
return $data['message'] === self::DEFAULT_ERROR_MESSAGE;
}), Mockery::on(function($traces) {
}), Mockery::on(function ($traces) {
return true;
}))->once();
}
Expand All @@ -130,9 +130,9 @@ public function testFilterExceptions($except, $exceptionClass, $exceptionCode, $
$target->sentry->shouldNotReceive('captureMessage');
}
$target->sentry->shouldReceive('capture')
->with(Mockery::on(function($data) {
->with(Mockery::on(function ($data) {
return $data['message'] === 'sentinel';
}), Mockery::on(function($traces) {
}), Mockery::on(function ($traces) {
return true;
}))->once();

Expand All @@ -159,7 +159,7 @@ public function filters()
[['levels' => 0], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']],
[
['levels' => Logger::LEVEL_INFO | Logger::LEVEL_WARNING | Logger::LEVEL_ERROR | Logger::LEVEL_TRACE],
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
],
[['levels' => ['error']], ['B', 'G', 'H']],
[['levels' => Logger::LEVEL_ERROR], ['B', 'G', 'H']],
Expand All @@ -181,7 +181,7 @@ public function filters()
[['levels' => 0], ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']],
[
['levels' => Logger::LEVEL_INFO | Logger::LEVEL_WARNING | Logger::LEVEL_ERROR | Logger::LEVEL_TRACE],
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
],
[['levels' => ['error']], ['B', 'G', 'H']],
[['levels' => Logger::LEVEL_ERROR], ['B', 'G', 'H']],
Expand Down Expand Up @@ -229,8 +229,7 @@ public function exceptFilters()
]);
}

$results = array_merge($results, [
]);
$results = array_merge($results, []);

return $results;
}
Expand All @@ -255,9 +254,9 @@ private function createException($type, $exceptionClass, $exceptionCode)
{
switch ($type) {
case self::EXCEPTION_TYPE_OBJECT:
if ($exceptionClass === HttpException::class){
if ($exceptionClass === HttpException::class) {
$args = [$exceptionCode, self::DEFAULT_ERROR_MESSAGE];
}else{
} else {
$args = [self::DEFAULT_ERROR_MESSAGE, $exceptionCode];
}
$exception = (new \ReflectionClass($exceptionClass))->newInstanceArgs($args);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/config/main.php
Expand Up @@ -7,5 +7,5 @@
'assetManager' => [
'basePath' => '@mitosentry/tests/unit/runtime/web/assets',
],
]
],
];

0 comments on commit b685350

Please sign in to comment.