Skip to content

Commit f884de9

Browse files
authored
Merge pull request #2 from beastbytes/no-step
Use Step::setData() to provide rendered view response to Wizard, and …
2 parents 1c92920 + 90228fc commit f884de9

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/Event/StepDataTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
trait StepDataTrait
1212
{
13-
private array $data = [];
13+
private mixed $data = null;
1414

15-
public function getData(): array
15+
public function getData(): mixed
1616
{
1717
return $this->data;
1818
}
@@ -22,7 +22,7 @@ public function hasData(): bool
2222
return !empty($this->data);
2323
}
2424

25-
public function setData(array $data): void
25+
public function setData(mixed $data): void
2626
{
2727
$this->data = $data;
2828
}

src/Wizard.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ public function step(ServerRequestInterface $request): ResponseInterface
175175
;
176176
}
177177

178-
return $this->createResponse($this->stepRoute, $this->getStepParameter());
178+
/** @psalm-return ResponseInterface */
179+
return $event->getData();
179180
}
180181

181182
public function withAutoAdvance(bool $autoAdvance): self

tests/WizardTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
use BeastBytes\Wizard\Exception\RuntimeException;
1717
use BeastBytes\Wizard\Wizard;
1818
use Generator;
19+
use HttpSoft\Message\Response;
1920
use HttpSoft\Message\ResponseFactory;
2021
use HttpSoft\Message\ServerRequest;
2122
use InvalidArgumentException;
2223
use PHPUnit\Framework\Attributes\DataProvider;
2324
use PHPUnit\Framework\TestCase;
2425
use ReflectionClass;
26+
use Yiisoft\DataResponse\DataResponse;
2527
use Yiisoft\EventDispatcher\Dispatcher\Dispatcher;
2628
use Yiisoft\EventDispatcher\Provider\ListenerCollection;
2729
use Yiisoft\EventDispatcher\Provider\Provider;
@@ -189,9 +191,7 @@ public function test_start_wizard(): void
189191
$steps,
190192
self::$session->get(Wizard::SESSION_KEY . '.' . Wizard::STEPS_KEY)
191193
);
192-
$this->assertSame(Status::FOUND, $result->getStatusCode());
193-
$this->assertTrue($result->hasHeader(Header::LOCATION));
194-
$this->assertSame([self::STEP_ROUTE_PATTERN], $result->getHeader(Header::LOCATION));
194+
$this->assertSame(Status::OK, $result->getStatusCode());
195195
}
196196

197197
/**
@@ -311,7 +311,7 @@ public function test_end_on_get(): void
311311
->step(new ServerRequest(method: Method::GET))
312312
;
313313

314-
if ($result->getHeader(Header::LOCATION) === [self::STEP_ROUTE_PATTERN]) {
314+
if ($this->events[AfterWizard::class] === 0) {
315315
$result = $this
316316
->wizard
317317
->step(new ServerRequest(method: Method::POST))
@@ -1218,10 +1218,6 @@ public function step(Step $event): void
12181218
{
12191219
$this->events[Step::class]++;
12201220

1221-
if ($event->getWizard()->getCurrentStep() === self::END_STEP && $this->endOnGet) {
1222-
$event->continue(false);
1223-
}
1224-
12251221
if ($event->getRequest()->getMethod() === Method::POST) {
12261222
$step = $event->getWizard()->getCurrentStep();
12271223
if ($step === self::REPEAT_STEP) {
@@ -1263,6 +1259,11 @@ public function step(Step $event): void
12631259
default:
12641260
break;
12651261
}
1262+
} else {
1263+
if ($this->endOnGet && $event->getWizard()->getCurrentStep() === self::END_STEP) {
1264+
$event->continue(false);
1265+
}
1266+
$event->setData(new Response());
12661267
}
12671268
}
12681269

0 commit comments

Comments
 (0)