diff --git a/.travis.yml b/.travis.yml index 58a59a0..e363a0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,22 @@ language: php php: - - 5.3.3 - - 5.4 - - 5.5 - 5.6 - 7.0 - - hhvm env: - PHP_BIN=php - PHP_BIN=php-cgi matrix: - allow_failures: + include: + - php: 5.6 + env: dependencies="--prefer-lowest --prefer-stable" PHP_BIN=php - php: 7.0 - - php: hhvm - - exclude: - - php: hhvm - env: PHP_BIN=php-cgi + env: coverage="--coverage ./coverage.xml --coverage-src ./src" PHP_BIN=phpdbg script: - - vendor/bin/tester -p $PHP_BIN tests -s - - php code-checker/src/code-checker.php + - vendor/bin/tester -p $PHP_BIN tests -s $coverage + - php temp/code-checker/src/code-checker.php --short-arrays after_failure: # Print *.actual content @@ -30,5 +24,19 @@ after_failure: before_script: # Install Nette Tester & Code Checker - - composer install --no-interaction --prefer-source - - composer create-project nette/code-checker code-checker ~2.2 --no-interaction --prefer-source + - travis_retry composer update --no-interaction --prefer-dist $dependencies + - travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction + +after_script: + # Report Code Coverage + - > + if [ "$coverage" != "" ]; then + wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar + && php coveralls.phar --verbose --config tests/.coveralls.yml + || true; fi + +sudo: false + +cache: + directories: + - $HOME/.composer/cache diff --git a/composer.json b/composer.json index cd691fe..287a1c8 100644 --- a/composer.json +++ b/composer.json @@ -1,22 +1,22 @@ { "name": "nette/bootstrap", "description": "Nette Bootstrap", - "homepage": "http://nette.org", + "homepage": "https://nette.org", "license": ["BSD-3-Clause", "GPL-2.0", "GPL-3.0"], "authors": [ { "name": "David Grudl", - "homepage": "http://davidgrudl.com" + "homepage": "https://davidgrudl.com" }, { "name": "Nette Community", - "homepage": "http://nette.org/contributors" + "homepage": "https://nette.org/contributors" } ], "require": { - "php": ">=5.3.1", - "nette/di": "~2.3", - "nette/utils": "~2.2" + "php": ">=5.6.0", + "nette/di": "~2.4.0", + "nette/utils": "~2.4" }, "suggest": { "nette/robot-loader": "to use Configurator::createRobotLoader()", @@ -32,9 +32,9 @@ "nette/robot-loader": "~2.2", "nette/safe-stream": "~2.2", "nette/security": "~2.3", - "nette/tester": "~1.3", + "nette/tester": "~2.0", "latte/latte": "~2.2", - "tracy/tracy": "~2.3" + "tracy/tracy": "^2.3" }, "conflict": { "nette/nette": "<2.2" @@ -45,7 +45,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "2.3-dev" + "dev-master": "2.4-dev" } } } diff --git a/contributing.md b/contributing.md index a1cbbd5..860882b 100644 --- a/contributing.md +++ b/contributing.md @@ -5,7 +5,7 @@ The issue tracker is the preferred channel for bug reports, features requests and submitting pull requests, but please respect the following restrictions: * Please **do not** use the issue tracker for personal support requests (use - [Nette forum](http://forum.nette.org) or [Stack Overflow](http://stackoverflow.com)). + [Nette forum](https://forum.nette.org) or [Stack Overflow](http://stackoverflow.com)). * Please **do not** derail or troll issues. Keep the discussion on topic and respect the opinions of others. @@ -21,7 +21,7 @@ fits with the scope and aims of the project. It's up to *you* to make a strong case to convince the project's developers of the merits of this feature. Nette welcomes **pull requests**. If you'd like to contribute, please take a moment -to [read the guidelines](http://nette.org/en/contributing) in order to make +to [read the guidelines](https://nette.org/en/contributing) in order to make the contribution process easy and effective for everyone involved. Thanks! diff --git a/license.md b/license.md index af571d5..cf741bd 100644 --- a/license.md +++ b/license.md @@ -21,7 +21,7 @@ If your stuff is good, it will not take long to establish a reputation for yours New BSD License --------------- -Copyright (c) 2004, 2014 David Grudl (http://davidgrudl.com) +Copyright (c) 2004, 2014 David Grudl (https://davidgrudl.com) All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/readme.md b/readme.md index 234499f..8b82879 100644 --- a/readme.md +++ b/readme.md @@ -3,6 +3,9 @@ Nette Bootstrap [![Downloads this Month](https://img.shields.io/packagist/dm/nette/bootstrap.svg)](https://packagist.org/packages/nette/bootstrap) [![Build Status](https://travis-ci.org/nette/bootstrap.svg?branch=master)](https://travis-ci.org/nette/bootstrap) +[![Coverage Status](https://coveralls.io/repos/github/nette/bootstrap/badge.svg?branch=master)](https://coveralls.io/github/nette/bootstrap?branch=master) +[![Latest Stable Version](https://poser.pugx.org/nette/bootstrap/v/stable)](https://github.com/nette/bootstrap/releases) +[![License](https://img.shields.io/badge/license-New%20BSD-blue.svg)](https://github.com/nette/bootstrap/blob/master/license.md) File `bootstrap.php` loads Nette Framework and all libraries that we depend on: @@ -29,7 +32,7 @@ Setup directory for temporary files $configurator->setTempDirectory(__DIR__ . '/../temp'); ``` -Activate [autoloading](http://doc.nette.org/en/auto-loading#toc-nette-loaders-robotloader), that will automatically load all the files with our classes: +Activate [autoloading](https://doc.nette.org/en/auto-loading#toc-nette-loaders-robotloader), that will automatically load all the files with our classes: ```php $configurator->createRobotLoader() diff --git a/src/Bootstrap/Configurator.php b/src/Bootstrap/Configurator.php index 2f269f6..b71dc89 100644 --- a/src/Bootstrap/Configurator.php +++ b/src/Bootstrap/Configurator.php @@ -1,70 +1,66 @@ 'Nette\DI\Extensions\PhpExtension', - 'constants' => 'Nette\DI\Extensions\ConstantsExtension', - 'extensions' => 'Nette\DI\Extensions\ExtensionsExtension', - 'application' => array('Nette\Bridges\ApplicationDI\ApplicationExtension', array('%debugMode%', array('%appDir%'), '%tempDir%/cache')), - 'decorator' => 'Nette\DI\Extensions\DecoratorExtension', - 'cache' => array('Nette\Bridges\CacheDI\CacheExtension', array('%tempDir%')), - 'database' => array('Nette\Bridges\DatabaseDI\DatabaseExtension', array('%debugMode%')), - 'di' => array('Nette\DI\Extensions\DIExtension', array('%debugMode%')), - 'forms' => 'Nette\Bridges\FormsDI\FormsExtension', - 'http' => 'Nette\Bridges\HttpDI\HttpExtension', - 'latte' => array('Nette\Bridges\ApplicationDI\LatteExtension', array('%tempDir%/cache/latte', '%debugMode%')), - 'mail' => 'Nette\Bridges\MailDI\MailExtension', - 'reflection' => array('Nette\Bridges\ReflectionDI\ReflectionExtension', array('%debugMode%')), - 'routing' => array('Nette\Bridges\ApplicationDI\RoutingExtension', array('%debugMode%')), - 'security' => array('Nette\Bridges\SecurityDI\SecurityExtension', array('%debugMode%')), - 'session' => array('Nette\Bridges\HttpDI\SessionExtension', array('%debugMode%')), - 'tracy' => array('Tracy\Bridges\Nette\TracyExtension', array('%debugMode%')), - 'inject' => 'Nette\DI\Extensions\InjectExtension', - ); + public $defaultExtensions = [ + 'php' => Nette\DI\Extensions\PhpExtension::class, + 'constants' => Nette\DI\Extensions\ConstantsExtension::class, + 'extensions' => Nette\DI\Extensions\ExtensionsExtension::class, + 'application' => [Nette\Bridges\ApplicationDI\ApplicationExtension::class, ['%debugMode%', ['%appDir%'], '%tempDir%/cache']], + 'decorator' => Nette\DI\Extensions\DecoratorExtension::class, + 'cache' => [Nette\Bridges\CacheDI\CacheExtension::class, ['%tempDir%']], + 'database' => [Nette\Bridges\DatabaseDI\DatabaseExtension::class, ['%debugMode%']], + 'di' => [Nette\DI\Extensions\DIExtension::class, ['%debugMode%']], + 'forms' => Nette\Bridges\FormsDI\FormsExtension::class, + 'http' => Nette\Bridges\HttpDI\HttpExtension::class, + 'latte' => [Nette\Bridges\ApplicationDI\LatteExtension::class, ['%tempDir%/cache/latte', '%debugMode%']], + 'mail' => Nette\Bridges\MailDI\MailExtension::class, + 'routing' => [Nette\Bridges\ApplicationDI\RoutingExtension::class, ['%debugMode%']], + 'security' => [Nette\Bridges\SecurityDI\SecurityExtension::class, ['%debugMode%']], + 'session' => [Nette\Bridges\HttpDI\SessionExtension::class, ['%debugMode%']], + 'tracy' => [Tracy\Bridges\Nette\TracyExtension::class, ['%debugMode%']], + 'inject' => Nette\DI\Extensions\InjectExtension::class, + ]; /** @var string[] of classes which shouldn't be autowired */ - public $autowireExcludedClasses = array( + public $autowireExcludedClasses = [ 'stdClass', - ); + ]; /** @var array */ protected $parameters; /** @var array */ - protected $services = array(); + protected $services = []; /** @var array [file|array, section] */ - protected $files = array(); + protected $files = []; public function __construct() @@ -87,7 +83,6 @@ public function setDebugMode($value) } $this->parameters['debugMode'] = $value; $this->parameters['productionMode'] = !$this->parameters['debugMode']; // compatibility - $this->parameters['environment'] = $this->parameters['debugMode'] ? 'development' : 'production'; return $this; } @@ -139,21 +134,16 @@ public function addServices(array $services) */ protected function getDefaultParameters() { - $trace = debug_backtrace(PHP_VERSION_ID >= 50306 ? DEBUG_BACKTRACE_IGNORE_ARGS : FALSE); + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $last = end($trace); $debugMode = static::detectDebugMode(); - return array( + return [ 'appDir' => isset($trace[1]['file']) ? dirname($trace[1]['file']) : NULL, 'wwwDir' => isset($last['file']) ? dirname($last['file']) : NULL, 'debugMode' => $debugMode, 'productionMode' => !$debugMode, - 'environment' => $debugMode ? 'development' : 'production', 'consoleMode' => PHP_SAPI === 'cli', - 'container' => array( - 'class' => NULL, - 'parent' => NULL, - ) - ); + ]; } @@ -176,7 +166,7 @@ public function enableDebugger($logDirectory = NULL, $email = NULL) */ public function createRobotLoader() { - if (!class_exists('Nette\Loaders\RobotLoader')) { + if (!class_exists(Nette\Loaders\RobotLoader::class)) { throw new Nette\NotSupportedException('RobotLoader not found, do you have `nette/robot-loader` package installed?'); } @@ -191,17 +181,13 @@ public function createRobotLoader() * Adds configuration file. * @return self */ - public function addConfig($file, $section = NULL) + public function addConfig($file) { - if ($section === NULL && is_string($file) && $this->parameters['debugMode']) { // back compatibility - try { - $loader = new DI\Config\Loader; - $loader->load($file, $this->parameters['environment']); - trigger_error("Config file '$file' has sections, call addConfig() with second parameter Configurator::AUTO.", E_USER_WARNING); - $section = $this->parameters['environment']; - } catch (\Exception $e) {} + $section = func_num_args() > 1 ? func_get_arg(1) : NULL; + if ($section !== NULL) { + trigger_error('Sections in config file are deprecated.', E_USER_DEPRECATED); } - $this->files[] = array($file, $section === self::AUTO ? $this->parameters['environment'] : $section); + $this->files[] = [$file, $section === self::AUTO ? ($this->parameters['debugMode'] ? 'development' : 'production') : $section]; return $this; } @@ -212,27 +198,37 @@ public function addConfig($file, $section = NULL) */ public function createContainer() { - $loader = new DI\ContainerLoader( - $this->getCacheDirectory() . '/Nette.Configurator', - $this->parameters['debugMode'] - ); - $class = $loader->load( - array($this->parameters, $this->files), - array($this, 'generateContainer') - ); - - $container = new $class; + $class = $this->loadContainer(); + $container = new $class(); foreach ($this->services as $name => $service) { $container->addService($name, $service); } $container->initialize(); - if (class_exists('Nette\Environment')) { + if (class_exists(Nette\Environment::class)) { Nette\Environment::setContext($container); // back compatibility } return $container; } + /** + * Loads system DI container class and returns its name. + * @return string + */ + public function loadContainer() + { + $loader = new DI\ContainerLoader( + $this->getCacheDirectory() . '/Nette.Configurator', + $this->parameters['debugMode'] + ); + $class = $loader->load( + [$this, 'generateContainer'], + [$this->parameters, $this->files, PHP_VERSION_ID - PHP_RELEASE_VERSION] + ); + return $class; + } + + /** * @return string * @internal @@ -240,8 +236,8 @@ public function createContainer() public function generateContainer(DI\Compiler $compiler) { $loader = $this->createLoader(); - $compiler->addConfig(array('parameters' => $this->parameters)); - $fileInfo = array(); + $compiler->addConfig(['parameters' => $this->parameters]); + $fileInfo = []; foreach ($this->files as $info) { if (is_scalar($info[0])) { $fileInfo[] = "// source: $info[0] $info[1]"; @@ -255,24 +251,17 @@ public function generateContainer(DI\Compiler $compiler) $builder->addExcludedClasses($this->autowireExcludedClasses); foreach ($this->defaultExtensions as $name => $extension) { - list($class, $args) = is_string($extension) ? array($extension, array()) : $extension; + list($class, $args) = is_string($extension) ? [$extension, []] : $extension; if (class_exists($class)) { - $rc = new \ReflectionClass($class); $args = DI\Helpers::expand($args, $this->parameters, TRUE); - $compiler->addExtension($name, $args ? $rc->newInstanceArgs($args) : $rc->newInstance()); + $compiler->addExtension($name, (new \ReflectionClass($class))->newInstanceArgs($args)); } } $this->onCompile($this, $compiler); $classes = $compiler->compile(); - - if (!empty($builder->parameters['container']['parent'])) { - $classes[0]->setExtends($builder->parameters['container']['parent']); - } - - return implode("\n", $fileInfo) . "\n\n" . implode("\n\n\n", $classes) - . (($tmp = $builder->parameters['container']['class']) ? "\nclass $tmp extends {$builder->getClassName()} {}\n" : ''); + return implode("\n", $fileInfo) . "\n\n" . $classes; } @@ -288,7 +277,7 @@ protected function createLoader() protected function getCacheDirectory() { if (empty($this->parameters['tempDir'])) { - throw new Nette\InvalidStateException("Set path to temporary directory using setTempDirectory()."); + throw new Nette\InvalidStateException('Set path to temporary directory using setTempDirectory().'); } $dir = $this->parameters['tempDir'] . '/cache'; if (!is_dir($dir)) { @@ -308,12 +297,14 @@ protected function fixCompatibility($config) $config['nette']['http']['frames'] = $config['nette']['security']['frames']; unset($config['nette']['security']['frames']); } - foreach (array('application', 'cache', 'database', 'di' => 'container', 'forms', 'http', - 'latte', 'mail' => 'mailer', 'routing', 'security', 'session', 'tracy' => 'debugger') as $new => $old) { + foreach (['application', 'cache', 'database', 'di' => 'container', 'forms', 'http', + 'latte', 'mail' => 'mailer', 'routing', 'security', 'session', 'tracy' => 'debugger'] as $new => $old) { if (isset($config['nette'][$old])) { $new = is_int($new) ? $old : $new; if (isset($config[$new])) { throw new Nette\DeprecatedException("You can use (deprecated) section 'nette.$old' or new section '$new', but not both of them."); + } else { + trigger_error("Configuration section 'nette.$old' is deprecated, use section '$new' (without 'nette')", E_USER_DEPRECATED); } $config[$new] = $config['nette'][$old]; unset($config['nette'][$old]); diff --git a/src/Bridges/Framework/TracyBridge.php b/src/Bridges/Framework/TracyBridge.php index 7ad491a..10a5a9a 100644 --- a/src/Bridges/Framework/TracyBridge.php +++ b/src/Bridges/Framework/TracyBridge.php @@ -1,61 +1,66 @@ getPanel('Tracy:info')->data['Nette Framework'] = $version; $blueScreen->info[] = "Nette Framework $version"; } - $blueScreen->addPanel(function($e) { + $blueScreen->addPanel(function ($e) { if ($e instanceof Latte\CompileException) { - return array( + return [ 'tab' => 'Template', - 'panel' => (@is_file($e->sourceName) // @ - may trigger error - ? '

File: ' . Helpers::editorLink($e->sourceName, $e->sourceLine) . '

' - : '') - . '
'
+					'panel' => (preg_match('#\n|\?#', $e->sourceName)
+							? ''
+							: '

' + . (@is_file($e->sourceName) // @ - may trigger error + ? 'File: ' . Helpers::editorLink($e->sourceName, $e->sourceLine) + : '' . htmlspecialchars($e->sourceName . ($e->sourceLine ? ':' . $e->sourceLine : '')) . '') + . '

') + . '
' . BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine) - . '
' - ); + . '
', + ]; } }); - $blueScreen->addPanel(function($e) { + $blueScreen->addPanel(function ($e) { if ($e instanceof Nette\Neon\Exception && preg_match('#line (\d+)#', $e->getMessage(), $m) && ($trace = Helpers::findTrace($e->getTrace(), 'Nette\Neon\Decoder::decode')) ) { - return array( + return [ 'tab' => 'NEON', 'panel' => ($trace2 = Helpers::findTrace($e->getTrace(), 'Nette\DI\Config\Adapters\NeonAdapter::load')) ? '

File: ' . Helpers::editorLink($trace2['args'][0], $m[1]) . '

' . BlueScreen::highlightFile($trace2['args'][0], $m[1]) - : BlueScreen::highlightPhp($trace['args'][0], $m[1]) - ); + : BlueScreen::highlightPhp($trace['args'][0], $m[1]), + ]; } }); } diff --git a/tests/.coveralls.yml b/tests/.coveralls.yml new file mode 100644 index 0000000..82764a3 --- /dev/null +++ b/tests/.coveralls.yml @@ -0,0 +1,4 @@ +# for php-coveralls +service_name: travis-ci +coverage_clover: coverage.xml +json_path: coverage.json diff --git a/tests/Bootstrap/Configurator.addServices.phpt b/tests/Bootstrap/Configurator.addServices.phpt index 672daa8..312d703 100644 --- a/tests/Bootstrap/Configurator.addServices.phpt +++ b/tests/Bootstrap/Configurator.addServices.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator::addServices() */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -16,7 +16,7 @@ class TestExistingService private $scream; - public function __construct($scream = true) + public function __construct($scream = TRUE) { $this->scream = $scream; } @@ -36,27 +36,27 @@ $configurator->addConfig(Tester\FileMock::create(' services: existingService: class: TestExistingService - run: yes + tags: [run] setup: - run ', 'neon')); -$existingService = new TestExistingService(false); +$existingService = new TestExistingService(FALSE); $newService = new stdClass(); $addServiceTwice = new stdClass(); -$configurator->addServices(array( +$configurator->addServices([ 'existingService' => $existingService, 'newService' => $newService, 'addServiceTwice' => $addServiceTwice, -)); +]); $addServiceTwice = new stdClass(); -$configurator->addServices(array( +$configurator->addServices([ 'addServiceTwice' => $addServiceTwice, -)); +]); $container = $configurator->createContainer(); diff --git a/tests/Bootstrap/Configurator.aliasNetteConfig.phpt b/tests/Bootstrap/Configurator.aliasNetteConfig.phpt index 14479f7..6879109 100644 --- a/tests/Bootstrap/Configurator.aliasNetteConfig.phpt +++ b/tests/Bootstrap/Configurator.aliasNetteConfig.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator aliases for nette config */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -22,7 +22,7 @@ class TestExtension extends Nette\DI\CompilerExtension } -test(function() { +test(function () { $configurator = new Configurator; $configurator->defaultExtensions['mail'] = 'TestExtension'; $configurator->setTempDirectory(TEMP_DIR); @@ -31,13 +31,13 @@ test(function() { mailer: item: 10 ', 'neon')); - $container = $configurator->createContainer(); + $container = @$configurator->createContainer(); - Assert::same(array('item' => 10), TestExtension::$cfg); + Assert::same(['item' => 10], TestExtension::$cfg); }); -Assert::exception(function() { +Assert::exception(function () { $configurator = new Configurator; $configurator->defaultExtensions['database'] = 'TestExtension'; $configurator->setTempDirectory(TEMP_DIR); @@ -50,4 +50,4 @@ Assert::exception(function() { item: 20 ', 'neon')); $container = $configurator->createContainer(); -}, 'Nette\DeprecatedException', "You can use (deprecated) section 'nette.database' or new section 'database', but not both of them."); +}, Nette\DeprecatedException::class, "You can use (deprecated) section 'nette.database' or new section 'database', but not both of them."); diff --git a/tests/Bootstrap/Configurator.autowireExcluded.phpt b/tests/Bootstrap/Configurator.autowireExcluded.phpt index a988b78..ceb56c0 100644 --- a/tests/Bootstrap/Configurator.autowireExcluded.phpt +++ b/tests/Bootstrap/Configurator.autowireExcluded.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and autowiring blacklist */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -26,8 +26,8 @@ services: $container = $configurator->createContainer(); -Assert::type('Foo', $container->getByType('Foo')); +Assert::type(Foo::class, $container->getByType('Foo')); Assert::exception(function () use ($container) { $container->getByType('stdClass'); -}, '\Nette\DI\MissingServiceException'); +}, Nette\DI\MissingServiceException::class); diff --git a/tests/Bootstrap/Configurator.basic.phpt b/tests/Bootstrap/Configurator.basic.phpt index 2079b2d..49d80ab 100644 --- a/tests/Bootstrap/Configurator.basic.phpt +++ b/tests/Bootstrap/Configurator.basic.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and createContainer. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -15,24 +15,24 @@ date_default_timezone_set('America/Los_Angeles'); $configurator = new Configurator; $configurator->setTempDirectory(TEMP_DIR); -$configurator->addParameters(array( +$configurator->addParameters([ 'wwwDir' => 'overwritten', // overwrites default value 'foo2' => '%foo%', // uses parameter from config file 'foo3' => '%foo%', // will be overwritten by config file -)); -$container = $configurator->addConfig('files/configurator.basic.neon', 'production') +]); +$container = @$configurator->addConfig('files/configurator.basic.neon', 'production') ->createContainer(); -Assert::same( 'overwritten', $container->parameters['wwwDir'] ); -Assert::same( 'hello world', $container->parameters['foo'] ); -Assert::same( 'hello world', $container->parameters['foo2'] ); -Assert::same( 'overwritten', $container->parameters['foo3'] ); -Assert::same( 'hello', $container->parameters['bar'] ); -Assert::same( 'hello world', constant('BAR') ); -Assert::same( 'Europe/Prague', date_default_timezone_get() ); +Assert::same('overwritten', $container->parameters['wwwDir']); +Assert::same('hello world', $container->parameters['foo']); +Assert::same('hello world', $container->parameters['foo2']); +Assert::same('overwritten', $container->parameters['foo3']); +Assert::same('hello', $container->parameters['bar']); +Assert::same('hello world', constant('BAR')); +Assert::same('Europe/Prague', date_default_timezone_get()); -Assert::same( array( +Assert::same([ 'dsn' => 'sqlite2::memory:', 'user' => 'dbuser', 'password' => 'secret', -), $container->parameters['database'] ); +], $container->parameters['database']); diff --git a/tests/Bootstrap/Configurator.debugMode.phpt b/tests/Bootstrap/Configurator.debugMode.phpt index ace2df3..2e00572 100644 --- a/tests/Bootstrap/Configurator.debugMode.phpt +++ b/tests/Bootstrap/Configurator.debugMode.phpt @@ -4,96 +4,96 @@ * Test: Nette\Configurator and production mode. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -test(function(){ +test(function () { unset($_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = 'xx'; $configurator = new Configurator; - Assert::false( $configurator->isDebugMode() ); + Assert::false($configurator->isDebugMode()); $configurator->setDebugMode(TRUE); - Assert::true( $configurator->isDebugMode() ); + Assert::true($configurator->isDebugMode()); $configurator->setDebugMode(FALSE); - Assert::false( $configurator->isDebugMode() ); + Assert::false($configurator->isDebugMode()); $configurator->setDebugMode($_SERVER['REMOTE_ADDR']); - Assert::true( $configurator->isDebugMode() ); + Assert::true($configurator->isDebugMode()); }); -Assert::exception(function(){ +Assert::exception(function () { $configurator = new Configurator; $configurator->setDebugMode(1); -}, 'Nette\InvalidArgumentException'); +}, Nette\InvalidArgumentException::class); -test(function(){ // localhost +test(function () { // localhost unset($_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; - Assert::true( Configurator::detectDebugMode() ); - Assert::true( Configurator::detectDebugMode('192.168.1.1') ); + Assert::true(Configurator::detectDebugMode()); + Assert::true(Configurator::detectDebugMode('192.168.1.1')); $_SERVER['REMOTE_ADDR'] = '::1'; - Assert::true( Configurator::detectDebugMode() ); + Assert::true(Configurator::detectDebugMode()); $_SERVER['REMOTE_ADDR'] = '192.168.1.1'; - Assert::false( Configurator::detectDebugMode() ); - Assert::false( Configurator::detectDebugMode('192.168.1.1.0') ); - Assert::true( Configurator::detectDebugMode('192.168.1.1') ); - Assert::true( Configurator::detectDebugMode('a,192.168.1.1,b') ); - Assert::true( Configurator::detectDebugMode('a 192.168.1.1 b') ); - - Assert::false( Configurator::detectDebugMode(array()) ); - Assert::true( Configurator::detectDebugMode(array('192.168.1.1')) ); + Assert::false(Configurator::detectDebugMode()); + Assert::false(Configurator::detectDebugMode('192.168.1.1.0')); + Assert::true(Configurator::detectDebugMode('192.168.1.1')); + Assert::true(Configurator::detectDebugMode('a,192.168.1.1,b')); + Assert::true(Configurator::detectDebugMode('a 192.168.1.1 b')); + + Assert::false(Configurator::detectDebugMode([])); + Assert::true(Configurator::detectDebugMode(['192.168.1.1'])); }); -test(function(){ // localhost + proxy +test(function () { // localhost + proxy $_SERVER['HTTP_X_FORWARDED_FOR'] = 'xx'; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; - Assert::false( Configurator::detectDebugMode() ); + Assert::false(Configurator::detectDebugMode()); $_SERVER['REMOTE_ADDR'] = '::1'; - Assert::false( Configurator::detectDebugMode() ); + Assert::false(Configurator::detectDebugMode()); $_SERVER['REMOTE_ADDR'] = '192.168.1.1'; - Assert::false( Configurator::detectDebugMode() ); - Assert::true( Configurator::detectDebugMode($_SERVER['REMOTE_ADDR']) ); + Assert::false(Configurator::detectDebugMode()); + Assert::true(Configurator::detectDebugMode($_SERVER['REMOTE_ADDR'])); }); -test(function(){ // missing $_SERVER['REMOTE_ADDR'] +test(function () { // missing $_SERVER['REMOTE_ADDR'] unset($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']); - Assert::false( Configurator::detectDebugMode() ); - Assert::false( Configurator::detectDebugMode('127.0.0.1') ); + Assert::false(Configurator::detectDebugMode()); + Assert::false(Configurator::detectDebugMode('127.0.0.1')); - Assert::true( Configurator::detectDebugMode(php_uname('n')) ); - Assert::true( Configurator::detectDebugMode(array(php_uname('n'))) ); + Assert::true(Configurator::detectDebugMode(php_uname('n'))); + Assert::true(Configurator::detectDebugMode([php_uname('n')])); }); -test(function(){ // secret +test(function () { // secret unset($_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = '192.168.1.1'; $_COOKIE[Configurator::COOKIE_SECRET] = '*secret*'; - Assert::false( Configurator::detectDebugMode() ); - Assert::true( Configurator::detectDebugMode('192.168.1.1') ); - Assert::false( Configurator::detectDebugMode('abc@192.168.1.1') ); - Assert::true( Configurator::detectDebugMode('*secret*@192.168.1.1') ); + Assert::false(Configurator::detectDebugMode()); + Assert::true(Configurator::detectDebugMode('192.168.1.1')); + Assert::false(Configurator::detectDebugMode('abc@192.168.1.1')); + Assert::true(Configurator::detectDebugMode('*secret*@192.168.1.1')); - $_COOKIE[Configurator::COOKIE_SECRET] = array('*secret*'); - Assert::false( Configurator::detectDebugMode('*secret*@192.168.1.1') ); + $_COOKIE[Configurator::COOKIE_SECRET] = ['*secret*']; + Assert::false(Configurator::detectDebugMode('*secret*@192.168.1.1')); }); diff --git a/tests/Bootstrap/Configurator.developmentContainer.phpt b/tests/Bootstrap/Configurator.developmentContainer.phpt index 5badbd2..6183205 100644 --- a/tests/Bootstrap/Configurator.developmentContainer.phpt +++ b/tests/Bootstrap/Configurator.developmentContainer.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and development container. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -28,46 +28,41 @@ nette: - Nette\Bridges\HttpTracy\SessionPanel ', 'neon')); -$container = $configurator->createContainer(); +$container = @$configurator->createContainer(); -Assert::type( 'Nette\DI\Container', $container ); +Assert::type(Nette\DI\Container::class, $container); -Assert::same( array( +Assert::same([ 'appDir' => __DIR__, 'wwwDir' => __DIR__, 'debugMode' => TRUE, 'productionMode' => FALSE, - 'environment' => 'development', 'consoleMode' => PHP_SAPI === 'cli', - 'container' => array( - 'class' => NULL, - 'parent' => NULL, - ), 'tempDir' => TEMP_DIR, -), $container->parameters ); +], $container->parameters); -Assert::true( $container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\FileJournal || $container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\SQLiteJournal ); -Assert::type( 'Nette\Caching\Storages\FileStorage', $container->getService('cacheStorage') ); -Assert::type( 'Nette\Http\Request', $container->getService('httpRequest') ); -Assert::type( 'Nette\Http\Response', $container->getService('httpResponse') ); -Assert::type( 'Nette\Http\Context', $container->getService('nette.httpContext') ); -Assert::type( 'Nette\Http\Session', $container->getService('session') ); -Assert::type( 'Nette\Security\User', $container->getService('user') ); -Assert::type( 'Nette\Http\UserStorage', $container->getService('nette.userStorage') ); -Assert::type( 'Nette\Application\Application', $container->getService('application') ); -Assert::type( 'Nette\Application\Routers\RouteList', $container->getService('router') ); -Assert::type( 'Nette\Application\PresenterFactory', $container->getService('nette.presenterFactory') ); -Assert::type( 'Nette\Mail\SendmailMailer', $container->getService('nette.mailer') ); -Assert::type( 'Tracy\Logger', $container->getService('tracy.logger') ); -Assert::type( 'Tracy\BlueScreen', $container->getService('tracy.blueScreen') ); -Assert::type( 'Tracy\Bar', $container->getService('tracy.bar') ); +Assert::true($container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\FileJournal || $container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\SQLiteJournal); +Assert::type(Nette\Caching\Storages\FileStorage::class, $container->getService('cacheStorage')); +Assert::type(Nette\Http\Request::class, $container->getService('httpRequest')); +Assert::type(Nette\Http\Response::class, $container->getService('httpResponse')); +Assert::type(Nette\Http\Context::class, @$container->getService('nette.httpContext')); // @ service is deprecated +Assert::type(Nette\Http\Session::class, $container->getService('session')); +Assert::type(Nette\Security\User::class, $container->getService('user')); +Assert::type(Nette\Http\UserStorage::class, $container->getService('nette.userStorage')); +Assert::type(Nette\Application\Application::class, $container->getService('application')); +Assert::type(Nette\Application\Routers\RouteList::class, $container->getService('router')); +Assert::type(Nette\Application\PresenterFactory::class, $container->getService('nette.presenterFactory')); +Assert::type(Nette\Mail\SendmailMailer::class, $container->getService('nette.mailer')); +Assert::type(Tracy\Logger::class, $container->getService('tracy.logger')); +Assert::type(Tracy\BlueScreen::class, $container->getService('tracy.blueScreen')); +Assert::type(Tracy\Bar::class, $container->getService('tracy.bar')); -Assert::type( 'Nette\Bridges\ApplicationLatte\ILatteFactory', $container->createService('nette.latteFactory') ); -Assert::type( 'Nette\Bridges\ApplicationLatte\TemplateFactory', $container->createService('nette.templateFactory') ); +Assert::type(Nette\Bridges\ApplicationLatte\ILatteFactory::class, $container->createService('nette.latteFactory')); +Assert::type(Nette\Bridges\ApplicationLatte\TemplateFactory::class, $container->createService('nette.templateFactory')); if (PHP_SAPI !== 'cli') { $headers = headers_list(); - Assert::contains( 'X-Frame-Options: SAMEORIGIN', $headers ); - Assert::contains( 'Content-Type: text/html; charset=utf-8', $headers ); - Assert::contains( 'X-Powered-By: Nette Framework', $headers ); + Assert::contains('X-Frame-Options: SAMEORIGIN', $headers); + Assert::contains('Content-Type: text/html; charset=utf-8', $headers); + Assert::contains('X-Powered-By: Nette Framework', $headers); } diff --git a/tests/Bootstrap/Configurator.inheritance1.phpt b/tests/Bootstrap/Configurator.inheritance1.phpt index 2fe0e10..ab4e8c1 100644 --- a/tests/Bootstrap/Configurator.inheritance1.phpt +++ b/tests/Bootstrap/Configurator.inheritance1.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and services inheritance and overwriting. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -29,13 +29,13 @@ services: setup: # extends original setup - $errorPresenter(Error) ', 'neon')); -$container = $configurator->createContainer(); +$container = @$configurator->createContainer(); // @ inheritance is deprecated -Assert::type( 'MyApp', $container->getService('application') ); -Assert::true( $container->getService('application')->catchExceptions ); -Assert::same( 'Error', $container->getService('application')->errorPresenter ); +Assert::type(MyApp::class, $container->getService('application')); +Assert::true($container->getService('application')->catchExceptions); +Assert::same('Error', $container->getService('application')->errorPresenter); -Assert::type( 'MyApp', $container->getService('app2') ); -Assert::true( $container->getService('app2')->catchExceptions ); -Assert::same( 'Error', $container->getService('app2')->errorPresenter ); +Assert::type(MyApp::class, $container->getService('app2')); +Assert::true($container->getService('app2')->catchExceptions); +Assert::same('Error', $container->getService('app2')->errorPresenter); diff --git a/tests/Bootstrap/Configurator.inheritance2.phpt b/tests/Bootstrap/Configurator.inheritance2.phpt index 399449d..d779872 100644 --- a/tests/Bootstrap/Configurator.inheritance2.phpt +++ b/tests/Bootstrap/Configurator.inheritance2.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and services inheritance and overwriting. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -30,13 +30,13 @@ services: setup: - $errorPresenter(Error) ', 'neon')); -$container = $configurator->createContainer(); +$container = @$configurator->createContainer(); // @ inheritance is deprecated -Assert::type( 'MyApp', $container->getService('application') ); -Assert::null( $container->getService('application')->catchExceptions ); -Assert::same( 'Error', $container->getService('application')->errorPresenter ); +Assert::type(MyApp::class, $container->getService('application')); +Assert::null($container->getService('application')->catchExceptions); +Assert::same('Error', $container->getService('application')->errorPresenter); -Assert::type( 'MyApp', $container->getService('app2') ); -Assert::null( $container->getService('app2')->catchExceptions ); -Assert::null( $container->getService('app2')->errorPresenter ); +Assert::type(MyApp::class, $container->getService('app2')); +Assert::null($container->getService('app2')->catchExceptions); +Assert::null($container->getService('app2')->errorPresenter); diff --git a/tests/Bootstrap/Configurator.inheritance3.phpt b/tests/Bootstrap/Configurator.inheritance3.phpt index 820802d..7124457 100644 --- a/tests/Bootstrap/Configurator.inheritance3.phpt +++ b/tests/Bootstrap/Configurator.inheritance3.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and services inheritance and overwriting. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -20,6 +20,6 @@ services: ', 'neon')); -Assert::exception(function() use ($configurator) { +Assert::exception(function () use ($configurator) { $configurator->createContainer(); -}, 'Nette\DI\ServiceCreationException', "Circular reference detected for service 'application'."); +}, Nette\DI\ServiceCreationException::class, "Circular reference detected for service 'application'."); diff --git a/tests/Bootstrap/Configurator.inheritance4.phpt b/tests/Bootstrap/Configurator.inheritance4.phpt index 2893321..1c2257a 100644 --- a/tests/Bootstrap/Configurator.inheritance4.phpt +++ b/tests/Bootstrap/Configurator.inheritance4.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and services inheritance and overwriting. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -21,4 +21,4 @@ services: $container = $configurator->createContainer(); -Assert::type( 'Nette\Application\Application', $container->getService('application') ); +Assert::type(Nette\Application\Application::class, $container->getService('application')); diff --git a/tests/Bootstrap/Configurator.loadConfig.errors.phpt b/tests/Bootstrap/Configurator.loadConfig.errors.phpt index ed2987b..a69e866 100644 --- a/tests/Bootstrap/Configurator.loadConfig.errors.phpt +++ b/tests/Bootstrap/Configurator.loadConfig.errors.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and createContainer errors. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -13,7 +13,7 @@ require __DIR__ . '/../bootstrap.php'; $configurator = new Configurator; -Assert::exception(function() use ($configurator) { +Assert::exception(function () use ($configurator) { $configurator->addConfig('files/missing.neon') ->createContainer(); -}, 'Nette\InvalidStateException', "Set path to temporary directory using setTempDirectory()."); +}, Nette\InvalidStateException::class, "Set path to temporary directory using setTempDirectory()."); diff --git a/tests/Bootstrap/Configurator.minimalContainer.phpt b/tests/Bootstrap/Configurator.minimalContainer.phpt index edd98c2..1ccd461 100644 --- a/tests/Bootstrap/Configurator.minimalContainer.phpt +++ b/tests/Bootstrap/Configurator.minimalContainer.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and minimal container. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -13,50 +13,45 @@ require __DIR__ . '/../bootstrap.php'; $configurator = new Configurator; $configurator->setTempDirectory(TEMP_DIR); -$configurator->addParameters(array( +$configurator->addParameters([ 'hello' => 'world', -)); +]); $container = $configurator->createContainer(); -Assert::type( 'Nette\DI\Container', $container ); +Assert::type(Nette\DI\Container::class, $container); -Assert::same( array( +Assert::same([ 'appDir' => __DIR__, 'wwwDir' => __DIR__, 'debugMode' => FALSE, 'productionMode' => TRUE, - 'environment' => 'production', 'consoleMode' => PHP_SAPI === 'cli', - 'container' => array( - 'class' => NULL, - 'parent' => NULL, - ), 'tempDir' => TEMP_DIR, 'hello' => 'world', -), $container->parameters ); - -Assert::true( $container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\FileJournal || $container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\SQLiteJournal ); -Assert::type( 'Nette\Caching\Storages\FileStorage', $container->getService('cacheStorage') ); -Assert::type( 'Nette\Http\Request', $container->getService('httpRequest') ); -Assert::type( 'Nette\Http\Response', $container->getService('httpResponse') ); -Assert::type( 'Nette\Http\Context', $container->getService('nette.httpContext') ); -Assert::type( 'Nette\Http\Session', $container->getService('session') ); -Assert::type( 'Nette\Security\User', $container->getService('user') ); -Assert::type( 'Nette\Http\UserStorage', $container->getService('nette.userStorage') ); -Assert::type( 'Nette\Application\Application', $container->getService('application') ); -Assert::type( 'Nette\Application\Routers\RouteList', $container->getService('router') ); -Assert::type( 'Nette\Application\PresenterFactory', $container->getService('nette.presenterFactory') ); -Assert::type( 'Nette\Mail\SendmailMailer', $container->getService('nette.mailer') ); -Assert::type( 'Tracy\Logger', $container->getService('tracy.logger') ); -Assert::type( 'Tracy\BlueScreen', $container->getService('tracy.blueScreen') ); -Assert::type( 'Tracy\Bar', $container->getService('tracy.bar') ); - -Assert::type( 'Nette\Bridges\ApplicationLatte\ILatteFactory', $container->createService('nette.latteFactory') ); -Assert::type( 'Nette\Bridges\ApplicationLatte\TemplateFactory', $container->createService('nette.templateFactory') ); +], $container->parameters); + +Assert::true($container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\FileJournal || $container->getService('nette.cacheJournal') instanceof Nette\Caching\Storages\SQLiteJournal); +Assert::type(Nette\Caching\Storages\FileStorage::class, $container->getService('cacheStorage')); +Assert::type(Nette\Http\Request::class, $container->getService('httpRequest')); +Assert::type(Nette\Http\Response::class, $container->getService('httpResponse')); +Assert::type(Nette\Http\Context::class, @$container->getService('nette.httpContext')); // @ service is deprecated +Assert::type(Nette\Http\Session::class, $container->getService('session')); +Assert::type(Nette\Security\User::class, $container->getService('user')); +Assert::type(Nette\Http\UserStorage::class, $container->getService('nette.userStorage')); +Assert::type(Nette\Application\Application::class, $container->getService('application')); +Assert::type(Nette\Application\Routers\RouteList::class, $container->getService('router')); +Assert::type(Nette\Application\PresenterFactory::class, $container->getService('nette.presenterFactory')); +Assert::type(Nette\Mail\SendmailMailer::class, $container->getService('nette.mailer')); +Assert::type(Tracy\Logger::class, $container->getService('tracy.logger')); +Assert::type(Tracy\BlueScreen::class, $container->getService('tracy.blueScreen')); +Assert::type(Tracy\Bar::class, $container->getService('tracy.bar')); + +Assert::type(Nette\Bridges\ApplicationLatte\ILatteFactory::class, $container->createService('nette.latteFactory')); +Assert::type(Nette\Bridges\ApplicationLatte\TemplateFactory::class, $container->createService('nette.templateFactory')); if (PHP_SAPI !== 'cli') { $headers = headers_list(); - Assert::contains( 'X-Frame-Options: SAMEORIGIN', $headers ); - Assert::contains( 'Content-Type: text/html; charset=utf-8', $headers ); - Assert::contains( 'X-Powered-By: Nette Framework', $headers ); + Assert::contains('X-Frame-Options: SAMEORIGIN', $headers); + Assert::contains('Content-Type: text/html; charset=utf-8', $headers); + Assert::contains('X-Powered-By: Nette Framework', $headers); } diff --git a/tests/Bootstrap/Configurator.onCompile.phpt b/tests/Bootstrap/Configurator.onCompile.phpt index 055cb29..38861e3 100644 --- a/tests/Bootstrap/Configurator.onCompile.phpt +++ b/tests/Bootstrap/Configurator.onCompile.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator and user extension. */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -15,14 +15,14 @@ class FooExtension extends Nette\DI\CompilerExtension { public function loadConfiguration() { - Assert::same( array('foo' => 'hello'), $this->config ); + Assert::same(['foo' => 'hello'], $this->config); } } $configurator = new Configurator; $configurator->setTempDirectory(TEMP_DIR); -$configurator->onCompile[] = function(Configurator $configurator, Nette\DI\Compiler $compiler) { +$configurator->onCompile[] = function (Configurator $configurator, Nette\DI\Compiler $compiler) { $compiler->addExtension('foo', new FooExtension); }; $configurator->addConfig(Tester\FileMock::create(' diff --git a/tests/Bootstrap/Configurator.presentersDecoration.phpt b/tests/Bootstrap/Configurator.presentersDecoration.phpt new file mode 100644 index 0000000..4b86cc9 --- /dev/null +++ b/tests/Bootstrap/Configurator.presentersDecoration.phpt @@ -0,0 +1,48 @@ +setDebugMode(FALSE); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig(Tester\FileMock::create(' + parameters: + param: \'test\' + decorator: + BasePresenter: + setup: + - setAttr(%param%) + ', 'neon')); + + $container = $configurator->createContainer(); + $services = array_keys($container->findByTag('nette.presenter'), 'Presenter1'); + Assert::count(1, $services); + $presenter = $container->createService($services[0]); + Assert::same('test', $presenter->getAttr()); +}); + + +test(function () { + $configurator = new Configurator; + $configurator->setDebugMode(FALSE); + $configurator->setTempDirectory(TEMP_DIR); + $configurator->addConfig(Tester\FileMock::create(' + decorator: + BasePresenter: + tags: [test.tag] + ', 'neon')); + + $container = $configurator->createContainer(); + $services = $container->findByTag('test.tag'); + Assert::count(1, $services); +}); diff --git a/tests/Bootstrap/Configurator.robotLoader.phpt b/tests/Bootstrap/Configurator.robotLoader.phpt index bdd9330..fd6cb54 100644 --- a/tests/Bootstrap/Configurator.robotLoader.phpt +++ b/tests/Bootstrap/Configurator.robotLoader.phpt @@ -4,8 +4,8 @@ * Test: Nette\Configurator::createRobotLoader() */ -use Nette\Configurator, - Tester\Assert; +use Nette\Configurator; +use Tester\Assert; require __DIR__ . '/../bootstrap.php'; @@ -13,13 +13,13 @@ require __DIR__ . '/../bootstrap.php'; $configurator = new Configurator; -Assert::exception(function() use ($configurator) { +Assert::exception(function () use ($configurator) { $configurator->createRobotLoader(); -}, 'Nette\InvalidStateException', "Set path to temporary directory using setTempDirectory()."); +}, Nette\InvalidStateException::class, 'Set path to temporary directory using setTempDirectory().'); $configurator->setTempDirectory(TEMP_DIR); $loader = $configurator->createRobotLoader(); -Assert::type( 'Nette\Loaders\RobotLoader', $loader ); -Assert::type( 'Nette\Caching\Storages\FileStorage', $loader->getCacheStorage() ); +Assert::type(Nette\Loaders\RobotLoader::class, $loader); +Assert::type(Nette\Caching\Storages\FileStorage::class, $loader->getCacheStorage()); diff --git a/tests/Bootstrap/files/MyPresenter.php b/tests/Bootstrap/files/MyPresenter.php new file mode 100644 index 0000000..36fb4f9 --- /dev/null +++ b/tests/Bootstrap/files/MyPresenter.php @@ -0,0 +1,20 @@ +attr; + } + + function setAttr($attr) + { + $this->attr = $attr; + } +} + +class Presenter1 extends BasePresenter +{ +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 270c4ae..7888ed0 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -28,7 +28,7 @@ function test(\Closure $function) class Notes { - static public $notes = array(); + static public $notes = []; public static function add($message) { @@ -38,7 +38,7 @@ public static function add($message) public static function fetch() { $res = self::$notes; - self::$notes = array(); + self::$notes = []; return $res; } diff --git a/tests/php-unix.ini b/tests/php-unix.ini new file mode 100644 index 0000000..3cdf095 --- /dev/null +++ b/tests/php-unix.ini @@ -0,0 +1,5 @@ +[PHP] +;extension_dir = "./ext" + +[Zend] +;zend_extension="./ext/zend_extension" diff --git a/tests/php-win.ini b/tests/php-win.ini new file mode 100644 index 0000000..ae0f393 --- /dev/null +++ b/tests/php-win.ini @@ -0,0 +1,6 @@ +[PHP] +extension_dir = "./ext" +extension=php_pdo_sqlite.dll + +[Zend] +;zend_extension="./ext/php_xdebug-2.0.5-5.3-vc6.dll"