Skip to content

Commit

Permalink
[player] ensure last jsonview is sent when last step of the last scen…
Browse files Browse the repository at this point in the history
…ario errored
  • Loading branch information
julien-jean committed Jan 13, 2025
1 parent acb984b commit d0263d9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Player/Extension/BlackfireExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public function afterStep(AbstractStep $step, StepContext $stepContext, Scenario

$parentStep = $step->getInitiator();
$profile = $this->blackfire->getProfile($uuid);
// Initialize profile data by calling getUrl()
$profile->getUrl();

$parentStep->setBlackfireProfileUuid($uuid);
$this->assertProfile($parentStep, $profile);
}
Expand Down
16 changes: 16 additions & 0 deletions Player/Extension/ProcessedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Blackfire Player package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Blackfire\Player\Extension;

class ProcessedException extends \RuntimeException
{
}
17 changes: 13 additions & 4 deletions Player/PlayerNext.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Blackfire\Player\Enum\BuildStatus;
use Blackfire\Player\Extension\ExceptionExtensionInterface;
use Blackfire\Player\Extension\NextStepExtensionInterface;
use Blackfire\Player\Extension\ProcessedException;
use Blackfire\Player\Extension\ScenarioExtensionInterface;
use Blackfire\Player\Extension\ScenarioSetExtensionInterface;
use Blackfire\Player\Extension\StepExtensionInterface;
Expand Down Expand Up @@ -122,10 +123,8 @@ private function handleScenario(int|string $index, Scenario $scenario, ScenarioS
);
} catch (\Throwable $e) {
$exception = $e;
foreach ($this->getSortedExtensions() as $extension) {
if ($extension instanceof ExceptionExtensionInterface) {
$extension->failStep($this->currentStep, $e);
}
if ($e instanceof ProcessedException) {
$exception = $e->getPrevious();
}
}

Expand Down Expand Up @@ -211,6 +210,16 @@ private function handleStep(ConfigurableStep $step, StepContext $stepContext, Sc
}
}
}
} catch (ProcessedException $exception) {
throw $exception;
} catch (\Throwable $exception) {
foreach ($this->getSortedExtensions() as $extension) {
if ($extension instanceof ExceptionExtensionInterface) {
$extension->failStep($this->currentStep, $exception);
}
}

throw new ProcessedException($exception->getMessage(), $exception->getCode(), $exception);
} finally {
$step->setStatus(BuildStatus::DONE);

Expand Down
11 changes: 10 additions & 1 deletion Player/Tests/Adapter/StubbedSdkAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ public function getProfile(string $uuid): Profile
return ($this->profileFactory)($uuid);
}

return new Profile(fn () => ['report' => ['state' => 'successful']], $uuid);
return new Profile(fn () => [
'report' => [
'state' => 'successful',
],
'_links' => [
'graph_url' => [
'href' => \sprintf('https://app.blackfire.io/profiles/%s/graph', $uuid),
],
],
], $uuid);
}

public function startBuild(string|null $env = null, array $options = []): Build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
],
],
],
'_links' => [
'graph_url' => [
'href' => sprintf('https://app.blackfire.io/profiles/%s/graph', $uuid),
],
],
], $uuid);
}
);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ext-filter": "*",
"ext-intl": "*",
"ext-mbstring": "*",
"blackfire/php-sdk": "^2.1 ",
"blackfire/php-sdk": "^2.5",
"fakerphp/faker": "^1.10",
"maltyxx/images-generator": "^1.0",
"mtdowling/jmespath.php": "^2.2",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d0263d9

Please sign in to comment.