Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with nette/application 3.2.3 #12

Merged
merged 9 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/coding-style.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Coding style

on:
- push
- pull_request

jobs:
tests:
runs-on: ubuntu-latest

name: PHP
steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1

- run: composer install --no-progress --prefer-dist

- run: composer cs
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ composer.lock
bin/*
tests/_output
tests/Support/_generated
.php-cs-fixer.cache
33 changes: 33 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

return (new Config())
->setRiskyAllowed(true)
->setRules([
'@PHP81Migration' => true,
'@PHP80Migration:risky' => true,
'@Symfony' => true,
'phpdoc_to_param_type' => true,
'phpdoc_to_property_type' => true,
'phpdoc_to_return_type' => true,
// Override some Symfony rules.
'braces_position' => [
'functions_opening_brace' => 'same_line',
'classes_opening_brace' => 'same_line',
],
'concat_space' => ['spacing' => 'one'],
'no_null_property_initialization' => false,
'yoda_style' => false,
])
->setIndent("\t")
->setFinder(
(new Finder())
->ignoreDotFiles(false)
->ignoreVCSIgnored(true)
->in(__DIR__)
)
;
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
"type": "library",
"desc": "Testing helpers for nette presenters and components",
"require-dev": {
"codeception/codeception": "^5.0",
"nette/application": "^3.2",
"nette/forms": "^3.1.12",
"codeception/codeception": "^5.0.0",
"codeception/module-asserts": "^3.0",
"friendsofphp/php-cs-fixer": "^3.56",
"latte/latte": "^3.0",
"codeception/module-asserts": "^3.0"
"nette/application": "^3.2",
"nette/forms": "^3.1.12"
},
"require": {
"php": ">= 8.0"
Expand All @@ -27,8 +28,13 @@
}
},
"scripts": {
"cs": "php-cs-fixer fix --verbose --dry-run --diff",
"fix": "php-cs-fixer fix --verbose --diff",
"tests": "vendor/bin/codecept run",
"stan": "vendor/bin/phpstan analyse src --level=3 --ansi --no-progress"
},
"minimum-stability": "RC"
"minimum-stability": "RC",
"config": {
"sort-packages": true
}
}
15 changes: 7 additions & 8 deletions src/Components/Control.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

namespace WebChemistry\Testing\Components;

use Nette\ComponentModel\IComponent;
use WebChemistry\Testing\Components\Requests\ControlRequest;

class Control {

/** @var Presenter */
private $presenter;
private PresenterFactory $presenterFactory;

public function __construct() {
$this->presenter = new Presenter();
$this->presenterFactory = new PresenterFactory();
}

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

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

declare(strict_types=1);

namespace WebChemistry\Testing\Components;

class FileSystem {

/**
* Removes directory $dir (including) and sub-directories if contains
*
* @param string $dir
* Removes directory $dir (including) and sub-directories if contains.
*/
public function removeDirRecursive(string $dir): void {
$this->rmDir($dir);
}

/**
* Returns count of directories, files, ... without . and ..
*
* @param string $dir
* @return int
*/
public function itemCount(string $dir): int {
$objects = scandir($dir);
Expand All @@ -26,38 +22,32 @@ public function itemCount(string $dir): int {
if ($object === '.' || $object === '..') {
continue;
}
$count++;
++$count;
}

return $count;
}

/**
* Returns count of files
*
* @param string $dir
* @return int
* Returns count of files.
*/
public function fileCount($dir) {
public function fileCount(string $dir): int {
$objects = scandir($dir);
$count = 0;
foreach ($objects as $object) {
if ($object === '.' || $object === '..') {
continue;
}
if (is_file($dir . '/' . $object)) {
$count++;
++$count;
}
}

return $count;
}

/**
* Returns count of directories
*
* @param string $dir
* @return int
* Returns count of directories.
*/
public function dirCount(string $dir): int {
$objects = scandir($dir);
Expand All @@ -67,7 +57,7 @@ public function dirCount(string $dir): int {
continue;
}
if (is_dir($dir . '/' . $object)) {
$count++;
++$count;
}
}

Expand All @@ -89,5 +79,4 @@ protected function rmDir(string $dir): void {
rmdir($dir);
}
}

}
20 changes: 9 additions & 11 deletions src/Components/Form.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

namespace WebChemistry\Testing\Components;

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

class Form {
private IPresenter|IContainer $presenter;

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

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

public function __construct() {
$this->presenters = new Presenter();
$this->presenter = $this->presenters->createPresenter(FormPresenter::class);
$this->presenterFactory = new PresenterFactory();
$this->presenter = $this->presenterFactory->createPresenter(FormPresenter::class);
}

public function createRequest(UI\Form $form, string $name = 'form'): FormRequest {
return new FormRequest($this->presenters, $form, $name);
return new FormRequest($this->presenterFactory, $form, $name);
}

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

declare(strict_types=1);

namespace WebChemistry\Testing\Components\Helpers;

class Helpers {

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

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

declare(strict_types=1);

namespace WebChemistry\Testing\Components\Helpers;

use Latte;
use Nette\Bridges\ApplicationLatte\LatteFactory as ILatteFactory;

class LatteFactory implements ILatteFactory {

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

}
6 changes: 3 additions & 3 deletions src/Components/Helpers/Request.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php declare(strict_types = 1);
<?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;
}

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

declare(strict_types=1);

namespace WebChemistry\Testing\Components\Helpers;

use Nette;
use Nette\Routing\Router;

class RouterStub implements Router {

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

public function match(Nette\Http\IRequest $httpRequest): array {
Expand All @@ -16,5 +17,4 @@ public function match(Nette\Http\IRequest $httpRequest): array {
public function constructUrl(array $params, Nette\Http\UrlScript $urlScript): string {
return $this->returnUrl;
}

}
13 changes: 6 additions & 7 deletions src/Components/Hierarchy.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php declare(strict_types = 1);
<?php

declare(strict_types=1);

namespace WebChemistry\Testing\Components;

use WebChemistry\Testing\Components\Hierarchy\Presenter as HierarchyPresenter;

class Hierarchy {

/** @var Presenter */
private $presenterService;
private PresenterFactory $presenterFactory;

public function __construct() {
$this->presenterService = new Presenter();
$this->presenterFactory = new PresenterFactory();
}

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

}
Loading