Skip to content

Commit

Permalink
Merge branch 'master' into no-external-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 24, 2019
2 parents 2731e12 + 1d2103a commit c2174e6
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Expand Up @@ -13,3 +13,5 @@
/yarn.lock export-ignore
/package-lock.json export-ignore
/CONTRIBUTING.md export-ignore
/resources/js export-ignore
/resources/css export-ignore
17 changes: 16 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,10 +2,25 @@

All notable changes to `ignition` will be documented in this file

## 1.11.3 - 2019-10-21
## 1.13.1 - 2019-10-21

- Remove external reference for icons (#134)

## 1.13.0 - 2019-11-27

- Allow custom grouping types

## 1.12.1 - 2019-11-25

- Detect multibyte position offsets when adding linenumbers to the blade view - Fixes #193

## 1.12.0 - 2019-11-14

- Add exception to html (#206)
- Add a clear exception when passing no parameters to ddd (#205)
- Ignore JS tests (#215)
- Fix share report route bug

## 1.11.2 - 2019-10-13

- simplify default Laravel installation (#198)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -13,7 +13,7 @@
"php": "^7.1",
"ext-json": "*",
"ext-mbstring": "*",
"facade/flare-client-php": "^1.1",
"facade/flare-client-php": "^1.3",
"facade/ignition-contracts": "^1.0",
"filp/whoops": "^2.4",
"illuminate/support": "~5.5.0 || ~5.6.0 || ~5.7.0 || ~5.8.0 || ^6.0",
Expand Down
1 change: 1 addition & 0 deletions config/flare.php
Expand Up @@ -31,6 +31,7 @@
'maximum_number_of_collected_queries' => 200,
'report_query_bindings' => true,
'report_view_data' => true,
'grouping_type' => null,
],

/*
Expand Down
3 changes: 3 additions & 0 deletions resources/views/errorPage.php
@@ -1,5 +1,8 @@
<!doctype html>
<html class="theme-<?=$config['theme']?>">
<!--
<?=$throwableString?>
-->
<head>
<!-- Hide dumps asap -->
<style>
Expand Down
10 changes: 7 additions & 3 deletions src/ErrorPage/ErrorPageViewModel.php
Expand Up @@ -109,10 +109,14 @@ public function solutions(): array
return $solutions;
}

protected function shareEndpoint()
protected function shareEndpoint(): string
{
// use string notation as L5.5 and L5.6 don't support array notation yet
return action('\Facade\Ignition\Http\Controllers\ShareReportController');
try {
// use string notation as L5.5 and L5.6 don't support array notation yet
return action('\Facade\Ignition\Http\Controllers\ShareReportController');
} catch (Exception $exception) {
return '';
}
}

public function report(): array
Expand Down
4 changes: 4 additions & 0 deletions src/IgnitionConfig.php
Expand Up @@ -37,6 +37,10 @@ public function getTheme(): ?string

public function getEnableShareButton(): bool
{
if (! app()->isBooted()) {
return false;
}

return Arr::get($this->options, 'enable_share_button', true);
}

Expand Down
5 changes: 5 additions & 0 deletions src/IgnitionServiceProvider.php
Expand Up @@ -28,6 +28,7 @@
use Facade\Ignition\DumpRecorder\DumpRecorder;
use Facade\Ignition\Middleware\SetNotifierName;
use Facade\Ignition\QueryRecorder\QueryRecorder;
use Facade\Ignition\Middleware\CustomizeGrouping;
use Facade\Ignition\Commands\SolutionMakeCommand;
use Facade\Ignition\Middleware\AddGitInformation;
use Facade\Ignition\Views\Engines\CompilerEngine;
Expand Down Expand Up @@ -332,6 +333,10 @@ protected function registerBuiltInMiddleware()
$middleware[] = (new AddGitInformation());
}

if (! is_null(config('flare.reporting.grouping_type'))) {
$middleware[] = new CustomizeGrouping(config('flare.reporting.grouping_type'));
}

foreach ($middleware as $singleMiddleware) {
$this->app->get('flare.client')->registerMiddleware($singleMiddleware);
}
Expand Down
27 changes: 27 additions & 0 deletions src/Middleware/CustomizeGrouping.php
@@ -0,0 +1,27 @@
<?php

namespace Facade\Ignition\Middleware;

use Facade\FlareClient\Report;
use Facade\FlareClient\Enums\GroupingTypes;

class CustomizeGrouping
{
protected $groupingType;

public function __construct($groupingType)
{
$this->groupingType = $groupingType;
}

public function handle(Report $report, $next)
{
$report->groupByTopFrame();

if ($this->groupingType === GroupingTypes::EXCEPTION) {
$report->groupByException();
}

return $next($report);
}
}
20 changes: 14 additions & 6 deletions src/Views/Compilers/BladeSourceMapCompiler.php
Expand Up @@ -38,13 +38,17 @@ protected function getExceptionLineOffset(): int

public function compileString($value)
{
$value = $this->addEchoLineNumbers($value);
try {
$value = $this->addEchoLineNumbers($value);

$value = $this->addStatementLineNumbers($value);
$value = $this->addStatementLineNumbers($value);

$value = parent::compileString($value);
$value = parent::compileString($value);

return $this->trimEmptyLines($value);
return $this->trimEmptyLines($value);
} catch (\Exception $e) {
return $value;
}
}

protected function addEchoLineNumbers(string $value)
Expand All @@ -53,7 +57,9 @@ protected function addEchoLineNumbers(string $value)

if (preg_match_all($pattern, $value, $matches, PREG_OFFSET_CAPTURE)) {
foreach (array_reverse($matches[0]) as $match) {
$value = $this->insertLineNumberAtPosition($match[1], $value);
$position = mb_strlen(substr($value, 0, $match[1]));

$value = $this->insertLineNumberAtPosition($position, $value);
}
}

Expand All @@ -71,7 +77,9 @@ protected function addStatementLineNumbers(string $value)

if ($shouldInsertLineNumbers) {
foreach (array_reverse($matches[0]) as $match) {
$value = $this->insertLineNumberAtPosition($match[1], $value);
$position = mb_strlen(substr($value, 0, $match[1]));

$value = $this->insertLineNumberAtPosition($position, $value);
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/helpers.php
Expand Up @@ -4,6 +4,12 @@
function ddd()
{
$args = func_get_args();

if (count($args) === 0)
{
throw new Exception("You should pass at least 1 argument to `ddd`");
}

call_user_func_array('dump', $args);

$handler = app(\Facade\Ignition\ErrorPage\ErrorPageHandler::class);
Expand Down
14 changes: 14 additions & 0 deletions tests/DddTest.php
@@ -0,0 +1,14 @@
<?php

namespace Facade\Ignition\Tests;

class DddTest extends TestCase
{
/** @test */
public function using_ddd_without_an_argument_will_throw_its_own_exception()
{
$this->expectExceptionMessage('You should pass at least 1 argument to `ddd`');

ddd();
}
}
17 changes: 17 additions & 0 deletions tests/ErrorPageViewModelTest.php
Expand Up @@ -26,4 +26,21 @@ public function it_can_encode_invalid_user_data()

$this->assertNotEmpty($model->jsonEncode($report->toArray()));
}

/** @test */
public function it_disables_share_report_when_share_report_controller_action_is_not_defined()
{
$flareClient = $this->app->make('flare.client');

$exception = new \Exception('Test Exception');

/** @var Report $report */
$report = $flareClient->createReport($exception);

$model = new ErrorPageViewModel($exception, new IgnitionConfig([]), $report, []);

$result = $model->toArray();

$this->assertEquals('', $result['shareEndpoint']);
}
}
19 changes: 19 additions & 0 deletions tests/IgnitionConfigTest.php
Expand Up @@ -3,6 +3,7 @@
namespace Facade\Ignition\Tests;

use Facade\Ignition\IgnitionConfig;
use Illuminate\Container\Container;

class IgnitionConfigTest extends TestCase
{
Expand Down Expand Up @@ -37,4 +38,22 @@ public function it_prioritizes_config_value_over_debug_mode()

$this->assertFalse($config->getEnableRunnableSolutions());
}

/** @test */
public function it_disables_share_report_when_app_has_not_finished_booting()
{
// Create an app but don't run the bootstrappers, so it is in booting state
$bootingApp = $this->resolveApplication();
$this->resolveApplicationBindings($bootingApp);
$this->resolveApplicationExceptionHandler($bootingApp);
$this->resolveApplicationCore($bootingApp);
$this->resolveApplicationConfiguration($bootingApp);
$this->resolveApplicationHttpKernel($bootingApp);
$this->resolveApplicationConsoleKernel($bootingApp);
Container::setInstance($bootingApp);

$config = new IgnitionConfig([]);

$this->assertFalse($config->getEnableShareButton());
}
}
10 changes: 10 additions & 0 deletions tests/ViewTest.php
Expand Up @@ -37,6 +37,16 @@ public function it_detects_the_original_line_number_in_view_exceptions()
}
}

/** @test */
public function it_detects_the_original_line_number_in_view_exceptions_with_utf8_characters()
{
try {
view('blade-exception-utf8')->render();
} catch (ViewException $exception) {
$this->assertSame(11, $exception->getLine());
}
}

/** @test */
public function it_adds_additional_blade_information_to_the_exception()
{
Expand Down
19 changes: 19 additions & 0 deletions tests/stubs/views/blade-exception-utf8.blade.php
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Laravel</title>
</head>
<body>
àààààààà
{{ throw new Exception }}
àààààààà
<ul>
@foreach ([1, 2, 3] as $i => $test)
<li>{{ $test }}</li>
@endforeach
</ul>
</body>
</html>

0 comments on commit c2174e6

Please sign in to comment.