Skip to content

Commit

Permalink
v2, php >= 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed Feb 21, 2019
1 parent 183a738 commit d648f85
Show file tree
Hide file tree
Showing 41 changed files with 573 additions and 665 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ os:
- linux

php:
- 5.4
- 5.5
- 5.6

This comment has been minimized.

Copy link
@adaamz

adaamz Feb 21, 2019

Why you need to test on 5.6+7.0, if composer requirement is php >= 7.1?

This comment has been minimized.

Copy link
@MartkCz

MartkCz Feb 21, 2019

Contributor

I have not noticed that :)

- 7.0
- 7.1
- hhvm
- nightly

matrix:
allow_failures:
- php: hhvm
- php: nightly
include:
- php: 7.1
env: PHP_STAN=1
Expand Down
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
"desc": "Testing helpers for nette presenters and components",
"require-dev": {
"codeception/codeception": "~2.2",
"nette/application": "~2.3",
"nette/forms": "~2.3",
"latte/latte": "~2.3"
"nette/application": "^3.0",
"nette/forms": "^3.0",
"latte/latte": "^3.0"
},
"require": {
"php": ">= 5.4"
"php": ">= 7.1"
},
"autoload": {
"psr-4": {
"WebChemistry\\Testing\\": "src/"
}
},
"config": {
"bin-dir": "bin"
}
"scripts": {
"tests": "vendor/bin/codecept run",
"stan": "vendor/bin/phpstan analyse src --level=3 --ansi --no-progress"
},
"minimum-stability": "RC"
}
33 changes: 3 additions & 30 deletions src/Components/Control.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components;

Expand All @@ -10,39 +10,12 @@ class Control {
/** @var Presenter */
private $presenter;

/** @var callable[] */
private $controls = [];

public function __construct() {
$this->presenter = new Presenter();
$this->presenter->addMapping('*', 'WebChemistry\Testing\Components\Presenters\*Presenter');
}

/**
* @param string $name
* @param callable $callback
* @return static
*/
public function addControl($name, callable $callback) {
$this->controls[$name] = $callback;

return $this;
}

/**
* @param string $name
* @return IComponent
*/
public function createControl($name) {
return call_user_func($this->controls[$name]);
}

/**
* @param string $name
* @return ControlRequest
*/
public function createRequest($name) {
return new ControlRequest($this->presenter, $this->createControl($name), $name);
public function createRequest(IComponent $control, string $name = 'control'): ControlRequest {
return new ControlRequest($this->presenter, $control, $name);
}

}
10 changes: 5 additions & 5 deletions src/Components/FileSystem.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components;

Expand All @@ -9,7 +9,7 @@ class FileSystem {
*
* @param string $dir
*/
public function removeDirRecursive($dir) {
public function removeDirRecursive(string $dir): void {
$this->rmDir($dir);
}

Expand All @@ -19,7 +19,7 @@ public function removeDirRecursive($dir) {
* @param string $dir
* @return int
*/
public function itemCount($dir) {
public function itemCount(string $dir): int {
$objects = scandir($dir);
$count = 0;
foreach ($objects as $object) {
Expand Down Expand Up @@ -59,7 +59,7 @@ public function fileCount($dir) {
* @param string $dir
* @return int
*/
public function dirCount($dir) {
public function dirCount(string $dir): int {
$objects = scandir($dir);
$count = 0;
foreach ($objects as $object) {
Expand All @@ -74,7 +74,7 @@ public function dirCount($dir) {
return $count;
}

protected function rmDir($dir) {
protected function rmDir(string $dir): void {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
Expand Down
53 changes: 5 additions & 48 deletions src/Components/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,25 @@

use Nette\Application\IPresenter;
use Nette\ComponentModel\IContainer;
use WebChemistry\Testing\Components\Presenters\FormPresenter;
use WebChemistry\Testing\Components\Requests\FormRequest;
use Nette\Application\UI;

class Form {

/** @var callable[] */
private $forms;

/** @var IPresenter|IContainer */
private $presenter;

/** @var array */
private $counter = [];

/** @var Presenter */
private $presenters;

public function __construct() {
$this->presenters = new Presenter();
$this->presenters->addMapping('*', 'WebChemistry\Testing\Components\Presenters\*Presenter');

$this->presenter = $this->presenters->createPresenter('Form');
}

/**
* @param string $name
* @param callable
*/
public function addForm($name, callable $form) {
$this->forms[$name] = $form;
$this->counter[$name] = 1;
}

/**
* @param string $name
* @return \Nette\Application\UI\Form
*/
public function createForm($name) {
$args = func_get_args(); array_shift($args);
$form = call_user_func_array($this->forms[$name], $args);
$this->presenter->addComponent($form, $name . $this->counter[$name]++);

return $form;
}

/**
* @param string $name
* @param ... $params
* @return \Nette\Application\UI\Form
*/
public function createPureForm($name) {
$args = func_get_args(); array_shift($args);

return call_user_func_array($this->forms[$name], $args);
$this->presenter = $this->presenters->createPresenter(FormPresenter::class);
}

/**
* @param string $name
* @param ... $params
* @return FormRequest
*/
public function createRequest($name) {
return new FormRequest($this->presenters, call_user_func_array([$this, 'createPureForm'], func_get_args()), $name);
public function createRequest(UI\Form $form, string $name = 'form'): FormRequest {
return new FormRequest($this->presenters, $form, $name);
}

}
16 changes: 2 additions & 14 deletions src/Components/Helpers/Helpers.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components\Helpers;

use Nette\Utils\Strings;

class Helpers {

public static function analyzeParams(array &$params, $controlName) {
public static function analyzeParams(array &$params, string $controlName) {
if (!$controlName) {
return;
}
Expand All @@ -19,16 +19,4 @@ public static function analyzeParams(array &$params, $controlName) {
}
}

public static function extractPathToArray($path, $val = NULL) {
$arr = [];
$pointer = &$arr;
foreach (explode('.', $path) as $item) {
$pointer[$item] = [];
$pointer = &$pointer[$item];
}
$pointer = $val;

return $arr;
}

}
4 changes: 2 additions & 2 deletions src/Components/Helpers/LatteFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components\Helpers;

Expand All @@ -7,7 +7,7 @@

class LatteFactory implements ILatteFactory {

public function create() {
public function create(): Latte\Engine {
return new Latte\Engine();
}

Expand Down
13 changes: 13 additions & 0 deletions src/Components/Helpers/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components\Helpers;

use Nette\Http\Request as NetteRequest;

final class Request extends NetteRequest {

public function isSameSite(): bool {
return true;
}

}
8 changes: 4 additions & 4 deletions src/Components/Helpers/RouterStub.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components\Helpers;

Expand All @@ -10,11 +10,11 @@ class RouterStub implements IRouter {

public $returnUrl = 'http://localhost/';

public function match(Nette\Http\IRequest $httpRequest) {
return $httpRequest;
public function match(Nette\Http\IRequest $httpRequest): array {
return [];
}

public function constructUrl(Request $appRequest, Nette\Http\Url $refUrl) {
public function constructUrl(array $params, Nette\Http\UrlScript $urlScript): string {
return $this->returnUrl;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Hierarchy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components;

Expand All @@ -13,7 +13,7 @@ public function __construct() {
$this->presenterService = new Presenter();
}

public function createHierarchy($name) {
public function createHierarchy(string $name): HierarchyPresenter {
return new HierarchyPresenter($name, $this->presenterService);
}

Expand Down
22 changes: 7 additions & 15 deletions src/Components/Hierarchy/Control.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
<?php declare(strict_types = 1);

namespace WebChemistry\Testing\Components\Hierarchy;

use Nette\Application\IPresenter;
use WebChemistry\Testing\Components\Helpers\Helpers;
use WebChemistry\Testing\Components\Requests\PresenterRequest;
use WebChemistry\Testing\Components\Responses\ControlResponse;
Expand All @@ -23,10 +22,7 @@ public function __construct(PresenterRequest $request, Container $control) {
$this->control = $control;
}

/**
* @return Container
*/
public function getObject() {
public function getObject(): Container {
return $this->control;
}

Expand All @@ -35,7 +31,7 @@ public function getObject() {
* @return Control
* @throws TestException
*/
public function getControl($name) {
public function getControl(string $name): Control {
$ctrl = $this->control->getComponent($name, TRUE);
if ($ctrl instanceof UI\Form) {
throw new TestException("Component '$name' is form, use getForm instead of getControl.");
Expand All @@ -52,7 +48,7 @@ public function getControl($name) {
* @return Form
* @throws TestException
*/
public function getForm($name) {
public function getForm(string $name): Form {
$ctrl = $this->control->getComponent($name);
if (!$ctrl instanceof UI\Form) {
throw new TestException("Component '$name' is not form, use getControl instead of getForm.");
Expand All @@ -61,11 +57,7 @@ public function getForm($name) {
return new Form($this->request, $ctrl);
}

/**
* @param array $params
* @return static
*/
public function addParams(array $params) {
public function addParams(array $params): self {
Helpers::analyzeParams($params, $this->control->lookupPath('Nette\Application\IPresenter'));
$this->request->addParams($params);

Expand All @@ -76,13 +68,13 @@ public function addParams(array $params) {
* @param string $signal
* @return ControlResponse
*/
public function sendSignal($signal) {
public function sendSignal(string $signal): ControlResponse {
$this->request->setSignal($this->control->lookupPath('Nette\Application\IPresenter') . '-' . $signal);

return new ControlResponse($this->request->send(), $this->control->lookupPath('Nette\Application\IPresenter'));
}

public function render() {
public function render(): string {
ob_start();

$this->request->send()->getPresenter()->getComponent($this->control->lookupPath('Nette\Application\IPresenter'))->render();
Expand Down
Loading

0 comments on commit d648f85

Please sign in to comment.