- UI Revamp
- Some i18n added/fixed - WIP on a new testing mechanism
This commit is contained in:
1 parent
f5014e1cee
commit
58c61a8f01
76 files changed
+1428
-313
No files matched your search
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Console\Form\Testing;
|
||||
|
||||
use Picea\Ui\Method\{ FormInterface, FormContextInterface };
|
||||
|
||||
use Lean\Console\{Attribute\TestParameter, Lib, Entity};
|
||||
|
||||
use Ulmus\{ EntityCollection };
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Test implements FormInterface
|
||||
{
|
||||
protected Lib\Testing\TestPreprocessorInterface $waitFor;
|
||||
|
||||
protected Lib\Testing\TestFetcherItem $definition;
|
||||
|
||||
public function __construct(
|
||||
protected ContainerInterface $container,
|
||||
protected Lib\Testing\TestFetcher $testFetcher,
|
||||
) {}
|
||||
|
||||
public function initialize(FormContextInterface $context) : void
|
||||
{
|
||||
if ($context->class ?? false) {
|
||||
$this->definition = $this->testFetcher->compile()[$context->class];
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(FormContextInterface $context) : bool
|
||||
{
|
||||
if (isset($this->definition->attribute) && $this->definition->attribute->waitFor) {
|
||||
$this->waitFor = new $this->definition->attribute->waitFor();
|
||||
}
|
||||
|
||||
return $context->valid();
|
||||
}
|
||||
|
||||
public function execute(FormContextInterface $context) : mixed
|
||||
{
|
||||
if (isset($this->waitFor)) {
|
||||
$this->waitFor->run();
|
||||
}
|
||||
|
||||
$controller = $this->container->get($context->class);
|
||||
|
||||
$test = $this->definition->methods->filtersOne(fn($e) => $e->attribute->name === $context->name);
|
||||
|
||||
$request = $context->getRequest()
|
||||
->withMethod($context->method)
|
||||
->withAttribute('arguments', $test->attribute->arguments)
|
||||
->withQueryParams($test->attribute->withQueryParams)
|
||||
->withParsedBody($test->attribute->withParsedBody);
|
||||
|
||||
$arguments = []; # @todo
|
||||
|
||||
$result = $controller->{$test->name}($request, $arguments);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function attributeCollection(array $collection) : EntityCollection
|
||||
{
|
||||
$collection = new EntityCollection(...$collection);
|
||||
$collection->entityClass = static::class;
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user