Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 11 additions & 42 deletions tests/DbgTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,35 @@
*/
class DbgTest extends \PHPUnit\Framework\TestCase
{
/**
* Test printing number.
*
* @return void
*/
public function testPrintNumber()
{
$var = 123;
$this->assertEquals('123', $this->captureOutput($var));
$var = TestHelper::randomInt();

$this->assertEquals($var, $this->captureOutput($var));
}

/**
* Test printing string.
*
* @return void
*/
public function testPrintString()
{
$var = 'some string';
$var = TestHelper::randomString();

$this->assertEquals($var, $this->captureOutput($var));
}

/**
* Test printing output.
*
* @return void
*/
public function testPrintArray()
{
$var = ['first', 'second', 'third'];
$expected = <<<'EOT'
Array
(
[0] => first
[1] => second
[2] => third
)
$var = TestHelper::randomArray();
$expected = TestHelper::makeArrayOutput($var);

EOT;
$this->assertEquals($expected, $this->captureOutput($var));
}

/**
* Test printing output in non-CLI environment.
*
* @return void
*/
public function testPrintArrayNonCli()
{
TestDebug::init();
$var = ['first', 'second', 'third'];
$expected = <<<'EOT'
<pre>Array
(
[0] => first
[1] => second
[2] => third
)
</pre>
EOT;

$var = TestHelper::randomArray();
$expected = '<pre>' . TestHelper::makeArrayOutput($var) . '</pre>';

$this->assertEquals($expected, $this->captureOutput($var));
}

Expand Down
34 changes: 7 additions & 27 deletions tests/DbgThrowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,25 @@
*/
class DbgThrowTest extends \PHPUnit\Framework\TestCase
{
/**
* Test printing number.
*
* @return void
*/
public function testThrowNumber()
{
$var = 123;
$var = TestHelper::randomInt();

$this->assertEquals($var, $this->captureException($var));
}

/**
* Test printing string.
*
* @return void
*/
public function testThrowString()
{
$var = 'some string';
$var = TestHelper::randomString();

$this->assertEquals($var, $this->captureException($var));
}

/**
* Test printing output.
*
* @return void
*/
public function testPrintArray()
public function testThrowArray()
{
$var = ['first', 'second', 'third'];
$expected = <<<'EOT'
Array
(
[0] => first
[1] => second
[2] => third
)
$var = TestHelper::randomArray();
$expected = TestHelper::makeArrayOutput($var);

EOT;
$this->assertEquals($expected, $this->captureException($var));
}

Expand Down
97 changes: 16 additions & 81 deletions tests/DbglogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,14 @@
*/
class DbglogTest extends \PHPUnit\Framework\TestCase
{
/**
* Test printing number with log file.
*
* @return void
*/
public function testLogNumberWithLogFile()
{
$logfile = TestHelper::createTempFile();
dbginit([
'log_file' => $logfile
]);

$var = random_int(PHP_INT_MIN, PHP_INT_MAX);
$var = TestHelper::randomInt();
dbglog($var);

$this->assertRegExp(
Expand All @@ -40,19 +35,14 @@ public function testLogNumberWithLogFile()
);
}

/**
* Test printing string with log file.
*
* @return void
*/
public function testLogStringWithLogFile()
{
$logfile = TestHelper::createTempFile();
dbginit([
'log_file' => $logfile
]);

$var = base64_encode(random_bytes(24));
$var = TestHelper::randomString();
dbglog($var);

$this->assertRegExp(
Expand All @@ -61,68 +51,44 @@ public function testLogStringWithLogFile()
);
}

/**
* Test printing output with log file.
*
* @return void
*/
public function testLogArrayWithLogFile()
{
$logfile = TestHelper::createTempFile();
dbginit([
'log_file' => $logfile
]);

$var = ['first', 'second', 'third'];
$var = TestHelper::randomArray();
dbglog($var);

$expected = <<<'EOT'
Array
(
[0] => first
[1] => second
[2] => third
)

EOT;
$expected = TestHelper::makeArrayOutput($var);
$this->assertRegExp(
TestHelper::makePattern($expected),
file_get_contents($logfile)
);
}

/**
* Test printing data with no log file.
*
* @return void
*/
public function testLogWithNoLogFile()
{
$logfile = TestHelper::createTempFile();
dbginit([
'log_file' => null
]);

$var = random_int(PHP_INT_MIN, PHP_INT_MAX);
$var = TestHelper::randomInt();
dbglog($var);

$this->assertEmpty(file_get_contents($logfile));
}

/**
* Test printing number with logger.
*
* @return void
*/
public function testLogNumberWithLogger()
{
$fp = tmpfile();
$logfile = stream_get_meta_data($fp)['uri'];
$logfile = TestHelper::createTempFile();
dbginit([
'logger' => new Logger($logfile)
]);

$var = random_int(PHP_INT_MIN, PHP_INT_MAX);
$var = TestHelper::randomInt();
dbglog($var);

$this->assertRegExp(
Expand All @@ -131,20 +97,14 @@ public function testLogNumberWithLogger()
);
}

/**
* Test printing string with logger.
*
* @return void
*/
public function testLogStringWithLogger()
{
$fp = tmpfile();
$logfile = stream_get_meta_data($fp)['uri'];
$logfile = TestHelper::createTempFile();
dbginit([
'logger' => new Logger($logfile)
]);

$var = base64_encode(random_bytes(24));
$var = TestHelper::randomString();
dbglog($var);

$this->assertRegExp(
Expand All @@ -153,52 +113,33 @@ public function testLogStringWithLogger()
);
}

/**
* Test printing output with logger.
*
* @return void
*/
public function testLogArrayWithLogger()
{
$fp = tmpfile();
$logfile = stream_get_meta_data($fp)['uri'];
$logfile = TestHelper::createTempFile();
dbginit([
'logger' => new Logger($logfile)
]);

$var = ['first', 'second', 'third'];
$var = TestHelper::randomArray();
dbglog($var);

$expected = <<<'EOT'
Array
(
[0] => first
[1] => second
[2] => third
)
$expected = TestHelper::makeArrayOutput($var);

EOT;
$this->assertRegExp(
TestHelper::makePattern($expected),
file_get_contents($logfile)
);
}

/**
* Test printing data with custom date format.
*
* @return void
*/
public function testLogWithLoggerAndCustomDateFormat()
{
$fp = tmpfile();
$logfile = stream_get_meta_data($fp)['uri'];
$logfile = TestHelper::createTempFile();
$dateFormat = 'Y/m/d H/i/s';
dbginit([
'logger' => new Logger($logfile, $dateFormat)
]);

$var = random_int(PHP_INT_MIN, PHP_INT_MAX);
$var = TestHelper::randomInt();
dbglog($var);

$this->assertRegExp(
Expand All @@ -207,20 +148,14 @@ public function testLogWithLoggerAndCustomDateFormat()
);
}

/**
* Test printing data with no logger.
*
* @return void
*/
public function testLogWithNoLogger()
{
$fp = tmpfile();
$logfile = stream_get_meta_data($fp)['uri'];
$logfile = TestHelper::createTempFile();
dbginit([
'logger' => null
]);

$var = random_int(PHP_INT_MIN, PHP_INT_MAX);
$var = TestHelper::randomInt();
dbglog($var);

$this->assertEmpty(file_get_contents($logfile));
Expand Down
Loading