Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Support for nette 3.0 (#25)
Browse files Browse the repository at this point in the history
* nette 3 support
  • Loading branch information
dakorpar authored Apr 27, 2019
1 parent 333261a commit d3c9f52
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 86 deletions.
29 changes: 13 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,32 @@ cache:
php:
- 7.1
- 7.2
- 7.3

env:
matrix:
- NETTE=nette-2.4
- RUN_TESTS=1 # dev
- RUN_TESTS=1 COMPOSER_EXTRA_ARGS="--prefer-stable"
- RUN_TESTS=1 COMPOSER_EXTRA_ARGS="--prefer-lowest --prefer-stable"

matrix:
fast_finish: true
include:
- php: 7.1
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
- php: 7.2
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
- php: 7.3
env: COMPOSER_EXTRA_ARGS="--prefer-stable" COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
exclude:
- php: 7.3
env: COMPOSER_EXTRA_ARGS="--prefer-stable"
allow_failures:
- php: 7.1
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
- php: 7.2
env: NETTE=nette-2.4 COVERAGE="--coverage ./coverage.xml --coverage-src ./src" TESTER_RUNTIME="phpdbg"
- env: RUN_TESTS=1

before_install:
- travis_retry composer self-update
- wget -O /tmp/composer-nette https://raw.githubusercontent.com/Kdyby/TesterExtras/master/bin/composer-nette.php
- php /tmp/composer-nette

install:
- travis_retry composer update --no-interaction --prefer-dist $COMPOSER_EXTRA_ARGS
- travis_retry composer create-project --no-interaction jakub-onderka/php-parallel-lint /tmp/php-parallel-lint
- travis_retry wget -O /tmp/coveralls.phar https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar
- travis_retry composer update --no-interaction --no-suggest --no-progress --prefer-dist $COMPOSER_EXTRA_ARGS # update because we may need --prefer-lowest option

script:
- vendor/bin/tester $COVERAGE -s -p ${TESTER_RUNTIME:-php} -c ./tests/php.ini-unix ./tests/KdybyTests/
- php /tmp/php-parallel-lint/parallel-lint.php -e php,phpt --exclude vendor .

after_script:
- if [ "$COVERAGE" != "" ]; then php /tmp/coveralls.phar --verbose --config tests/.coveralls.yml || true; fi
Expand Down
44 changes: 22 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,32 @@
"issues": "https://github.com/Kdyby/ElasticSearch/issues"
},
"require": {
"nette/di": "~2.4",
"tracy/tracy": "~2.4",
"nette/utils": "~2.4",
"php": ">=7.1",
"nette/di": "~3.0",
"tracy/tracy": "~2.6",
"nette/utils": "~3.0",

"ruflin/elastica": "~5.0|~6.0"
"ruflin/elastica": "~6.0"
},
"require-dev": {
"nette/application": "~2.4",
"nette/bootstrap": "~2.4",
"nette/caching": "~2.4",
"nette/component-model": "~2.4",
"nette/database": "~2.4",
"nette/finder": "~2.4",
"nette/forms": "~2.4",
"nette/http": "~2.4",
"nette/mail": "~2.4",
"nette/neon": "~2.4",
"nette/php-generator": "~2.6",
"nette/reflection": "~2.4",
"nette/robot-loader": "~2.4",
"nette/safe-stream": "~2.3",
"nette/security": "~2.4",
"nette/tokenizer": "~2.3",
"latte/latte": "~2.4",
"nette/application": "~3.0",
"nette/bootstrap": "~3.0",
"nette/caching": "~3.0",
"nette/component-model": "~3.0",
"nette/database": "~3.0",
"nette/finder": "~2.5",
"nette/forms": "~3.0",
"nette/http": "~3.0",
"nette/mail": "~3.0",
"nette/neon": "~3.0",
"nette/php-generator": "~3.0",
"nette/robot-loader": "~3.0",
"nette/safe-stream": "~2.4",
"nette/security": "~3.0",
"nette/tokenizer": "~3.0",
"latte/latte": "~2.5",

"nette/tester": "~1.7"
"nette/tester": "~2.2"
},
"autoload": {
"psr-0": {
Expand Down
23 changes: 7 additions & 16 deletions src/Kdyby/ElasticSearch/DI/SearchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ class SearchExtension extends Nette\DI\CompilerExtension

public function loadConfiguration()
{
/** @var array $config */
$config = \Nette\DI\Config\Helpers::merge($this->getConfig(), $this->defaults + $this->elasticaDefaults);
$this->setConfig($config);
$builder = $this->getContainerBuilder();
$config = $this->getConfig($this->defaults + $this->elasticaDefaults);

if (empty($config['connections'])) {
$config['connections']['default'] = Config\Helpers::merge(array_intersect_key($config, $this->connectionDefaults), $builder->expand($this->connectionDefaults));
$config['connections']['default'] = Config\Helpers::merge(array_intersect_key($config, $this->connectionDefaults), Nette\DI\Helpers::expand($this->connectionDefaults, $builder->parameters));

} else {
foreach ($config['connections'] as $name => $connectionConfig) {
$config['connections'][$name] = Config\Helpers::merge($connectionConfig, $builder->expand($this->connectionDefaults));
$config['connections'][$name] = Config\Helpers::merge($connectionConfig, Nette\DI\Helpers::expand($this->connectionDefaults, $builder->parameters));
}
}

Expand All @@ -90,18 +92,16 @@ public function loadConfiguration()

$elasticaConfig = array_intersect_key($config, $this->elasticaDefaults);
$elastica = $builder->addDefinition($this->prefix('elastica'))
->setClass('Kdyby\ElasticSearch\Client', [$elasticaConfig]);
->setFactory(Kdyby\ElasticSearch\Client::class, [$elasticaConfig]);

if ($config['debugger']) {
$builder->addDefinition($this->prefix('panel'))
->setClass('Kdyby\ElasticSearch\Diagnostics\Panel');
->setFactory(Kdyby\ElasticSearch\Diagnostics\Panel::class);

$elastica->addSetup($this->prefix('@panel') . '::register', ['@self']);
}
}



public function afterCompile(Nette\PhpGenerator\ClassType $class)
{
$initialize = $class->methods['initialize'];
Expand All @@ -110,13 +110,4 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
$initialize->addBody('?::getBlueScreen()->addPanel(?);', [new Code\PhpLiteral($debuggerClass), 'Kdyby\\ElasticSearch\\Diagnostics\\Panel::renderException']);
}



public static function register(Nette\Configurator $configurator)
{
$configurator->onCompile[] = function ($config, Nette\DI\Compiler $compiler) {
$compiler->addExtension('search', new SearchExtension());
};
}

}
22 changes: 9 additions & 13 deletions tests/KdybyTests/ElasticSearch/Extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,27 @@ require_once __DIR__ . '/../bootstrap.php';
class ExtensionTest extends Tester\TestCase
{

/**
* @param string $configFile
* @return \SystemContainer|\Nette\DI\Container
*/
protected function createContainer($configFile = 'default')
public function createContainer(string $configFile = 'default'): Nette\DI\Container
{
$config = new Nette\Configurator();
$config->setTempDirectory(TEMP_DIR);
$config->addParameters(['container' => ['class' => 'SystemContainer_' . md5($configFile)]]);
Kdyby\ElasticSearch\DI\SearchExtension::register($config);
$config->addConfig(__DIR__ . '/config/' . $configFile . '.neon');
$config->onCompile[] = static function ($config, Nette\DI\Compiler $compiler): void {
$compiler->addExtension('elasticSearch', new Kdyby\ElasticSearch\DI\SearchExtension());
};
return $config->createContainer();
}



public function testFunctional()
public function testFunctional(): void
{
$sl = $this->createContainer();

Assert::type('Kdyby\ElasticSearch\Client', $sl->getService('search.elastica'));
Assert::type('Elastica\Client', $sl->getService('search.elastica'));
Assert::type('Kdyby\ElasticSearch\Diagnostics\Panel', $sl->getService('search.panel'));
Assert::type(Kdyby\ElasticSearch\Client::class, $sl->getService('elasticSearch.elastica'));
Assert::type(\Elastica\Client::class, $sl->getService('elasticSearch.elastica'));
Assert::type(Kdyby\ElasticSearch\Diagnostics\Panel::class, $sl->getService('elasticSearch.panel'));
}

}

\run(new ExtensionTest());
(new ExtensionTest())->run();
2 changes: 1 addition & 1 deletion tests/KdybyTests/ElasticSearch/config/default.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
search:
elasticSearch:
debugger: on
24 changes: 6 additions & 18 deletions tests/KdybyTests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,18 @@
* For the full copyright and license information, please view the file license.md that was distributed with this source code.
*/

use Tester\Environment;
use Tester\Helpers;

if (!@include __DIR__ . '/../../vendor/autoload.php') {
echo 'Install Nette Tester using `composer update --dev`';
exit(1);
}
date_default_timezone_set('Europe/Prague');

// configure environment
Tester\Environment::setup();
class_alias('Tester\Assert', 'Assert');
Environment::setup();
date_default_timezone_set('Europe/Prague');

// create temporary directory
define('TEMP_DIR', __DIR__ . '/../tmp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()));
Tester\Helpers::purge(TEMP_DIR);


$_SERVER = array_intersect_key($_SERVER, array_flip([
'PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv']));
$_SERVER['REQUEST_TIME'] = 1234567890;
$_ENV = $_GET = $_POST = [];

function id($val) {
return $val;
}

function run(Tester\TestCase $testCase) {
$testCase->run(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : NULL);
}
Helpers::purge(TEMP_DIR);

0 comments on commit d3c9f52

Please sign in to comment.