Skip to content

Commit

Permalink
Merge pull request #277 from scoutapp/8.2.x-merge-up-into-8.3.x_F630ch6X
Browse files Browse the repository at this point in the history
Merge release 8.2.1 into 8.3.x
  • Loading branch information
asgrim authored Jul 4, 2022
2 parents 36e76b7 + 06f318b commit 33ea589
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ jobs:
run: "composer remove --dev symfony/* laravel/* --no-update --no-interaction"
- name: "Require framework ${{ matrix.laravel-version}}"
run: "composer require laravel/framework:${{ matrix.laravel-version}} --no-update --no-interaction --prefer-dist --prefer-stable"
- name: "Install spatie/laravel-ignition (if available)"
if: ${{ (matrix.php-version == '8.0' || matrix.php-version == '8.1') && (matrix.laravel-version == '8.*' || matrix.laravel-version == '9.*') }}
run: "composer require --dev spatie/laravel-ignition --no-update --no-interaction"
- name: "Replace guzzlehttp/guzzle with php-http/guzzle6-adapter for PHP 7.1"
if: ${{ matrix.php-version == '7.1' }}
run: |
Expand Down
23 changes: 15 additions & 8 deletions known-issues.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.22.0@fc2c6ab4d5fa5d644d8617089f012f3bb84b8703">
<files psalm-version="4.24.0@06dd975cb55d36af80f242561738f16c5f58264f">
<file src="src/Agent.php">
<MixedArgument occurrences="10">
<MixedArgument occurrences="9">
<code>$config-&gt;get(ConfigKey::MONITORING_ENABLED)</code>
<code>$configuration-&gt;get(ConfigKey::IGNORED_ENDPOINTS)</code>
<code>$this-&gt;config-&gt;get(ConfigKey::APPLICATION_NAME)</code>
<code>$this-&gt;config-&gt;get(ConfigKey::APPLICATION_NAME)</code>
<code>$this-&gt;config-&gt;get(ConfigKey::CORE_AGENT_CONFIG_FILE)</code>
<code>$this-&gt;config-&gt;get(ConfigKey::CORE_AGENT_DOWNLOAD_URL)</code>
<code>$this-&gt;config-&gt;get(ConfigKey::CORE_AGENT_FULL_NAME)</code>
Expand All @@ -28,11 +27,6 @@
<code>$this-&gt;config-&gt;get(ConfigKey::MONITORING_ENABLED)</code>
</MixedReturnStatement>
</file>
<file src="src/Cache/DevNullCache.php">
<MixedArgumentTypeCoercion occurrences="1">
<code>$keysAsArray</code>
</MixedArgumentTypeCoercion>
</file>
<file src="src/Config.php">
<MixedArgumentTypeCoercion occurrences="1">
<code>$key</code>
Expand Down Expand Up @@ -335,6 +329,19 @@
</MixedAssignment>
</file>
<file src="tests/Unit/Laravel/View/Engine/ScoutViewEngineDecoratorTest.php">
<MixedArgument occurrences="1">
<code>BladeSourceMapCompiler::class</code>
</MixedArgument>
<MixedAssignment occurrences="1">
<code>$vem</code>
</MixedAssignment>
<MixedMethodCall occurrences="1">
<code>map</code>
</MixedMethodCall>
<UndefinedClass occurrences="2">
<code>BladeSourceMapCompiler</code>
<code>ViewException</code>
</UndefinedClass>
<UnusedClosureParam occurrences="4">
<code>$name</code>
<code>$name</code>
Expand Down
21 changes: 14 additions & 7 deletions src/Laravel/View/Engine/ScoutViewEngineDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@ final class ScoutViewEngineDecorator implements Engine
{
public const VIEW_FACTORY_SHARED_KEY = '__scout_apm_view_name';

/** @var Engine */
private $realEngine;
/**
* Note: property MUST be called `$engine` as package `spatie/laravel-ignition` makes assumptions about how
* implementors of {@see Engine} structure their classes.
*
* @link https://github.com/spatie/laravel-ignition/blob/d53075177ee0c710fbf588b8569f50435e1da054/src/Views/ViewExceptionMapper.php#L124-L130
*
* @var Engine
*/
private $engine;

/** @var ScoutApmAgent */
private $agent;

/** @var Factory */
private $viewFactory;

public function __construct(Engine $realEngine, ScoutApmAgent $agent, Factory $viewFactory)
public function __construct(Engine $engine, ScoutApmAgent $agent, Factory $viewFactory)
{
$this->realEngine = $realEngine;
$this->engine = $engine;
$this->agent = $agent;
$this->viewFactory = $viewFactory;
}
Expand All @@ -42,7 +49,7 @@ public function get($path, array $data = []): string
'View',
(string) $this->viewFactory->shared(self::VIEW_FACTORY_SHARED_KEY, 'unknown'),
function () use ($path, $data) {
return $this->realEngine->get($path, $data);
return $this->engine->get($path, $data);
}
);
}
Expand All @@ -55,9 +62,9 @@ function () use ($path, $data) {
*/
public function getCompiler(): CompilerInterface
{
assert(method_exists($this->realEngine, 'getCompiler'));
assert(method_exists($this->engine, 'getCompiler'));
/** @psalm-suppress UndefinedInterfaceMethod */
$compiler = $this->realEngine->getCompiler();
$compiler = $this->engine->getCompiler();
assert($compiler instanceof CompilerInterface);

return $compiler;
Expand Down
42 changes: 42 additions & 0 deletions tests/Unit/Laravel/View/Engine/ScoutViewEngineDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@

namespace Scoutapm\UnitTests\Laravel\View\Engine;

use Illuminate\Container\Container as ContainerSingleton;
use Illuminate\Contracts\Container\Container as ContainerInterface;
use Illuminate\Contracts\View\Engine;
use Illuminate\View\Compilers\CompilerInterface;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Factory as ViewFactory;
use Illuminate\View\ViewException;
use PHPUnit\Framework\Constraint\IsType;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Scoutapm\Laravel\View\Engine\ScoutViewEngineDecorator;
use Scoutapm\ScoutApmAgent;
use Spatie\LaravelIgnition\Views\BladeSourceMapCompiler;
use Spatie\LaravelIgnition\Views\ViewExceptionMapper;

use function class_exists;
use function uniqid;

/** @covers \Scoutapm\Laravel\View\Engine\ScoutViewEngineDecorator */
Expand Down Expand Up @@ -113,4 +120,39 @@ public function testGetCompilerWillProxyToRealEngineGetCompilerMethd(): void

self::assertSame($compiler, $this->viewEngineDecorator->getCompiler());
}

public function testSpatieLaravelIgnitionCompatibility(): void
{
if (! class_exists(ViewExceptionMapper::class)) {
self::markTestSkipped('Test depends on `spatie/laravel-ignition`, but it is not installed');
}

/**
* The `spatie/laravel-ignition` package depends on the engine having a property called `lastCompiled`, which
* only exists in the `\Illuminate\View\Engines\CompilerEngine` Blade Compiler. The implementation does sort of
* account for decoration, but it expects the property to be called `engine`. Therefore, in this test, we
* invoke the problematic consumer to ensure our decorated view engine conforms to this assumption.
*
* @link https://github.com/spatie/laravel-ignition/blob/d53075177ee0c710fbf588b8569f50435e1da054/src/Views/ViewExceptionMapper.php#L124-L130
*
* @noinspection PhpPossiblePolymorphicInvocationInspection PhpUndefinedFieldInspection
* @psalm-suppress NoInterfaceProperties
*/
$this->realEngine->lastCompiled = [];

$viewEngineResolver = new EngineResolver();
$viewEngineResolver->register('blade', function () {
return $this->viewEngineDecorator;
});

$fakeContainer = $this->createMock(ContainerInterface::class);
$fakeContainer->expects(self::once())
->method('make')
->with('view.engine.resolver')
->willReturn($viewEngineResolver);
ContainerSingleton::setInstance($fakeContainer);

$vem = new ViewExceptionMapper($this->createMock(BladeSourceMapCompiler::class));
$vem->map(new ViewException('things (View: paththing)'));
}
}

0 comments on commit 33ea589

Please sign in to comment.