Skip to content

Commit

Permalink
Merge pull request #148 from treehousetim/master
Browse files Browse the repository at this point in the history
Exception line/file of where thrown plus add shortcut to composer for running tests with `composer test
  • Loading branch information
Deacon-McIntyre committed May 12, 2022
2 parents 677b684 + a502afd commit ab31a7c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Composer test on push and pull

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress

# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md

- name: Run test suite
run: composer test
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"test": ["phpunit"]
}
}
12 changes: 12 additions & 0 deletions src/Raygun4php/RaygunExceptionMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,21 @@ public function __construct($exception)
}
}

private function getExceptionLine( $exceptionOrErrorException )
{
$line = new RaygunExceptionTraceLineMessage();
$line->FileName = $exceptionOrErrorException->getFile();
$line->LineNumber = $exceptionOrErrorException->getLine();
return $line;
}

private function BuildErrorTrace($error)
{
$traces = $error->getTrace();
$lines = array();

$lines[] = $this->getExceptionLine( $error );

foreach ($traces as $trace) {
$line = new RaygunExceptionTraceLineMessage();

Expand Down Expand Up @@ -79,6 +89,8 @@ private function BuildStackTrace($exception)
$traces = $exception->getTrace();
$lines = array();

$lines[] = $this->getExceptionLine( $exception );

foreach ($traces as $trace) {
$lines[] = $this->BuildLine($trace);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/RaygunMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ public function testBuildMessageWithException()
$this->assertEquals($msg->Details->Error->Message, 'Exception: test');
}

public function testFirstStackTraceLineIsNotNull()
{
$msg = new RaygunMessage();

$msg->build(new \Exception('test'));
$line = __LINE__ - 1;
$file = __FILE__;

$this->assertNotNull( $msg->Details->Error->StackTrace[0] );
$this->assertEquals( $msg->Details->Error->StackTrace[0]->LineNumber, $line );
$this->assertEquals( $msg->Details->Error->StackTrace[0]->FileName, $file );
}

public function testBuildMessageWithNestedException()
{
$msg = new RaygunMessage();
Expand Down

0 comments on commit ab31a7c

Please sign in to comment.