Skip to content

Commit

Permalink
Merge b3cdcb4 into 36fc752
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrukowski committed Oct 10, 2018
2 parents 36fc752 + b3cdcb4 commit 2ba1e58
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 15 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog

## [1.3.1] - ????-??-??

Removed `at` word from result of `Awesomite\StackTrace\StackTrace::__toString` whenever step does not contain
reference to called function, e.g.: `#0 (...)/file.php:14` instead of `#0 at (...)file.php:14`.

## [1.3.0] - 2018-09-28

* Added optional parameter `$maxSerializableStringLen` to [`Awesomite\StackTrace\StackTraceFactory::__construct`](./src/StackTraceFactory.php)
Added optional parameter `$maxSerializableStringLen` to [`Awesomite\StackTrace\StackTraceFactory::__construct`](./src/StackTraceFactory.php).

## [1.2.0] - 2018-09-21

Expand Down Expand Up @@ -37,6 +42,7 @@ in [`Value::dumpAsString()`](./src/Arguments/Values/Value.php).

This version contains the same source code as [0.12.0].

[1.3.1]: https://github.com/awesomite/stack-trace/compare/v1.3.0...v1.3.1
[1.3.0]: https://github.com/awesomite/stack-trace/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/awesomite/stack-trace/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/awesomite/stack-trace/compare/v1.0.2...v1.1.0
Expand Down
2 changes: 0 additions & 2 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
final class Constants
{
const KEY_FILE_OBJECT = '__awesomite_file_object';

const KEY_ARGS_CONVERTED = '__awesomite_args_converted';

const MAX_LINE_THRESHOLD = 20;
}
7 changes: 5 additions & 2 deletions src/StackTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
final class StackTrace implements StackTraceInterface
{
const VERSION = '1.3.0';
const VERSION = '1.3.1';
const CONSTRAINTS_VERSION = '^1.0.0';

private $arrayStackTrace;
Expand Down Expand Up @@ -137,10 +137,13 @@ public function __toString()
$line = '#' . $stepNumber;
if ($step->hasCalledFunction()) {
$line .= ' ' . $step->getCalledFunction()->getName() . '()';
if ($step->hasPlaceInCode()) {
$line .= ' at';
}
}
if ($step->hasPlaceInCode()) {
$placeInCode = $step->getPlaceInCode();
$line .= ' at ' . $placeInCode->getFileName() . ':' . $placeInCode->getLineNumber();
$line .= ' ' . $placeInCode->getFileName() . ':' . $placeInCode->getLineNumber();
}

$result[] = $line;
Expand Down
59 changes: 49 additions & 10 deletions tests/StackTraceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,57 @@ public function testGetId()
$this->assertSame(32, \mb_strlen($stackTraceA->getId()));
}

public function testToString()
/**
* @dataProvider providerToString
*
* @param array $rawStackTrace
* @param string $expected
*/
public function testToString(array $rawStackTrace, $expected)
{
$factory = new StackTraceFactory();
$stackTrace = $factory->create();
$string = (string)$stackTrace;
$shouldContains = array(
__FUNCTION__,
__CLASS__,
$stackTrace = new StackTrace($rawStackTrace, new LightVarDumper(), null);
$expected = \str_replace('%file%', __FILE__, $expected);
$result = (string)$stackTrace;
$this->assertInternalType('string', $result);
$this->assertSame($expected, $result);
}

public function providerToString()
{
return array(
array(
array(
array('file' => __FILE__, 'line' => 15, 'function' => 'run', 'type' => '->', 'class' => 'Awesomite\MyApp'),
array('file' => __FILE__, 'line' => 23, 'function' => 'handleHttp', 'type' => '->', 'class' => 'Awesomite\MyApp\Http\Handler'),
),
<<<OUTPUT
#0 Awesomite\MyApp->run() at %file%:15
#1 Awesomite\MyApp\Http\Handler->handleHttp() at %file%:23
OUTPUT
),
array(
array(
array('file' => __FILE__ . '.test', 'line' => 15, 'function' => 'run', 'type' => '->', 'class' => 'Awesomite\MyApp'),
array('file' => __FILE__ . '.test', 'line' => 23, 'function' => 'handleHttp', 'type' => '->', 'class' => 'Awesomite\MyApp\Http\Handler'),
),
<<<OUTPUT
#0 Awesomite\MyApp->run()
#1 Awesomite\MyApp\Http\Handler->handleHttp()
OUTPUT
),
array(
array(
array('file' => __FILE__, 'line' => 17),
),
'#0 %file%:17',
),
array(
array(
array('function' => 'eval'),
),
'#0 eval()',
),
);
foreach ($shouldContains as $expectedPart) {
$this->assertContains($expectedPart, $string);
}
}

/**
Expand Down

0 comments on commit 2ba1e58

Please sign in to comment.