From b05f2ca03f1dabc35f6b358e081fcc6246b8acec Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Nedelcu Date: Mon, 15 Apr 2019 11:27:02 +0200 Subject: [PATCH 1/7] Added check for both class and function --- src/Stacktrace.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Stacktrace.php b/src/Stacktrace.php index cf0e68e46..c6ecaf390 100644 --- a/src/Stacktrace.php +++ b/src/Stacktrace.php @@ -115,8 +115,10 @@ public function addFrame(string $file, int $line, array $backtraceFrame): void $line = (int) $matches[2]; } - if (isset($backtraceFrame['class'])) { + if (isset($backtraceFrame['class']) && isset($backtraceFrame['function'])) { $functionName = sprintf('%s::%s', $backtraceFrame['class'], $backtraceFrame['function']); + } elseif (isset($backtraceFrame['class'])) { + $functionName = $backtraceFrame['class']; } elseif (isset($backtraceFrame['function'])) { $functionName = $backtraceFrame['function']; } else { From 74b236d440cf63c0e14c758ac89458f04d86c6d8 Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Nedelcu Date: Mon, 15 Apr 2019 11:36:30 +0200 Subject: [PATCH 2/7] Added new branch as alias for 2.0.x-dev --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f6872b8f2..3c631e6ba 100644 --- a/composer.json +++ b/composer.json @@ -69,7 +69,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.0.x-dev", + "dev-fix-undefined-index": "2.0.x-dev" } } } From cacfe6261e503babcc1a91f5fbc8ba8baa0eaa11 Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Nedelcu Date: Fri, 24 May 2019 15:10:53 +0200 Subject: [PATCH 3/7] Updated StacktraceTest to test also for the fix. --- .../Fixtures/backtraces/anonymous_frame.json | 5 +++- tests/Fixtures/backtraces/exception.json | 7 ++++- tests/Fixtures/frames/class.json | 5 ++++ tests/StacktraceTest.php | 27 ++++++++++++------- 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 tests/Fixtures/frames/class.json diff --git a/tests/Fixtures/backtraces/anonymous_frame.json b/tests/Fixtures/backtraces/anonymous_frame.json index 84eaa9898..d296a3ef5 100644 --- a/tests/Fixtures/backtraces/anonymous_frame.json +++ b/tests/Fixtures/backtraces/anonymous_frame.json @@ -6,10 +6,13 @@ "function": "triggerError", "class": "TestClass" }, + { + "class": "CrashyClass" + }, { "file": "path/to/file", "line": 7, "function": "call_user_func" } ] -} \ No newline at end of file +} diff --git a/tests/Fixtures/backtraces/exception.json b/tests/Fixtures/backtraces/exception.json index 543157330..82c2e4016 100644 --- a/tests/Fixtures/backtraces/exception.json +++ b/tests/Fixtures/backtraces/exception.json @@ -2,6 +2,11 @@ "file": "path/to/file", "line": 12, "backtrace": [ + { + "file": "path/to/file", + "line": 30, + "class": "CrashyClass" + }, { "file": "path/to/file", "function": "triggerError", @@ -15,4 +20,4 @@ "function": "crashyFunction" } ] -} \ No newline at end of file +} diff --git a/tests/Fixtures/frames/class.json b/tests/Fixtures/frames/class.json new file mode 100644 index 000000000..8168cfc92 --- /dev/null +++ b/tests/Fixtures/frames/class.json @@ -0,0 +1,5 @@ +{ + "file": "path/to/file", + "line": 12, + "class": "CrashyClass" +} diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index 7c5bd2849..947cb75f1 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -39,15 +39,17 @@ public function testGetFramesAndToArray(): void { $stacktrace = new Stacktrace($this->options, $this->serializer, $this->representationSerializer); - $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 1, 'function' => 'test_function']); - $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function', 'class' => 'TestClass']); + $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 2, 'class' => 'CrashyClass']); + $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 1, 'function' => 'test_function']); + $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function', 'class' => 'TestClass']); $frames = $stacktrace->getFrames(); - $this->assertCount(2, $frames); + $this->assertCount(3, $frames); $this->assertEquals($frames, $stacktrace->toArray()); - $this->assertFrameEquals($frames[0], 'TestClass::test_function', 'path/to/file', 2); - $this->assertFrameEquals($frames[1], 'test_function', 'path/to/file', 1); + $this->assertFrameEquals($frames[0], 'TestClass::test_function', 'path/to/file', 3); + $this->assertFrameEquals($frames[1], 'test_function', 'path/to/file', 2); + $this->assertFrameEquals($frames[2], 'CrashyClass', 'path/to/file', 1); } public function testStacktraceJsonSerialization(): void @@ -56,6 +58,7 @@ public function testStacktraceJsonSerialization(): void $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 1, 'function' => 'test_function']); $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function', 'class' => 'TestClass']); + $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 2, 'class' => 'CrashyClass']); $frames = json_encode($stacktrace->getFrames()); $serializedStacktrace = json_encode($stacktrace); @@ -72,6 +75,7 @@ public function testAddFrame(): void $this->getJsonFixture('frames/eval.json'), $this->getJsonFixture('frames/runtime_created.json'), $this->getJsonFixture('frames/function.json'), + $this->getJsonFixture('frames/class.json'), ]; foreach ($frames as $frame) { @@ -80,10 +84,11 @@ public function testAddFrame(): void $frames = $stacktrace->getFrames(); - $this->assertCount(3, $frames); - $this->assertFrameEquals($frames[0], 'TestClass::test_function', 'path/to/file', 12); - $this->assertFrameEquals($frames[1], 'test_function', 'path/to/file', 12); + $this->assertCount(4, $frames); + $this->assertFrameEquals($frames[0], 'CrashyClass', 'path/to/file', 12); + $this->assertFrameEquals($frames[1], 'TestClass::test_function', 'path/to/file', 12); $this->assertFrameEquals($frames[2], 'test_function', 'path/to/file', 12); + $this->assertFrameEquals($frames[3], 'test_function', 'path/to/file', 12); } public function testAddFrameSerializesMethodArguments(): void @@ -227,7 +232,8 @@ public function testFromBacktrace(): void $this->assertFrameEquals($frames[0], null, 'path/to/file', 16); $this->assertFrameEquals($frames[1], 'TestClass::crashyFunction', 'path/to/file', 7); - $this->assertFrameEquals($frames[2], 'TestClass::triggerError', 'path/to/file', 12); + $this->assertFrameEquals($frames[2], 'TestClass::triggerError', 'path/to/file', 30); + $this->assertFrameEquals($frames[3], 'CrashyClass', 'path/to/file', 12); } public function testFromBacktraceWithAnonymousFrame(): void @@ -237,7 +243,8 @@ public function testFromBacktraceWithAnonymousFrame(): void $this->assertFrameEquals($frames[0], null, 'path/to/file', 7); $this->assertFrameEquals($frames[1], 'call_user_func', '[internal]', 0); - $this->assertFrameEquals($frames[2], 'TestClass::triggerError', 'path/to/file', 12); + $this->assertFrameEquals($frames[2], 'CrashyClass', '[internal]', 0); + $this->assertFrameEquals($frames[3], 'TestClass::triggerError', 'path/to/file', 12); } public function testInAppWithEmptyFrame(): void From bc48740a4ae8a937823eddf151f62775cf5da0cb Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Nedelcu Date: Wed, 29 May 2019 08:43:43 +0200 Subject: [PATCH 4/7] Removed the extra alias added for 2.0.x-dev --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3c631e6ba..f6872b8f2 100644 --- a/composer.json +++ b/composer.json @@ -69,8 +69,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev", - "dev-fix-undefined-index": "2.0.x-dev" + "dev-master": "2.0.x-dev" } } } From 5bdf708ea36418f6b15251cda14746c48f6f6d36 Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Nedelcu Date: Wed, 26 Jun 2019 09:15:13 +0200 Subject: [PATCH 5/7] Implemented changes requested in pull request. --- tests/Fixtures/backtraces/anonymous_frame.json | 3 --- tests/Fixtures/backtraces/exception.json | 5 ----- .../frames/{class.json => missing_function_key.json} | 2 +- tests/StacktraceTest.php | 12 +++++------- 4 files changed, 6 insertions(+), 16 deletions(-) rename tests/Fixtures/frames/{class.json => missing_function_key.json} (64%) diff --git a/tests/Fixtures/backtraces/anonymous_frame.json b/tests/Fixtures/backtraces/anonymous_frame.json index d296a3ef5..2f450a5db 100644 --- a/tests/Fixtures/backtraces/anonymous_frame.json +++ b/tests/Fixtures/backtraces/anonymous_frame.json @@ -6,9 +6,6 @@ "function": "triggerError", "class": "TestClass" }, - { - "class": "CrashyClass" - }, { "file": "path/to/file", "line": 7, diff --git a/tests/Fixtures/backtraces/exception.json b/tests/Fixtures/backtraces/exception.json index 82c2e4016..f371c73e5 100644 --- a/tests/Fixtures/backtraces/exception.json +++ b/tests/Fixtures/backtraces/exception.json @@ -2,11 +2,6 @@ "file": "path/to/file", "line": 12, "backtrace": [ - { - "file": "path/to/file", - "line": 30, - "class": "CrashyClass" - }, { "file": "path/to/file", "function": "triggerError", diff --git a/tests/Fixtures/frames/class.json b/tests/Fixtures/frames/missing_function_key.json similarity index 64% rename from tests/Fixtures/frames/class.json rename to tests/Fixtures/frames/missing_function_key.json index 8168cfc92..898b752e7 100644 --- a/tests/Fixtures/frames/class.json +++ b/tests/Fixtures/frames/missing_function_key.json @@ -1,5 +1,5 @@ { "file": "path/to/file", "line": 12, - "class": "CrashyClass" + "class": "TestClass" } diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index 947cb75f1..74e0abdb4 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -58,7 +58,7 @@ public function testStacktraceJsonSerialization(): void $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 1, 'function' => 'test_function']); $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function', 'class' => 'TestClass']); - $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 2, 'class' => 'CrashyClass']); + $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 2, 'class' => 'TestClass']); $frames = json_encode($stacktrace->getFrames()); $serializedStacktrace = json_encode($stacktrace); @@ -75,7 +75,7 @@ public function testAddFrame(): void $this->getJsonFixture('frames/eval.json'), $this->getJsonFixture('frames/runtime_created.json'), $this->getJsonFixture('frames/function.json'), - $this->getJsonFixture('frames/class.json'), + $this->getJsonFixture('frames/missing_function_key.json'), ]; foreach ($frames as $frame) { @@ -85,7 +85,7 @@ public function testAddFrame(): void $frames = $stacktrace->getFrames(); $this->assertCount(4, $frames); - $this->assertFrameEquals($frames[0], 'CrashyClass', 'path/to/file', 12); + $this->assertFrameEquals($frames[0], 'TestClass', 'path/to/file', 12); $this->assertFrameEquals($frames[1], 'TestClass::test_function', 'path/to/file', 12); $this->assertFrameEquals($frames[2], 'test_function', 'path/to/file', 12); $this->assertFrameEquals($frames[3], 'test_function', 'path/to/file', 12); @@ -232,8 +232,7 @@ public function testFromBacktrace(): void $this->assertFrameEquals($frames[0], null, 'path/to/file', 16); $this->assertFrameEquals($frames[1], 'TestClass::crashyFunction', 'path/to/file', 7); - $this->assertFrameEquals($frames[2], 'TestClass::triggerError', 'path/to/file', 30); - $this->assertFrameEquals($frames[3], 'CrashyClass', 'path/to/file', 12); + $this->assertFrameEquals($frames[2], 'TestClass::triggerError', 'path/to/file', 12); } public function testFromBacktraceWithAnonymousFrame(): void @@ -243,8 +242,7 @@ public function testFromBacktraceWithAnonymousFrame(): void $this->assertFrameEquals($frames[0], null, 'path/to/file', 7); $this->assertFrameEquals($frames[1], 'call_user_func', '[internal]', 0); - $this->assertFrameEquals($frames[2], 'CrashyClass', '[internal]', 0); - $this->assertFrameEquals($frames[3], 'TestClass::triggerError', 'path/to/file', 12); + $this->assertFrameEquals($frames[2], 'TestClass::triggerError', 'path/to/file', 12); } public function testInAppWithEmptyFrame(): void From 8bec8404dcc9cb927f50d869c2b009bfb8f7d47a Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Nedelcu Date: Wed, 31 Jul 2019 15:00:39 +0200 Subject: [PATCH 6/7] Removed elseif for only class index. Changed StacktraceTest according to requested changes. --- src/Stacktrace.php | 2 -- tests/StacktraceTest.php | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Stacktrace.php b/src/Stacktrace.php index c6ecaf390..370bfe9ae 100644 --- a/src/Stacktrace.php +++ b/src/Stacktrace.php @@ -117,8 +117,6 @@ public function addFrame(string $file, int $line, array $backtraceFrame): void if (isset($backtraceFrame['class']) && isset($backtraceFrame['function'])) { $functionName = sprintf('%s::%s', $backtraceFrame['class'], $backtraceFrame['function']); - } elseif (isset($backtraceFrame['class'])) { - $functionName = $backtraceFrame['class']; } elseif (isset($backtraceFrame['function'])) { $functionName = $backtraceFrame['function']; } else { diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index 74e0abdb4..f75e78547 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -39,9 +39,9 @@ public function testGetFramesAndToArray(): void { $stacktrace = new Stacktrace($this->options, $this->serializer, $this->representationSerializer); - $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 2, 'class' => 'CrashyClass']); - $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 1, 'function' => 'test_function']); - $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function', 'class' => 'TestClass']); + $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 1, 'class' => 'CrashyClass']); + $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function']); + $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 3, 'function' => 'test_function', 'class' => 'TestClass']); $frames = $stacktrace->getFrames(); @@ -58,7 +58,7 @@ public function testStacktraceJsonSerialization(): void $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 1, 'function' => 'test_function']); $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function', 'class' => 'TestClass']); - $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 2, 'class' => 'TestClass']); + $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 3, 'class' => 'TestClass']); $frames = json_encode($stacktrace->getFrames()); $serializedStacktrace = json_encode($stacktrace); From 715387ac0fdbc501c9ab46d42ce0b81a26f5d77d Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Nedelcu Date: Wed, 31 Jul 2019 15:11:47 +0200 Subject: [PATCH 7/7] Updated test to work without the elseif case. --- tests/StacktraceTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/StacktraceTest.php b/tests/StacktraceTest.php index f75e78547..08222be4a 100644 --- a/tests/StacktraceTest.php +++ b/tests/StacktraceTest.php @@ -39,7 +39,7 @@ public function testGetFramesAndToArray(): void { $stacktrace = new Stacktrace($this->options, $this->serializer, $this->representationSerializer); - $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 1, 'class' => 'CrashyClass']); + $stacktrace->addFrame('path/to/file', 1, ['file' => 'path/to/file', 'line' => 1, 'class' => 'TestClass']); $stacktrace->addFrame('path/to/file', 2, ['file' => 'path/to/file', 'line' => 2, 'function' => 'test_function']); $stacktrace->addFrame('path/to/file', 3, ['file' => 'path/to/file', 'line' => 3, 'function' => 'test_function', 'class' => 'TestClass']); @@ -49,7 +49,7 @@ public function testGetFramesAndToArray(): void $this->assertEquals($frames, $stacktrace->toArray()); $this->assertFrameEquals($frames[0], 'TestClass::test_function', 'path/to/file', 3); $this->assertFrameEquals($frames[1], 'test_function', 'path/to/file', 2); - $this->assertFrameEquals($frames[2], 'CrashyClass', 'path/to/file', 1); + $this->assertFrameEquals($frames[2], null, 'path/to/file', 1); } public function testStacktraceJsonSerialization(): void @@ -85,7 +85,7 @@ public function testAddFrame(): void $frames = $stacktrace->getFrames(); $this->assertCount(4, $frames); - $this->assertFrameEquals($frames[0], 'TestClass', 'path/to/file', 12); + $this->assertFrameEquals($frames[0], null, 'path/to/file', 12); $this->assertFrameEquals($frames[1], 'TestClass::test_function', 'path/to/file', 12); $this->assertFrameEquals($frames[2], 'test_function', 'path/to/file', 12); $this->assertFrameEquals($frames[3], 'test_function', 'path/to/file', 12);