Skip to content

Fix Closure Error #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "codespaces-laravel",
"dockerComposeFile": ["docker-compose.yml"],
"workspaceFolder": "/workspace",
"service": "app",
"shutdownAction": "stopCompose",
"extensions": [
"editorconfig.editorconfig",
"ryannaddy.laravel-artisan",
"amiralizadeh9480.laravel-extra-intellisense",
"stef-k.laravel-goto-controller",
"codingyu.laravel-goto-view",
"mikestead.dotenv",
"eg2.tslint",
"christian-kohler.path-intellisense",
"esbenp.prettier-vscode",
"CoenraadS.bracket-pair-colorizer"
],
"settings": {
"#terminal.integrated.shell.linux": "/bin/bash"
},
"postCreateCommand": "cp .env.example .env && composer install",
}
32 changes: 32 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3"
services:
app:
build: ./docker/app
volumes:
- ../:/workspace:cached
ports:
- 80:80
tty: true
environment:
APP_ENV: local
PHP_EXTENSION_XDEBUG: 1
PHP_EXTENSION_PGSQL: 1
PHP_EXTENSION_PDO_PGSQL: 1
APACHE_DOCUMENT_ROOT: /workspace/public
db:
image: postgres:13
restart: unless-stopped
ports:
- 5432:5432
environment:
POSTGRES_DB: laravel
POSTGRES_USER: laravel
POSTGRES_PASSWORD: laravel
redis:
image: redis:6-alpine
ports:
- 6379:6379
mailhog:
image: mailhog/mailhog
ports:
- 8025:8025
4 changes: 4 additions & 0 deletions .devcontainer/docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG PHP_EXTENSIONS="mysqli pgsql pdo_mysql pdo_pgsql"

FROM thecodingmachine/php:8.1-v4-apache-node12
WORKDIR /workspace
13 changes: 13 additions & 0 deletions src/Serializers/Y.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Workflow\Serializers;

use Closure;
use Laravel\SerializableClosure\SerializableClosure;
use Throwable;

final class Y implements SerializerInterface
{
Expand Down Expand Up @@ -40,6 +42,17 @@ public static function decode(string $data): string
public static function serialize($data): string
{
SerializableClosure::setSecretKey(config('app.key'));
if ($data instanceof Throwable) {
$data = [
'class' => get_class($data),
'message' => $data->getMessage(),
'code' => $data->getCode(),
'line' => $data->getLine(),
'trace' => collect($data->getTrace())
->filter(static fn ($trace) => $trace instanceof Closure)
->toArray(),
];
}
return self::encode(serialize(new SerializableClosure(static fn () => $data)));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/ExceptionWorkflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testRetry(): void
$this->assertSame(WorkflowCompletedStatus::class, $workflow->status());
$this->assertSame('workflow_activity_other', $workflow->output());
if ($workflow->exceptions()->first()) {
$this->assertSame('failed', Y::unserialize($workflow->exceptions()->first()->exception)->getMessage());
$this->assertSame('failed', Y::unserialize($workflow->exceptions()->first()->exception)['message']);
}
}
}
16 changes: 15 additions & 1 deletion tests/Unit/Serializers/SerializeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

namespace Tests\Unit\Serializers;

use Closure;
use Tests\Fixtures\TestEnum;
use Tests\TestCase;
use Throwable;
use Workflow\Serializers\Y;

final class SerializeTest extends TestCase
Expand All @@ -17,7 +19,19 @@ public function testSerialize($data): void
{
$unserialized = Y::unserialize(Y::serialize($data));
if (is_object($data)) {
$this->assertEqualsCanonicalizing($data, $unserialized);
if ($data instanceof Throwable) {
$this->assertEquals([
'class' => get_class($data),
'message' => $data->getMessage(),
'code' => $data->getCode(),
'line' => $data->getLine(),
'trace' => collect($data->getTrace())
->filter(static fn ($trace) => $trace instanceof Closure)
->toArray(),
], $unserialized);
} else {
$this->assertEqualsCanonicalizing($data, $unserialized);
}
} else {
$this->assertSame($data, $unserialized);
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy