Skip to content

Commit

Permalink
BC: Support only PHP 7.1, Nette 3.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
slepic authored and o5 committed Jan 5, 2020
1 parent 6e4397d commit 7fbb263
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 124 deletions.
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
language: php

php:
- 5.6
- 7.0
- hhvm

matrix:
allow_failures:
- php: hhvm
- 7.1

before_install:
- if [ $TRAVIS_PHP_VERSION = '5.6' ]; then COVERAGE="-c `php -i | grep 'xdebug.ini'` --coverage coverage.xml --coverage-src=src/ "; else COVERAGE="" && if [ $TRAVIS_PHP_VERSION = '5.6' ]; then phpenv config-rm xdebug.ini; fi; fi
- if [ $TRAVIS_PHP_VERSION = '7.1' ]; then COVERAGE="-c `php -i | grep 'xdebug.ini'` --coverage coverage.xml --coverage-src=src/ "; else COVERAGE="" && if [ $TRAVIS_PHP_VERSION = '7.1' ]; then phpenv config-rm xdebug.ini; fi; fi
- composer global require hirak/prestissimo

install:
Expand All @@ -21,4 +15,4 @@ script:
- vendor/bin/tester -p php $COVERAGE tests/

after_script:
- if [ $TRAVIS_PHP_VERSION = '5.6' ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.xml; fi
- if [ $TRAVIS_PHP_VERSION = '7.1' ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.xml; fi
35 changes: 20 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,32 @@
}
},
"scripts": {
"test": "./vendor/bin/tester --colors 1 -p php tests/",
"test": "./vendor/bin/tester --colors 1 -j 4 -c tests/php-unix.ini -p php tests/",
"syntax": "./vendor/bin/phpcs --standard=standards.xml --colors --encoding=utf-8 -sp src/",
"syntax-fix": "./vendor/bin/phpcbf --standard=standards.xml src/"
},
"require": {
"php": ">=5.6",
"nette/utils": "~2.4",
"nette/forms": "~2.2",
"latte/latte": "~2.3",
"nette/application": "~2.2",
"nette/component-model": "~2.2",
"php": ">=7.1",
"nette/utils": "^3.0",
"nette/forms": "^3.0",
"latte/latte": "^2.5",
"nette/application": "^3.0",
"nette/component-model": "^3.0",
"symfony/property-access": "~3.0"
},
"require-dev": {
"tracy/tracy": "~2.3",
"nette/bootstrap": "~2.3",
"nette/database": "~2.2",
"tracy/tracy": "^2.6",
"nette/bootstrap": "^3.0",
"nette/database": "^3.0",
"nette/tester": "~1.7.1",
"mockery/mockery": "~0.9.3",
"dibi/dibi": "~3.0.1",
"kdyby/doctrine": "~3.3.0",
"squizlabs/php_codesniffer": "~2.5"
}
"mockery/mockery": "^1.0",
"squizlabs/php_codesniffer": "~2.5",
"kdyby/annotations": "^3.0",
"kdyby/console": "dev-master",
"kdyby/doctrine": "dev-master",
"kdyby/events": "dev-master",
"dibi/dibi": "^4.0"
},
"minimum-stability": "dev",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion src/Components/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function handleExport()
* @param \Nette\Http\IResponse $httpResponse
* @return void
*/
public function send(\Nette\Http\IRequest $httpRequest, \Nette\Http\IResponse $httpResponse)
public function send(\Nette\Http\IRequest $httpRequest, \Nette\Http\IResponse $httpResponse): void
{
$encoding = 'utf-8';
$label = $this->label
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function handleOperations(\Nette\Forms\Controls\SubmitButton $button)

foreach ($values as $key => $val) {
if ($val) {
$ids[] = $key;
$ids[] = (string) $key;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function setStepCount($stepCount)
/**
* @return int
*/
public function getPage()
public function getPage(): int
{
if ($this->page === NULL) {
$this->page = parent::getPage();
Expand Down
14 changes: 7 additions & 7 deletions src/DataSources/DibiFluent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @subpackage DataSources
* @author Petr Bugyík
*
* @property-read \DibiFluent $fluent
* @property-read \Dibi\Fluent $fluent
* @property-read int $limit
* @property-read int $offset
* @property-read int $count
Expand All @@ -30,7 +30,7 @@ class DibiFluent implements IDataSource
{
use \Nette\SmartObject;

/** @var \DibiFluent */
/** @var \Dibi\Fluent */
protected $fluent;

/** @var int */
Expand All @@ -40,15 +40,15 @@ class DibiFluent implements IDataSource
protected $offset;

/**
* @param \DibiFluent $fluent
* @param \Dibi\Fluent $fluent
*/
public function __construct(\DibiFluent $fluent)
public function __construct(\Dibi\Fluent $fluent)
{
$this->fluent = $fluent;
}

/**
* @return \DibiFluent
* @return \Dibi\Fluent
*/
public function getFluent()
{
Expand All @@ -73,9 +73,9 @@ public function getOffset()

/**
* @param \Grido\Components\Filters\Condition $condition
* @param \DibiFluent $fluent
* @param \Dibi\Fluent $fluent
*/
protected function makeWhere(\Grido\Components\Filters\Condition $condition, \DibiFluent $fluent = NULL)
protected function makeWhere(\Grido\Components\Filters\Condition $condition, \Dibi\Fluent $fluent = NULL)
{
$fluent = $fluent === NULL
? $this->fluent
Expand Down
22 changes: 19 additions & 3 deletions src/DataSources/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,23 @@ public function setFetchJoinCollection($fetchJoinCollection)
*/
public function getQuery()
{
return $this->qb->getQuery();
return $this->_getQuery($this->qb);
}

/**
* Workaround for https://github.com/Kdyby/DoctrineCache/issues/23
*
* @param \Doctrine\ORM\QueryBuilder $qb
* @return \Doctrine\ORM\Query
*/
private function _getQuery(\Doctrine\ORM\QueryBuilder $qb)
{
$query = $qb->getQuery();
$ttl = $query->getQueryCacheLifetime();
if (!\is_int($ttl)) {
$query->setQueryCacheLifetime(0);
}
return $query;
}

/**
Expand Down Expand Up @@ -205,7 +221,7 @@ public function getData()
// Paginator is better if the query uses ManyToMany associations
$result = $this->qb->getMaxResults() !== NULL || $this->qb->getFirstResult() !== NULL
? new Paginator($this->getQuery())
: $this->qb->getQuery()->getResult();
: $this->getQuery()->getResult();

foreach ($result as $item) {
// Return only entity itself
Expand Down Expand Up @@ -279,7 +295,7 @@ public function suggest($column, array $conditions, $limit)
}

$items = [];
$data = $qb->getQuery()->getScalarResult();
$data = $this->_getQuery($qb)->getScalarResult();
foreach ($data as $row) {
if (is_string($column)) {
$value = (string) current($row);
Expand Down
4 changes: 2 additions & 2 deletions src/DataSources/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Model
*/
public function __construct($model)
{
if ($model instanceof \DibiFluent) {
if ($model instanceof \Dibi\Fluent) {
$dataSource = new DibiFluent($model);
} elseif ($model instanceof \Nette\Database\Table\Selection) {
$dataSource = new NetteDatabase($model);
Expand All @@ -56,7 +56,7 @@ public function __construct($model)
}

/**
* @return \IDataSource
* @return IDataSource
*/
public function getDataSource()
{
Expand Down
13 changes: 6 additions & 7 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Grido\Components\Filters\Filter;
use Grido\Components\Actions\Action;

use Nette\Application\UI\Presenter;
use Symfony\Component\PropertyAccess\PropertyAccessor;

/**
Expand Down Expand Up @@ -140,7 +141,6 @@ class Grid extends Components\Container
*/
public function __construct()
{
parent::__construct();
list($parent, $name) = func_get_args() + [NULL, NULL];
if ($parent !== NULL) {
$parent->addComponent($this, $name);
Expand Down Expand Up @@ -701,7 +701,7 @@ public function getCustomization()
* @param array $params
* @internal
*/
public function loadState(array $params)
public function loadState(array $params): void
{
//loads state from session
$session = $this->getRememberSession();
Expand All @@ -720,10 +720,10 @@ public function loadState(array $params)
* @param \Nette\Application\UI\PresenterComponentReflection $reflection (internal, used by Presenter)
* @internal
*/
public function saveState(array &$params, $reflection = NULL)
public function saveState(array &$params, $reflection = NULL): void
{
!empty($this->onRegistered) && $this->onRegistered($this);
return parent::saveState($params, $reflection);
parent::saveState($params, $reflection);
}

/**
Expand Down Expand Up @@ -832,10 +832,9 @@ public function reload()
/**********************************************************************************************/

/**
* @return \Nette\Templating\FileTemplate
* @internal
*/
public function createTemplate()
public function createTemplate(): \Nette\Application\UI\ITemplate
{
$template = parent::createTemplate();
$template->setFile($this->getCustomization()->getTemplateFiles()[Customization::TEMPLATE_DEFAULT]);
Expand Down Expand Up @@ -1029,7 +1028,7 @@ protected function getItemsForCountSelect()
*/
public function __triggerUserNotice($message)
{
if ($this->getPresenter(FALSE) && $session = $this->getRememberSession()) {
if ($this->lookup(Presenter::class, FALSE) && $session = $this->getRememberSession()) {
$session->remove();
}

Expand Down
6 changes: 3 additions & 3 deletions src/Translations/FileTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ protected function getTranslationsFromFile($lang)

/**
* @param string $message
* @param int $count plural
* @param ...$parameters
* @return string
*/
public function translate($message, $count = NULL)
public function translate($message, ...$parameters): string
{
return isset($this->translations[$message])
? $this->translations[$message]
: $message;
: ($message ?? '');
}
}
2 changes: 1 addition & 1 deletion tests/Components/Action.Event.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ class ActionEventTest extends \Tester\TestCase
}
}

run(__FILE__);
run(__FILE__);
29 changes: 4 additions & 25 deletions tests/Components/Column.Editable.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -309,41 +309,20 @@ class EditableTest extends \Tester\TestCase
Helper::grid(function(Grid $grid) {
$grid->setModel([]);
$grid->presenter->forceAjaxMode = TRUE;
$grid->addColumnText('firstname', 'Firstname')->setEditable(function() {}, new TextInput);
$grid->addColumnText('firstname', 'Firstname')
->setEditable(function() {}, new \Nette\Forms\Controls\TextInput());
});

ob_start();
Helper::request([
$response = Helper::request([
'do' => 'grid-columns-firstname-editableControl',
'grid-columns-firstname-value' => 'Test',
]);
$response->send(Helper::$presenter->getHttpRequest(), Helper::$presenter->getHttpResponse());
$output = ob_get_clean();
Assert::same('<input type="text" name="editfirstname" id="frm-grid-form-editfirstname" value="Test">', $output);
}
}

class TextInput extends \Nette\Forms\Controls\TextInput
{
public function getControl()
{
return new Html(parent::getControl());
}
}

class Html extends \Nette\Utils\Html
{
private $control;

public function __construct($control)
{
$this->control = $control;
}

public function render($indent = NULL)
{
print $this->control->render();
}
}

$test = new EditableTest();
$test->run();
26 changes: 13 additions & 13 deletions tests/Components/Export.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ namespace Grido\Tests;

use Tester\Assert,
Grido\Grid,
Grido\Tests\Helper,
Grido\Components\Export,
Grido\DataSources\ArraySource;

Expand All @@ -23,23 +22,24 @@ class Response implements \Nette\Http\IResponse

public static $headers = [];

function setHeader($name, $value)
function setHeader(string $name, string $value)
{
self::$headers[$name] = $value;
return $this;
}

function setCode($code) {}
function getCode() {}
function addHeader($name, $value) {}
function getHeader($header, $default = NULL) {}
function setContentType($type, $charset = NULL) {}
function redirect($url, $code = self::S302_FOUND) {}
function setExpiration($seconds) {}
function isSent() {}
function getHeaders() {}
function setCookie($name, $value, $expire, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL) {}
function deleteCookie($name, $path = NULL, $domain = NULL, $secure = NULL) {}
function setCode(int $code, ?string $reason = null): void {}
function getCode(): int {}
function addHeader(string $name, string $value) {}
function getHeader(string $header, ?string $default = NULL): ?string {}
function deleteHeader(string $name) {}
function setContentType(string $type, string $charset = NULL) {}
function redirect(string $url, int $code = self::S302_FOUND): void {}
function setExpiration(?string $seconds) {}
function isSent(): bool {}
function getHeaders(): array {}
function setCookie(string $name, string $value, $expire, string $path = NULL, string $domain = NULL, bool $secure = NULL, bool $httpOnly = NULL) {}
function deleteCookie(string $name, string $path = NULL, string $domain = NULL, bool $secure = NULL) {}
}

class ExportTest extends \Tester\TestCase
Expand Down
Loading

0 comments on commit 7fbb263

Please sign in to comment.