Skip to content

Commit

Permalink
typo (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
mildabre authored Sep 10, 2024
1 parent 43f2a02 commit 55146b2
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Application/Routers/RouteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function addRoute(
#[Language('TEXT')]
string $mask,
array|string|\Closure $metadata = [],
int|bool $oneWay = 0,
bool $oneWay = false,
): static
{
$this->add(new Route($mask, $metadata), (int) $oneWay);
$this->add(new Route($mask, $metadata), $oneWay);

Check failure on line 71 in src/Application/Routers/RouteList.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #2 $oneWay of method Nette\Routing\RouteList::add() expects int, bool given.
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Application/UI/Presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function run(Application\Request $request): Application\Response
$this->startup();
if (!$this->startupCheck) {
$class = static::getReflection()->getMethod('startup')->getDeclaringClass()->getName();
throw new Nette\InvalidStateException("Method $class::startup() or its descendant doesn't call parent::startup().");
throw new Nette\InvalidStateException("Method $class::startup() or its parents doesn't call parent::startup().");
}

// calls $this->action<Action>()
Expand Down
6 changes: 4 additions & 2 deletions src/Bridges/ApplicationDI/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public function loadConfiguration(): void
}

$builder->addDefinition($this->prefix('templateFactory'))
->setFactory(ApplicationLatte\TemplateFactory::class)
->setArguments(['templateClass' => $config->templateClass]);
->setFactory(ApplicationLatte\TemplateFactory::class, [
'templateClass' => $config->templateClass,
'configVars' => $config->variables,
]);

if ($this->name === 'latte') {
$builder->addAlias('nette.latteFactory', $this->prefix('latteFactory'));
Expand Down
1 change: 1 addition & 0 deletions src/Bridges/ApplicationLatte/DefaultTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class DefaultTemplate extends Template

/** @var \stdClass[] */
public array $flashes = [];
public \stdClass $config;


/**
Expand Down
2 changes: 2 additions & 0 deletions src/Bridges/ApplicationLatte/TemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(
private readonly ?Nette\Http\IRequest $httpRequest = null,
private readonly ?Nette\Security\User $user = null,
$templateClass = null,
private array $configVars = [],
) {
if ($templateClass && (!class_exists($templateClass) || !is_a($templateClass, Template::class, true))) {
throw new Nette\InvalidArgumentException("Class $templateClass does not implement " . Template::class . ' or it does not exist.');
Expand Down Expand Up @@ -63,6 +64,7 @@ public function createTemplate(?UI\Control $control = null, ?string $class = nul
'flashes' => $flashes,
'control' => $control,
'presenter' => $presenter,
'config' => $control instanceof UI\Presenter && $this->configVars ? (object) $this->configVars : null,
];

foreach ($params as $key => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/ApplicationTracy/RoutingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function analyse(Routing\RouteList $router, ?Nette\Http\IRequest $httpRe
continue;
}

$matched = $flags[$i] & $router::ONE_WAY ? 'oneway' : 'no';
$matched = empty($flags[$i]['oneWay']) ? 'no' : 'oneway';
$params = $e = null;
try {
if (
Expand Down
74 changes: 74 additions & 0 deletions tests/Bridges.DI/LatteExtension.variables.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* Test: LatteExtension v3
*/

declare(strict_types=1);

use Nette\DI;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';

Tester\Environment::bypassFinals();


test('no variables', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
latte:
variables:
', 'neon'));

$compiler = new DI\Compiler;
$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false));
$code = $compiler
->addConfig($config)
->setClassName('Container1')
->compile();
eval($code);

$container = new Container1;
$latteFactory = $container->getService('latte.templateFactory');
$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
$presenter->shouldReceive('getHttpResponse')->andReturn(Mockery::mock(Nette\Http\IResponse::class)->shouldIgnoreMissing());
$presenter->shouldIgnoreMissing();

$template = $latteFactory->createTemplate($presenter);
Assert::notContains('config', $template->getParameters());
});


test('presenter presence', function () {
$loader = new DI\Config\Loader;
$config = $loader->load(Tester\FileMock::create('
latte:
variables:
foo: bar
', 'neon'));

$compiler = new DI\Compiler;
$compiler->addExtension('latte', new Nette\Bridges\ApplicationDI\LatteExtension('', false));
$code = $compiler
->addConfig($config)
->setClassName('Container2')
->compile();
eval($code);

$container = new Container2;
$latteFactory = $container->getService('latte.templateFactory');
$template = $latteFactory->createTemplate();
Assert::notContains('config', $template->getParameters());


$presenter = Mockery::mock(Nette\Application\UI\Presenter::class);
$presenter->shouldReceive('getHttpResponse')->andReturn(Mockery::mock(Nette\Http\IResponse::class)->shouldIgnoreMissing());
$presenter->shouldIgnoreMissing();

$template = $latteFactory->createTemplate($presenter);
Assert::equal(
(object) ['foo' => 'bar'],
$template->getParameters()['config'],
);
});
2 changes: 1 addition & 1 deletion tests/Routers/RouteList.addRoute.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require __DIR__ . '/Route.php';

$list = new RouteList;
$list->addRoute('foo', ['presenter' => 'foo'], RouteList::ONE_WAY);
$list->addRoute('bar', ['presenter' => 'bar'], RouteList::ONE_WAY);
$list->addRoute('bar', ['presenter' => 'bar'], oneWay: true);
$list->addRoute('hello', ['presenter' => 'hello']);


Expand Down

0 comments on commit 55146b2

Please sign in to comment.