Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
47d4cfe
Removed Awesomite\StackTrace\Arguments\Values\MultipleValues
bkrukowski Jun 4, 2017
1eeba0a
Bug in old HHVM versions:
bkrukowski Jun 5, 2017
d21a0e3
Additional tests for Awesomite\StackTrace\StackTrace
bkrukowski Jun 5, 2017
7c27dda
Clean up code in Awesomite\StackTrace\StackTrace
bkrukowski Jun 5, 2017
21f1496
Added tests for HHVM with flag hhvm.php7.all=1
bkrukowski Jun 5, 2017
66a67dd
bin/hhvm-travis.sh: line 11: travis_wait: command not found
bkrukowski Jun 5, 2017
e27023c
HHVM does not allow to change value of reference using debug_backtrace()
bkrukowski Jun 5, 2017
0205ec4
composer self-update before test hhvm in php7 mode
bkrukowski Jun 5, 2017
6f65552
https://travis-ci.org/awesomite/stack-trace/jobs/239647168
bkrukowski Jun 5, 2017
05ecde6
Speedup HHVM tests
bkrukowski Jun 5, 2017
31c4526
Tests for hhvm
bkrukowski Jun 5, 2017
747c221
Tests for hhvm
bkrukowski Jun 5, 2017
aea5fa6
https://blog.travis-ci.com/2016-11-08-trusty-container-public-beta/
bkrukowski Jun 5, 2017
4e874d9
Speed up tests for hhvm
bkrukowski Jun 5, 2017
adb579b
Tests for hhvm
bkrukowski Jun 5, 2017
8342182
Speed up tests in hhvm
bkrukowski Jun 5, 2017
9d72d4a
sed: couldn't open temporary file /etc/hhvm/sedWvqZYm: Permission denied
bkrukowski Jun 5, 2017
04fd0dd
Tests for hhvm
bkrukowski Jun 5, 2017
02ede56
More readable exception
bkrukowski Jun 5, 2017
5b068b6
Tests for hhvm
bkrukowski Jun 5, 2017
abbb7c4
Interface Throwable does not exist
bkrukowski Jun 5, 2017
501eaed
Test with coverage
bkrukowski Jun 5, 2017
84b6c4e
PHP tests should be executed before HHVM tests
bkrukowski Jun 5, 2017
3c4e31f
Awesomite\StackTrace\StackTrace::unserialize throws Awesomite\StackTr…
bkrukowski Jun 5, 2017
8c81cd1
Fixes for hhvm
bkrukowski Jun 5, 2017
4138e87
Fixes for hhvm
bkrukowski Jun 5, 2017
17463d6
Fixes for hhvm
bkrukowski Jun 5, 2017
58a76cd
Fixes for hhvm
bkrukowski Jun 5, 2017
9c45ae9
Fixes for hhvm
bkrukowski Jun 5, 2017
aa187c8
Fixes for hhvm
bkrukowski Jun 5, 2017
f767292
Fixes for hhvm
bkrukowski Jun 5, 2017
f6db0c1
Fixes for hhvm
bkrukowski Jun 5, 2017
0ead119
Fixes for hhvm
bkrukowski Jun 5, 2017
001a62b
Fixes for hhvm
bkrukowski Jun 5, 2017
d7f2c37
Fixes for hhvm
bkrukowski Jun 5, 2017
0517c11
Fixes for hhvm
bkrukowski Jun 5, 2017
cbb4fdc
Codacy suggestions
bkrukowski Jun 5, 2017
c580686
Added support for awesomite/var-dumper ^0.7
bkrukowski Jun 6, 2017
78fcd4f
Do not export bin/composer-set-config.php
bkrukowski Jun 6, 2017
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/bin/coveralls.sh export-ignore
/bin/composer-set-config.php export-ignore
/.coveralls.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
Expand Down
27 changes: 24 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ install:
- mv .git ~.git

dist: trusty
sudo: false

php:
- 5.4
Expand All @@ -27,10 +28,30 @@ matrix:
- php: 5.3
dist: precise

- php: hhvm
env: HHVM_PHP7=1

- php: hhvm-3.12
env: HHVM_PHP7=1

- php: hhvm-3.15
env: HHVM_PHP7=1

- php: hhvm-3.18
env: HHVM_PHP7=1

- php: hhvm-nightly
env: HHVM_PHP7=1

before_script:
- if [ ${HHVM_PHP7+x} ]; then bin/composer-set-config.php php 7.0; fi
- if [ ${HHVM_PHP7+x} ]; then export EXTRA_CONFIG='-d hhvm.php7.all=1'; else export EXTRA_CONFIG=''; fi

script:
- php -r "echo phpversion() . PHP_EOL;"
- travis_wait composer update --prefer-lowest --no-interaction && php -d error_reporting=$(php -r "var_export(E_ALL & ~E_DEPRECATED);") vendor/bin/phpunit
- travis_wait composer update --no-interaction && vendor/bin/phpunit
- php ${EXTRA_CONFIG} -r "echo phpversion() . PHP_EOL;"

- if [ ${HHVM_PHP7+x} ]; then echo "Do not test the lowest dependencies on HHVM with PHP7 support"; else travis_wait composer update --prefer-lowest --no-interaction && php -d hhvm.jit=0 -d error_reporting=$(php -r "var_export(E_ALL & ~E_DEPRECATED);") vendor/bin/phpunit; fi
- travis_wait composer update --no-interaction && php -d hhvm.jit=0 ${EXTRA_CONFIG} vendor/bin/phpunit

after_script:
- mv ~.git .git
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.10.0

* Removed `Awesomite\StackTrace\Arguments\Values\MultipleValues`
* Added tests for HHVM with flag `hhvm.php7.all=1`
* `Awesomite\StackTrace\StackTrace::unserialize` throws `Awesomite\StackTrace\Exceptions\LogicException` instead of `LogicException`

## 0.9.2

* Fixed phpdoc for `Awesomite\StackTrace\Arguments\ArgumentsInterface::getIterator`
Expand Down
21 changes: 21 additions & 0 deletions bin/composer-set-config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env php
<?php

global $argv;

$handle = function ($scriptName, $key, $value) {
$jsonPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'composer.json';
$json = json_decode(file_get_contents($jsonPath), true);
if (!isset($json['config'])) {
$json['config'] = array();
}
$json['config'][$key] = $value;

$options = JSON_UNESCAPED_UNICODE;
if (defined('JSON_PRETTY_PRINT')) {
$options |= constant('JSON_PRETTY_PRINT');
}
file_put_contents($jsonPath, json_encode($json, $options));
};

call_user_func_array($handle, $argv);
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
}
},
"autoload-dev": {
"files": ["tests/hhvm-polyfill/exceptions.php.polyfill"],
"psr-4": {
"Awesomite\\StackTrace\\": "tests/"
}
},
"require": {
"php": "^5.3 || ^7.0",
"composer/semver": "^1.4.2",
"awesomite/var-dumper": "^0.6.1",
"awesomite/var-dumper": "^0.6.1 || ^0.7.0",
"awesomite/iterators": "^0.2.0"
},
"minimum-stability": "dev",
Expand All @@ -33,7 +34,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "0.9-dev"
"dev-master": "0.10-dev"
}
}
}
7 changes: 0 additions & 7 deletions src/Arguments/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Awesomite\StackTrace\Arguments;

use Awesomite\StackTrace\Arguments\Declarations\Declaration;
use Awesomite\StackTrace\Arguments\Values\MultipleValues;
use Awesomite\StackTrace\Arguments\Values\ValueInterface;
use Awesomite\StackTrace\Functions\FunctionInterface;

Expand Down Expand Up @@ -42,12 +41,6 @@ public function getIterator()
foreach ($this->function->getReflection()->getParameters() as $parameter) {
$declaration = new Declaration($parameter);

if ($declaration->isVariadic()) {
$result[] = new Argument($declaration, $arguments ? new MultipleValues($arguments) : null);
$arguments = array();
continue;
}

if ($arguments) {
$result[] = new Argument($declaration, array_shift($arguments));
continue;
Expand Down
67 changes: 0 additions & 67 deletions src/Arguments/Values/MultipleValues.php

This file was deleted.

70 changes: 45 additions & 25 deletions src/StackTrace.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Awesomite\Iterators\CallbackIterator;
use Awesomite\StackTrace\Arguments\Values\DeserializedValue;
use Awesomite\StackTrace\Arguments\Values\Value;
use Awesomite\StackTrace\Exceptions\LogicException;
use Awesomite\StackTrace\SourceCode\File;
use Awesomite\StackTrace\Steps\Step;
use Awesomite\StackTrace\Steps\StepInterface;
Expand All @@ -17,8 +18,8 @@
*/
class StackTrace implements StackTraceInterface
{
const VERSION = '0.9.2';
const CONSTRAINTS_VERSION = '>=0.1.0 <0.10.0';
const VERSION = '0.10.0';
const CONSTRAINTS_VERSION = '>=0.1.0 <0.11.0';

private $arrayStackTrace;

Expand Down Expand Up @@ -92,7 +93,7 @@ public function unserialize($serialized)
$data = unserialize($serialized);
if (!Semver::satisfies($data['__version'], static::CONSTRAINTS_VERSION)) {
$message = 'Cannot use incompatible version to unserialize stack trace (serialized by: %s, current: %s).';
throw new \LogicException(sprintf($message, $data['__version'], static::VERSION));
throw new LogicException(sprintf($message, $data['__version'], static::VERSION));
}
$this->arrayStackTrace = $data['steps'];
$this->unserialized = true;
Expand Down Expand Up @@ -160,32 +161,38 @@ public function setVarDumper(VarDumperInterface $varDumper)
*/
public function convertStep(array $step, $toSerialize = false)
{
$result = array();
foreach ($step as $key => $value) {
$result[$key] = $value;
}

if ($this->withoutArgs) {
$result['args'] = array();
} else if (empty($result[Constants::KEY_ARGS_CONVERTED]) && isset($result['args'])) {
$result['args'] = $this->convertArgs($result['args']);
$result[Constants::KEY_ARGS_CONVERTED] = true;
$step['args'] = array();
} else if (empty($step[Constants::KEY_ARGS_CONVERTED]) && isset($step['args'])) {
$maxArgs = null;
if (version_compare(PHP_VERSION, '5.6') >= 0) {
$fakeStep = new Step($step);
$reflectionFn = $fakeStep->hasCalledFunction() && $fakeStep->getCalledFunction()->hasReflection()
? $fakeStep->getCalledFunction()->getReflection()
: null;
if (!is_null($reflectionFn) && $reflectionFn->isVariadic()) {
$maxArgs = count($reflectionFn->getParameters());
}
}

$step['args'] = $this->convertArgs($step['args'], $maxArgs);
$step[Constants::KEY_ARGS_CONVERTED] = true;
}

if (
!$toSerialize
&& !isset($result[Constants::KEY_FILE_OBJECT])
&& isset($result['file'])
&& isset($this->files[$result['file']])
&& !isset($step[Constants::KEY_FILE_OBJECT])
&& isset($step['file'])
&& isset($this->files[$step['file']])
) {
$result[Constants::KEY_FILE_OBJECT] = $this->files[$result['file']];
$step[Constants::KEY_FILE_OBJECT] = $this->files[$step['file']];
}

if (isset($result['object'])) {
unset($result['object']);
if (isset($step['object'])) {
unset($step['object']);
}

return $result;
return $step;
}

private function getVarDumper()
Expand All @@ -197,19 +204,32 @@ private function getVarDumper()
return $this->varDumper;
}

private function convertArgs(array $args)
/**
* @param array $inputArgs
* @param int|null $maxArgs
* @return array
*/
private function convertArgs(array $inputArgs, $maxArgs)
{
/**
* input has to be copied to different array,
* because array $args returned by debug_backtrace function contains references from PHP 7.0
* debug_backtrace()[$x]['args'] can contain references
*/
$result = array();
$args = array();
foreach ($inputArgs as $key => $value) {
$args[$key] = $value;
}

if (!is_null($maxArgs) && $maxArgs <= count($args)) {
$preparedCopy = $args;
$args = array_slice($preparedCopy, 0, $maxArgs - 1);
$args[] = array_slice($preparedCopy, $maxArgs - 1);
}

foreach ($args as $key => $value) {
$result[$key] = $this->convertArg($value);
$args[$key] = $this->convertArg($value);
}

return $result;
return $args;
}

private function convertArg($value)
Expand Down
30 changes: 27 additions & 3 deletions src/StackTraceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class StackTraceFactory
{
private static $rootExceptionClass = null;

/**
* @param int $stepLimit
* @param bool $ignoreArgs
Expand Down Expand Up @@ -45,14 +47,36 @@ public function create($stepLimit = 0, $ignoreArgs = false)
*/
public function createByThrowable($exception, $stepLimit = 0, $ignoreArgs = false)
{
$exceptionClass = version_compare(PHP_VERSION, '7.0') >= 0 ? '\Throwable' : '\Exception';
if (!$exception instanceof $exceptionClass) {
throw new InvalidArgumentException("Argument should be an instance of {$exceptionClass}!");
$exceptionClass = $this->getRootExceptionClass();
if (!is_object($exception) || !$exception instanceof $exceptionClass) {
throw new InvalidArgumentException(sprintf(
"Expected argument of type %s, %s given",
$exceptionClass,
is_object($exception) ? get_class($exception) : gettype($exception)
));
}

return $this->createBy($exception, $stepLimit, $ignoreArgs);
}

/**
* HHVM still does not support \Throwable interface
*
* @return null|string
*/
private function getRootExceptionClass()
{
if (is_null(self::$rootExceptionClass)) {
$reflection = new \ReflectionClass('\Exception');
$throwableExists = interface_exists('\Throwable', false);
self::$rootExceptionClass = $throwableExists && $reflection->implementsInterface('\Throwable')
? '\Throwable'
: '\Exception';
}

return self::$rootExceptionClass;
}

/**
* @param \Exception|\Throwable $exception
* @param int $stepLimit
Expand Down
3 changes: 2 additions & 1 deletion tests/Arguments/ArgumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ArgumentsTest extends BaseTestCase
public function testAll(Arguments $arguments, $count)
{
$this->assertSame($count, count($arguments));
$this->assertSame(count($arguments), count(iterator_to_array($arguments)));
foreach ($arguments as $argument) {
$this->assertTrue($argument instanceof ArgumentInterface);
}
Expand Down Expand Up @@ -60,7 +61,7 @@ private function providerVariadic()
));

return array(
$this->createByRawValues(array('1', '2', '3'), $function),
$this->createByRawValues(array(array('1', '2', '3')), $function),
1
);
}
Expand Down
Loading