silverstripe-framework/tests/php/Dev/BacktraceTest.php

69 lines
1.7 KiB
PHP
Raw Normal View History

<?php
2016-10-14 03:30:05 +02:00
namespace SilverStripe\Dev\Tests;
2016-09-09 08:43:05 +02:00
use SilverStripe\Dev\Backtrace;
use SilverStripe\Dev\SapphireTest;
class BacktraceTest extends SapphireTest {
2014-08-15 08:53:05 +02:00
public function testFullFuncNameWithArgsAndCustomCharLimit() {
$func = array(
'class' => 'MyClass',
'type' => '->',
'file' => 'MyFile.php',
'line' => 99,
'function' => 'myFunction',
'args' => array(
'number' => 1,
'mylongstring' => 'more than 20 characters 1234567890',
)
);
$this->assertEquals(
'MyClass->myFunction(1,more than 20 charact...)',
2016-09-09 08:43:05 +02:00
Backtrace::full_func_name($func, true, 20)
);
}
2014-08-15 08:53:05 +02:00
public function testIgnoredFunctionArgs() {
$bt = array(
array(
'type' => '->',
'file' => 'MyFile.php',
'line' => 99,
'function' => 'myIgnoredGlobalFunction',
'args' => array('password' => 'secred',)
),
array(
'class' => 'MyClass',
'type' => '->',
'file' => 'MyFile.php',
'line' => 99,
'function' => 'myIgnoredClassFunction',
'args' => array('password' => 'secred',)
),
array(
'class' => 'MyClass',
'type' => '->',
'file' => 'MyFile.php',
'line' => 99,
'function' => 'myFunction',
'args' => array('myarg' => 'myval')
)
);
2016-09-09 08:43:05 +02:00
Backtrace::config()->update('ignore_function_args',
array(
array('MyClass', 'myIgnoredClassFunction'),
'myIgnoredGlobalFunction'
)
);
2016-09-09 08:43:05 +02:00
$filtered = Backtrace::filter_backtrace($bt);
$this->assertEquals('<filtered>', $filtered[0]['args']['password'], 'Filters global functions');
$this->assertEquals('<filtered>', $filtered[1]['args']['password'], 'Filters class functions');
$this->assertEquals('myval', $filtered[2]['args']['myarg'], 'Doesnt filter other functions');
}
2014-08-15 08:53:05 +02:00
}