Skip to content

Commit

Permalink
Added test for working with backtraces
Browse files Browse the repository at this point in the history
  • Loading branch information
kktsvetkov committed Nov 28, 2018
1 parent 557b38b commit c97073e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/ProtectValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Fuko\Masked\Tests;

use Fuko\Masked\Protect;
use Fuko\Masked\Redact;
use PHPUnit\Framework\TestCase;

class ProtectValueTest extends TestCase
Expand Down Expand Up @@ -79,4 +80,60 @@ function provider_protect_value()
),
);
}

function test_protect_backtrace()
{
Protect::hideValue($username = 'u53rn4m3');
Protect::hideValue($password = 'P422wOrd');

$d = $this->uno($username, $password);
$this->assertBacktrace(
var_export(Protect::protect($d), true),
$username,
$password);

$d = $this->ichi($username, $password);
$this->assertBacktrace(Protect::protect($d), $username, $password);
}

function assertBacktrace($redacted, $username, $password)
{
$this->assertFalse(
strpos($redacted, $username)
);
$this->assertFalse(
strpos($redacted, $password)
);

$this->assertInternalType(
'int',
strpos($redacted, Redact::redact( $username ))
);
$this->assertInternalType(
'int',
strpos($redacted, Redact::redact( $password ))
);
}

function uno($username, $password)
{
return $this->due($username, $password);
}

function due($username, $password)
{
return debug_backtrace();
}

function ichi($username, $password)
{
return $this->ni($username, $password);
}

function ni($username, $password)
{
ob_start();
debug_print_backtrace();
return ob_get_clean();
}
}

0 comments on commit c97073e

Please sign in to comment.