Skip to content

Commit

Permalink
tests: test() with description
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Aug 16, 2020
1 parent c4c9034 commit a3ca2f8
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 74 deletions.
10 changes: 5 additions & 5 deletions tests/Tracy/Debugger.detectDebugMode.phpt
Expand Up @@ -14,7 +14,7 @@ require __DIR__ . '/../bootstrap.php';



test(function () { // localhost
test('localhost', function () {
unset($_SERVER['HTTP_X_FORWARDED_FOR']);

$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
Expand All @@ -36,7 +36,7 @@ test(function () { // localhost
});


test(function () { // localhost + proxy
test('localhost + proxy', function () {
$_SERVER['HTTP_X_FORWARDED_FOR'] = 'xx';

$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
Expand All @@ -51,7 +51,7 @@ test(function () { // localhost + proxy
});


test(function () { // missing $_SERVER['REMOTE_ADDR']
test('missing $_SERVER[REMOTE_ADDR]', function () {
unset($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']);

Assert::false(Debugger::detectDebugMode());
Expand All @@ -62,7 +62,7 @@ test(function () { // missing $_SERVER['REMOTE_ADDR']
});


test(function () { // secret
test('secret', function () {
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = '192.168.1.1';
$_COOKIE[Debugger::COOKIE_SECRET] = '*secret*';
Expand All @@ -77,7 +77,7 @@ test(function () { // secret
});


test(function () {
test('', function () {
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = 'xx';

Expand Down
6 changes: 3 additions & 3 deletions tests/Tracy/Debugger.dump().phpt
Expand Up @@ -21,7 +21,7 @@ header('Content-Type: text/plain');
Tracy\Dumper::$useColors = false;


test(function () { // production mode
test('production mode', function () {
Debugger::$productionMode = true;

ob_start();
Expand All @@ -32,7 +32,7 @@ test(function () { // production mode
});


test(function () { // development mode
test('development mode', function () {
Debugger::$productionMode = false;

ob_start();
Expand All @@ -44,7 +44,7 @@ test(function () { // development mode
});


test(function () { // returned value
test('returned value', function () {
$obj = new stdClass;
Assert::same(Debugger::dump($obj), $obj);
});
10 changes: 5 additions & 5 deletions tests/Tracy/Dumper.dump().cli.phpt
Expand Up @@ -38,23 +38,23 @@ stream_filter_register('Capture', 'Capture');
stream_filter_append(STDOUT, 'Capture');


test(function () { // colors
test('colors', function () {
Dumper::$useColors = true;
Capture::$buffer = '';
Dumper::dump(123);
Assert::match("\e[1;32m123\e[0m", Capture::$buffer);
});


test(function () { // no color
test('no color', function () {
Dumper::$useColors = false;
Capture::$buffer = '';
Dumper::dump(123);
Assert::match('123', Capture::$buffer);
});


test(function () { // production mode
test('production mode', function () {
Debugger::$productionMode = true;
Capture::$buffer = '';
ob_start();
Expand All @@ -64,15 +64,15 @@ test(function () { // production mode
});


test(function () { // development mode
test('development mode', function () {
Debugger::$productionMode = false;
Capture::$buffer = '';
Dumper::dump('sensitive data');
Assert::match("'sensitive data'", Capture::$buffer);
});


test(function () { // returned value
test('returned value', function () {
$obj = new stdClass;
Assert::same(Dumper::dump($obj), $obj);
});
12 changes: 6 additions & 6 deletions tests/Tracy/Dumper.dump().html.phpt
Expand Up @@ -18,7 +18,7 @@ if (PHP_SAPI === 'cli') {
}


test(function () { // html mode
test('html mode', function () {
header('Content-Type: text/html');
ob_start();
Assert::same(123, Dumper::dump(123));
Expand All @@ -33,7 +33,7 @@ XX
});


test(function () { // repeated html mode
test('repeated html mode', function () {
ob_start();
Assert::same(123, Dumper::dump(123));
Assert::match(<<<'XX'
Expand All @@ -45,7 +45,7 @@ XX
});


test(function () { // production mode
test('production mode', function () {
Debugger::$productionMode = true;

ob_start();
Expand All @@ -54,7 +54,7 @@ test(function () { // production mode
});


test(function () { // development mode
test('development mode', function () {
Debugger::$productionMode = false;

ob_start();
Expand All @@ -63,13 +63,13 @@ test(function () { // development mode
});


test(function () { // returned value
test('returned value', function () {
$obj = new stdClass;
Assert::same(Dumper::dump($obj), $obj);
});


test(function () { // options
test('options', function () {
$arr = ['loooooooooooooooooooooong texxxxxt', [2, 3, 4, 5, 6, 7, 8]];
ob_start();
Dumper::$showLocation = false;
Expand Down
6 changes: 3 additions & 3 deletions tests/Tracy/Dumper.dump().text.phpt
Expand Up @@ -21,14 +21,14 @@ if (PHP_SAPI === 'cli') {
header('Content-Type: text/plain');


test(function () { // text mode
test('text mode', function () {
ob_start();
Dumper::dump(123);
Assert::match('123', ob_get_clean());
});


test(function () { // production mode
test('production mode', function () {
Debugger::$productionMode = true;

ob_start();
Expand All @@ -37,7 +37,7 @@ test(function () { // production mode
});


test(function () { // development mode
test('development mode', function () {
Debugger::$productionMode = false;

ob_start();
Expand Down
12 changes: 5 additions & 7 deletions tests/Tracy/Helpers.improveError.phpt
Expand Up @@ -46,26 +46,25 @@ class TestClass
$obj = new TestClass;


// reading
test(function () use ($obj) {
test('reading', function () use ($obj) {
@$val = $obj->publicX;
$message = Helpers::improveError(error_get_last()['message']);
Assert::same('Undefined property: TestClass::$publicX, did you mean $public?', $message);
});

test(function () use ($obj) { // suggest only non-static property
test('suggest only non-static property', function () use ($obj) {
@$val = $obj->publicStaticX;
$message = Helpers::improveError(error_get_last()['message']);
Assert::same('Undefined property: TestClass::$publicStaticX', $message);
});

test(function () use ($obj) { // suggest only public property
test('suggest only public property', function () use ($obj) {
@$val = $obj->protectedX;
$message = Helpers::improveError(error_get_last()['message']);
Assert::same('Undefined property: TestClass::$protectedX', $message);
});

test(function () { // do not suggest anything when accessing anonymous class
test('do not suggest anything when accessing anonymous class', function () {
$obj = new class {
};
@$val = $obj->property;
Expand All @@ -74,8 +73,7 @@ test(function () { // do not suggest anything when accessing anonymous class
});


// variables
test(function () use ($obj) {
test('variables', function () use ($obj) {
$abcd = 1;
@$val = $abc;
$message = Helpers::improveError(error_get_last()['message'], get_defined_vars());
Expand Down
35 changes: 16 additions & 19 deletions tests/Tracy/Helpers.improveException.phpt
Expand Up @@ -51,8 +51,7 @@ function myFunction()
$obj = new TestClass;


// calling
test(function () {
test('calling', function () {
try {
trimx();
} catch (\Error $e) {
Expand All @@ -63,7 +62,7 @@ test(function () {
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () {
test('', function () {
try {
abc\trimx();
} catch (\Error $e) {
Expand All @@ -74,7 +73,7 @@ test(function () {
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () {
test('', function () {
try {
myFunctionx();
} catch (\Error $e) {
Expand All @@ -85,7 +84,7 @@ test(function () {
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () {
test('', function () {
try {
TestClass::publicMethodX();
} catch (\Error $e) {
Expand All @@ -96,7 +95,7 @@ test(function () {
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () use ($obj) {
test('', function () use ($obj) {
try {
$obj->publicMethodX();
} catch (\Error $e) {
Expand All @@ -107,7 +106,7 @@ test(function () use ($obj) {
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () use ($obj) { // suggest static method
test('suggest static method', function () use ($obj) {
try {
$obj->publicMethodStaticX();
} catch (\Error $e) {
Expand All @@ -118,7 +117,7 @@ test(function () use ($obj) { // suggest static method
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () use ($obj) { // suggest only public method
test('suggest only public method', function () use ($obj) {
try {
$obj->protectedMethodX();
} catch (\Error $e) {
Expand All @@ -128,7 +127,7 @@ test(function () use ($obj) { // suggest only public method
Assert::false(isset($e->tracyAction));
});

test(function () { // do not suggest anything when accessing anonymous class
test('do not suggest anything when accessing anonymous class', function () {
try {
$obj = new class {
};
Expand All @@ -141,8 +140,7 @@ test(function () { // do not suggest anything when accessing anonymous class
});


// reading
test(function () use ($obj) {
test('reading', function () use ($obj) {
@$val = $obj->publicX;
$e = new ErrorException(error_get_last()['message'], 0, error_get_last()['type']);
Helpers::improveException($e);
Expand All @@ -151,23 +149,23 @@ test(function () use ($obj) {
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () use ($obj) { // suggest only non-static property
test('suggest only non-static property', function () use ($obj) {
@$val = $obj->publicStaticX;
$e = new ErrorException(error_get_last()['message'], 0, error_get_last()['type']);
Helpers::improveException($e);
Assert::same('Undefined property: TestClass::$publicStaticX', $e->getMessage());
Assert::false(isset($e->tracyAction));
});

test(function () use ($obj) { // suggest only public property
test('suggest only public property', function () use ($obj) {
@$val = $obj->protectedX;
$e = new ErrorException(error_get_last()['message'], 0, error_get_last()['type']);
Helpers::improveException($e);
Assert::same('Undefined property: TestClass::$protectedX', $e->getMessage());
Assert::false(isset($e->tracyAction));
});

test(function () use ($obj) { // suggest only static property
test('suggest only static property', function () use ($obj) {
try {
$val = TestClass::$publicStaticX;
} catch (\Error $e) {
Expand All @@ -178,7 +176,7 @@ test(function () use ($obj) { // suggest only static property
Assert::same('fix it', $e->tracyAction['label']);
});

test(function () use ($obj) { // suggest only public static property
test('suggest only public static property', function () use ($obj) {
try {
$val = TestClass::$protectedMethodX;
} catch (\Error $e) {
Expand All @@ -188,7 +186,7 @@ test(function () use ($obj) { // suggest only public static property
Assert::false(isset($e->tracyAction));
});

test(function () { // do not suggest anything when accessing anonymous class
test('do not suggest anything when accessing anonymous class', function () {
$obj = new class {
};
@$val = $obj->property;
Expand All @@ -198,7 +196,7 @@ test(function () { // do not suggest anything when accessing anonymous class
Assert::false(isset($e->tracyAction));
});

test(function () { // do not suggest anything when accessing anonymous class
test('do not suggest anything when accessing anonymous class', function () {
try {
$obj = new class {
};
Expand All @@ -212,8 +210,7 @@ test(function () { // do not suggest anything when accessing anonymous class
});


// variables
test(function () use ($obj) {
test('variables', function () use ($obj) {
$abcd = 1;
@$val = $abc;
$e = new ErrorException(error_get_last()['message'], 0, error_get_last()['type']);
Expand Down

0 comments on commit a3ca2f8

Please sign in to comment.