Skip to content

Commit

Permalink
Compiler: triggers schema warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 30, 2020
1 parent e9c866e commit 33b188d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DI/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,14 @@ private function processSchema(Schema\Schema $schema, array $configs, $name = nu
$context->dynamics = &$this->extensions[self::PARAMETERS]->dynamicValidators;
};
try {
return $processor->processMultiple($schema, $configs);
$res = $processor->processMultiple($schema, $configs);
} catch (Schema\ValidationException $e) {
throw new Nette\DI\InvalidConfigurationException($e->getMessage());
}
foreach ($processor->getWarnings() as $warning) {
trigger_error($warning, E_USER_DEPRECATED);
}
return $res;
}


Expand Down
43 changes: 43 additions & 0 deletions tests/DI/Compiler.extension.schema.deprecated.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* Test: Nette\DI\CompilerExtension and schema validation
*/

declare(strict_types=1);

use Nette\Schema\Expect;
use Tester\Assert;


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


class FooExtension extends Nette\DI\CompilerExtension
{
public $loadedConfig;


public function getConfigSchema(): Nette\Schema\Schema
{
return Expect::structure([
'key' => Expect::string()->deprecated(),
]);
}


public function loadConfiguration()
{
$this->loadedConfig = $this->config;
}
}


Assert::error(function () {
$compiler = new Nette\DI\Compiler;
$compiler->addExtension('foo', $foo = new FooExtension);
createContainer($compiler, '
foo:
key: hello
');
}, E_USER_DEPRECATED, "The item 'foo › key' is deprecated.");

0 comments on commit 33b188d

Please sign in to comment.