diff --git a/.gitattributes b/.gitattributes index f6cd387..ab73207 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ .gitattributes export-ignore .gitignore export-ignore +.github export-ignore .travis.yml export-ignore tests/ export-ignore *.sh eol=lf diff --git a/.github/issue_template.md b/.github/issue_template.md new file mode 100644 index 0000000..a6a22a9 --- /dev/null +++ b/.github/issue_template.md @@ -0,0 +1,16 @@ +- bug report? yes/no +- feature request? yes/no +- version: ?.?.? + +### Description +... + +### Steps To Reproduce +... If possible a minimal demo of the problem ... + + diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..8bcf026 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,12 @@ +- bug fix? yes/no +- new feature? yes/no +- BC break? yes/no +- doc PR: nette/docs#??? + + diff --git a/.travis.yml b/.travis.yml index e5bdfac..a9801d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,14 +2,22 @@ language: php php: - 5.6 - 7.0 + - 7.1 +env: matrix: include: - php: 5.6 env: dependencies="--prefer-lowest --prefer-stable" + - php: 7.0 + env: coverage=on + + allow_failures: + - php: 7.0 + env: coverage=on script: - - vendor/bin/tester tests -s $coverage + - vendor/bin/tester tests -s $coverageArgs - php temp/code-checker/src/code-checker.php --short-arrays after_failure: @@ -20,12 +28,12 @@ before_script: # Install Nette Tester & Code Checker - travis_retry composer update --no-interaction --prefer-dist $dependencies - travis_retry composer create-project nette/code-checker temp/code-checker ~2.5 --no-interaction - - if [ $TRAVIS_PHP_VERSION == "7.0" ]; then coverage="-p phpdbg --coverage ./coverage.xml --coverage-src ./src"; fi + - if [ "$coverage" == "on" ]; then coverageArgs="-p phpdbg --coverage ./coverage.xml --coverage-src ./src"; fi after_script: # Report Code Coverage - > - if [ "$coverage" != "" ]; then + if [ "$coverage" == "on" ]; 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 diff --git a/composer.json b/composer.json index bb43bda..20c2506 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,10 @@ ], "require": { "php": ">=5.6.0", - "nette/utils": "^2.4" + "nette/utils": "^2.4 || ~3.0.0" }, "require-dev": { - "nette/tester": "~2.0", + "nette/tester": "^2.0", "tracy/tracy": "^2.3" }, "conflict": { diff --git a/contributing.md b/contributing.md index 860882b..184152c 100644 --- a/contributing.md +++ b/contributing.md @@ -1,27 +1,33 @@ How to contribute & use the issue tracker ========================================= -The issue tracker is the preferred channel for bug reports, features requests -and submitting pull requests, but please respect the following restrictions: +Nette welcomes your contributions. There are several ways to help out: -* Please **do not** use the issue tracker for personal support requests (use - [Nette forum](https://forum.nette.org) or [Stack Overflow](http://stackoverflow.com)). +* Create an issue on GitHub, if you have found a bug +* Write test cases for open bug issues +* Write fixes for open bug/feature issues, preferably with test cases included +* Contribute to the [documentation](https://nette.org/en/writing) -* Please **do not** derail or troll issues. Keep the discussion on topic and - respect the opinions of others. +Issues +------ -* Use the GitHub **issue search** — check if the issue has already been - reported. +Please **do not use the issue tracker to ask questions**. We will be happy to help you +on [Nette forum](https://forum.nette.org) or chat with us on [Gitter](https://gitter.im/nette/nette). -A good **bug report** shouldn't leave others needing to chase you up for more +A good bug report shouldn't leave others needing to chase you up for more information. Please try to be as detailed as possible in your report. **Feature requests** are welcome. But take a moment to find out whether your idea 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](https://nette.org/en/contributing) in order to make -the contribution process easy and effective for everyone involved. +Contributing +------------ -Thanks! +If you'd like to contribute, please take a moment to read [the contributing guide](https://nette.org/en/contributing). + +The best way to propose a feature is to discuss your ideas on [Nette forum](https://forum.nette.org) before implementing them. + +Please do not fix whitespace, format code, or make a purely cosmetic patch. + +Thanks! :heart: diff --git a/readme.md b/readme.md index c472eef..8337c68 100644 --- a/readme.md +++ b/readme.md @@ -77,15 +77,15 @@ Monitoring and lookup of components or paths using `lookup` is **very precisely Iterating over children ----------------------- -There is a method `getComponents($deep = FALSE, $type = NULL)` for that. First parameter determines if the components should be looked up in depth (recursively). With `TRUE`, it not only iterates all it's children, but also all chilren of it's children, etc. Second parameter servers as an optional filter by class or interface. +There is a method `getComponents($deep = false, $type = null)` for that. First parameter determines if the components should be looked up in depth (recursively). With `true`, it not only iterates all it's children, but also all chilren of it's children, etc. Second parameter servers as an optional filter by class or interface. For example, this is the way how validation of forms is "internally"((this is done by framework itself, you don't have to call it explicitly)) performed: ```php -$valid = TRUE; -foreach ($form->getComponents(TRUE, Nette\Forms\IControl::class) as $control) { +$valid = true; +foreach ($form->getComponents(true, Nette\Forms\IControl::class) as $control) { if (!$control->getRules()->validate()) { - $valid = FALSE; + $valid = false; break; } } diff --git a/src/ComponentModel/Component.php b/src/ComponentModel/Component.php index 04e003a..7100f6c 100644 --- a/src/ComponentModel/Component.php +++ b/src/ComponentModel/Component.php @@ -16,7 +16,7 @@ * Components are objects implementing IComponent. They has parent component and own name. * * @property-read string $name - * @property-read IContainer|NULL $parent + * @property-read IContainer|null $parent */ abstract class Component implements IComponent { @@ -34,8 +34,8 @@ abstract class Component implements IComponent public function __construct() { - list($parent, $name) = func_get_args() + [NULL, NULL]; - if ($parent !== NULL) { + list($parent, $name) = func_get_args() + [null, null]; + if ($parent !== null) { $parent->addComponent($this, $name); } elseif (is_string($name)) { @@ -46,38 +46,38 @@ public function __construct() /** * Lookup hierarchy for component specified by class or interface name. - * @param string class/interface type - * @param bool throw exception if component doesn't exist? - * @return IComponent + * @param string|null + * @param bool + * @return IComponent|null */ - public function lookup($type, $need = TRUE) + public function lookup($type, $throw = true) { if (!isset($this->monitors[$type])) { // not monitored or not processed yet $obj = $this->parent; $path = self::NAME_SEPARATOR . $this->name; $depth = 1; - while ($obj !== NULL) { + while ($obj !== null) { $parent = $obj->getParent(); - if ($type ? $obj instanceof $type : $parent === NULL) { + if ($type ? $obj instanceof $type : $parent === null) { break; } $path = self::NAME_SEPARATOR . $obj->getName() . $path; $depth++; $obj = $parent; // IComponent::getParent() if ($obj === $this) { - $obj = NULL; // prevent cycling + $obj = null; // prevent cycling } } if ($obj) { - $this->monitors[$type] = [$obj, $depth, substr($path, 1), FALSE]; + $this->monitors[$type] = [$obj, $depth, substr($path, 1), false]; } else { - $this->monitors[$type] = [NULL, NULL, NULL, FALSE]; // not found + $this->monitors[$type] = [null, null, null, false]; // not found } } - if ($need && $this->monitors[$type][0] === NULL) { + if ($throw && $this->monitors[$type][0] === null) { throw new Nette\InvalidStateException("Component '$this->name' is not attached to '$type'."); } @@ -88,36 +88,36 @@ public function lookup($type, $need = TRUE) /** * Lookup for component specified by class or interface name. Returns backtrace path. * A path is the concatenation of component names separated by self::NAME_SEPARATOR. - * @param string class/interface type - * @param bool throw exception if component doesn't exist? - * @return string + * @param string|null + * @param bool + * @return string|null */ - public function lookupPath($type = NULL, $need = TRUE) + public function lookupPath($type = null, $throw = true) { - $this->lookup($type, $need); + $this->lookup($type, $throw); return $this->monitors[$type][2]; } /** * Starts monitoring. - * @param string class/interface type + * @param string * @return void */ public function monitor($type) { if (empty($this->monitors[$type][3])) { - if ($obj = $this->lookup($type, FALSE)) { + if ($obj = $this->lookup($type, false)) { $this->attached($obj); } - $this->monitors[$type][3] = TRUE; // mark as monitored + $this->monitors[$type][3] = true; // mark as monitored } } /** * Stops monitoring. - * @param string class/interface type + * @param string * @return void */ public function unmonitor($type) @@ -152,7 +152,7 @@ protected function detached($obj) /** - * @return string + * @return string|null */ public function getName() { @@ -162,7 +162,7 @@ public function getName() /** * Returns the container if any. - * @return IContainer|NULL + * @return IContainer|null */ public function getParent() { @@ -171,38 +171,38 @@ public function getParent() /** - * Sets the parent of this component. This method is managed by containers and should + * Sets or removes the parent of this component. This method is managed by containers and should * not be called by applications - * @param IContainer New parent or null if this component is being removed from a parent + * @param IContainer * @param string - * @return self + * @return static * @throws Nette\InvalidStateException * @internal */ - public function setParent(IContainer $parent = NULL, $name = NULL) + public function setParent(IContainer $parent = null, $name = null) { - if ($parent === NULL && $this->parent === NULL && $name !== NULL) { + if ($parent === null && $this->parent === null && $name !== null) { $this->name = $name; // just rename return $this; - } elseif ($parent === $this->parent && $name === NULL) { + } elseif ($parent === $this->parent && $name === null) { return $this; // nothing to do } // A component cannot be given a parent if it already has a parent. - if ($this->parent !== NULL && $parent !== NULL) { + if ($this->parent !== null && $parent !== null) { throw new Nette\InvalidStateException("Component '$this->name' already has a parent."); } // remove from parent? - if ($parent === NULL) { + if ($parent === null) { $this->refreshMonitors(0); - $this->parent = NULL; + $this->parent = null; } else { // add to parent $this->validateParent($parent); $this->parent = $parent; - if ($name !== NULL) { + if ($name !== null) { $this->name = $name; } @@ -227,11 +227,11 @@ protected function validateParent(IContainer $parent) /** * Refreshes monitors. * @param int - * @param array|NULL (array = attaching, NULL = detaching) + * @param array|null (array = attaching, null = detaching) * @param array * @return void */ - private function refreshMonitors($depth, & $missing = NULL, & $listeners = []) + private function refreshMonitors($depth, &$missing = null, &$listeners = []) { if ($this instanceof IContainer) { foreach ($this->getComponents() as $component) { @@ -241,11 +241,11 @@ private function refreshMonitors($depth, & $missing = NULL, & $listeners = []) } } - if ($missing === NULL) { // detaching + if ($missing === null) { // detaching foreach ($this->monitors as $type => $rec) { if (isset($rec[1]) && $rec[1] > $depth) { if ($rec[3]) { // monitored - $this->monitors[$type] = [NULL, NULL, NULL, TRUE]; + $this->monitors[$type] = [null, null, null, true]; $listeners[] = [$this, $rec[0]]; } else { // not monitored, just randomly cached unset($this->monitors[$type]); @@ -262,25 +262,25 @@ private function refreshMonitors($depth, & $missing = NULL, & $listeners = []) unset($this->monitors[$type]); } elseif (isset($missing[$type])) { // known from previous lookup - $this->monitors[$type] = [NULL, NULL, NULL, TRUE]; + $this->monitors[$type] = [null, null, null, true]; } else { - $this->monitors[$type] = NULL; // forces re-lookup - if ($obj = $this->lookup($type, FALSE)) { + $this->monitors[$type] = null; // forces re-lookup + if ($obj = $this->lookup($type, false)) { $listeners[] = [$this, $obj]; } else { - $missing[$type] = TRUE; + $missing[$type] = true; } - $this->monitors[$type][3] = TRUE; // mark as monitored + $this->monitors[$type][3] = true; // mark as monitored } } } if ($depth === 0) { // call listeners - $method = $missing === NULL ? 'detached' : 'attached'; + $method = $missing === null ? 'detached' : 'attached'; $prev = []; foreach ($listeners as $item) { - if (!in_array($item, $prev, TRUE)) { + if (!in_array($item, $prev, true)) { $item[0]->$method($item[1]); $prev[] = $item; } @@ -297,17 +297,17 @@ private function refreshMonitors($depth, & $missing = NULL, & $listeners = []) */ public function __clone() { - if ($this->parent === NULL) { + if ($this->parent === null) { return; } elseif ($this->parent instanceof Container) { $this->parent = $this->parent->_isCloning(); - if ($this->parent === NULL) { // not cloning + if ($this->parent === null) { // not cloning $this->refreshMonitors(0); } } else { - $this->parent = NULL; + $this->parent = null; $this->refreshMonitors(0); } } @@ -329,5 +329,4 @@ public function __wakeup() { throw new Nette\NotImplementedException('Object unserialization is not supported by class ' . get_class($this)); } - } diff --git a/src/ComponentModel/Container.php b/src/ComponentModel/Container.php index a3d5dd9..2847ae1 100644 --- a/src/ComponentModel/Container.php +++ b/src/ComponentModel/Container.php @@ -13,14 +13,14 @@ /** * ComponentContainer is default implementation of IContainer. * - * @property-read \ArrayIterator $components + * @property-read \Iterator $components */ class Container extends Component implements IContainer { /** @var IComponent[] */ private $components = []; - /** @var IComponent|NULL */ + /** @var IComponent|null */ private $cloning; @@ -30,14 +30,14 @@ class Container extends Component implements IContainer /** * Adds the specified component to the IContainer. * @param IComponent - * @param string - * @param string - * @return self + * @param string|int + * @param string|int + * @return static * @throws Nette\InvalidStateException */ - public function addComponent(IComponent $component, $name, $insertBefore = NULL) + public function addComponent(IComponent $component, $name, $insertBefore = null) { - if ($name === NULL) { + if ($name === null) { $name = $component->getName(); } @@ -62,7 +62,7 @@ public function addComponent(IComponent $component, $name, $insertBefore = NULL) throw new Nette\InvalidStateException("Circular reference detected while adding component '$name'."); } $obj = $obj->getParent(); - } while ($obj !== NULL); + } while ($obj !== null); // user checking $this->validateChildComponent($component); @@ -102,17 +102,17 @@ public function removeComponent(IComponent $component) } unset($this->components[$name]); - $component->setParent(NULL); + $component->setParent(null); } /** * Returns component specified by name or path. - * @param string + * @param string|int * @param bool throw exception if component doesn't exist? - * @return IComponent|NULL + * @return IComponent|null */ - public function getComponent($name, $need = TRUE) + public function getComponent($name, $throw = true) { if (isset($this->components[$name])) { return $this->components[$name]; @@ -126,13 +126,13 @@ public function getComponent($name, $need = TRUE) } else { $a = strpos($name, self::NAME_SEPARATOR); - if ($a !== FALSE) { + if ($a !== false) { $ext = (string) substr($name, $a + 1); $name = substr($name, 0, $a); } if ($name === '') { - if ($need) { + if ($throw) { throw new Nette\InvalidArgumentException('Component or subcomponent name must not be empty string.'); } return; @@ -156,13 +156,13 @@ public function getComponent($name, $need = TRUE) return $this->components[$name]; } elseif ($this->components[$name] instanceof IContainer) { - return $this->components[$name]->getComponent($ext, $need); + return $this->components[$name]->getComponent($ext, $throw); - } elseif ($need) { + } elseif ($throw) { throw new Nette\InvalidArgumentException("Component with name '$name' is not container and cannot have '$ext' component."); } - } elseif ($need) { + } elseif ($throw) { $hint = Nette\Utils\ObjectMixin::getSuggestion(array_merge( array_keys($this->components), array_map('lcfirst', preg_filter('#^createComponent([A-Z0-9].*)#', '$1', get_class_methods($this))) @@ -174,8 +174,8 @@ public function getComponent($name, $need = TRUE) /** * Component factory. Delegates the creation of components to a createComponent method. - * @param string component name - * @return IComponent the created component (optionally) + * @param string + * @return IComponent|null */ protected function createComponent($name) { @@ -194,11 +194,11 @@ protected function createComponent($name) /** * Iterates over components. - * @param bool recursive? - * @param string class types filter - * @return \ArrayIterator + * @param bool + * @param string + * @return \Iterator */ - public function getComponents($deep = FALSE, $filterType = NULL) + public function getComponents($deep = false, $filterType = null) { $iterator = new RecursiveComponentIterator($this->components); if ($deep) { @@ -238,7 +238,7 @@ public function __clone() foreach ($this->components as $name => $component) { $this->components[$name] = clone $component; } - $oldMyself->cloning = NULL; + $oldMyself->cloning = null; } parent::__clone(); } @@ -246,12 +246,11 @@ public function __clone() /** * Is container cloning now? - * @return NULL|IComponent + * @return IComponent|null * @internal */ public function _isCloning() { return $this->cloning; } - } diff --git a/src/ComponentModel/IComponent.php b/src/ComponentModel/IComponent.php index 96fbf2d..6d8f5dc 100644 --- a/src/ComponentModel/IComponent.php +++ b/src/ComponentModel/IComponent.php @@ -17,13 +17,13 @@ interface IComponent const NAME_SEPARATOR = '-'; /** - * @return string + * @return string|null */ function getName(); /** * Returns the container if any. - * @return IContainer|NULL + * @return IContainer|null */ function getParent(); @@ -31,8 +31,7 @@ function getParent(); * Sets the parent of this component. * @param IContainer * @param string - * @return void + * @return static */ - function setParent(IContainer $parent = NULL, $name = NULL); - + function setParent(IContainer $parent = null, $name = null); } diff --git a/src/ComponentModel/IContainer.php b/src/ComponentModel/IContainer.php index 08fb59e..0a5eb6e 100644 --- a/src/ComponentModel/IContainer.php +++ b/src/ComponentModel/IContainer.php @@ -17,8 +17,8 @@ interface IContainer extends IComponent /** * Adds the specified component to the IContainer. * @param IComponent - * @param string - * @return void + * @param string|int + * @return static */ function addComponent(IComponent $component, $name); @@ -31,17 +31,16 @@ function removeComponent(IComponent $component); /** * Returns single component. - * @param string - * @return IComponent|NULL + * @param string|int + * @return IComponent|null */ function getComponent($name); /** * Iterates over a components. - * @param bool recursive? - * @param string class types filter + * @param bool + * @param string * @return \Iterator */ - function getComponents($deep = FALSE, $filterType = NULL); - + function getComponents($deep = false, $filterType = null); } diff --git a/src/ComponentModel/RecursiveComponentIterator.php b/src/ComponentModel/RecursiveComponentIterator.php index c39360a..a265a38 100644 --- a/src/ComponentModel/RecursiveComponentIterator.php +++ b/src/ComponentModel/RecursiveComponentIterator.php @@ -43,5 +43,4 @@ public function count() { return iterator_count($this); } - } diff --git a/tests/ComponentModel/Container.attached.phpt b/tests/ComponentModel/Container.attached.phpt index d810aac..c940a21 100644 --- a/tests/ComponentModel/Container.attached.phpt +++ b/tests/ComponentModel/Container.attached.phpt @@ -13,43 +13,58 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container implements ArrayAccess { - function attached($obj) + public function attached($obj) { Notes::add(get_class($this) . '::ATTACHED(' . get_class($obj) . ')'); } - function detached($obj) + + public function detached($obj) { Notes::add(get_class($this) . '::detached(' . get_class($obj) . ')'); } - function offsetSet($name, $component) + + public function offsetSet($name, $component) { $this->addComponent($component, $name); } - function offsetGet($name) + + public function offsetGet($name) { - return $this->getComponent($name, TRUE); + return $this->getComponent($name, true); } - function offsetExists($name) + + public function offsetExists($name) { - return $this->getComponent($name) !== NULL; + return $this->getComponent($name) !== null; } - function offsetUnset($name) + + public function offsetUnset($name) { - $this->removeComponent($this->getComponent($name, TRUE)); + $this->removeComponent($this->getComponent($name, true)); } } -class A extends TestClass {} -class B extends TestClass {} -class C extends TestClass {} -class D extends TestClass {} -class E extends TestClass {} +class A extends TestClass +{ +} +class B extends TestClass +{ +} +class C extends TestClass +{ +} +class D extends TestClass +{ +} +class E extends TestClass +{ +} $d = new D; $d['e'] = new E; @@ -81,7 +96,7 @@ $a['b'] = $b; Assert::same('b-c-d-e', $d['e']->lookupPath('A')); Assert::same($a, $d['e']->lookup('A')); Assert::same('b-c-d-e', $d['e']->lookupPath()); -Assert::same($a, $d['e']->lookup(NULL)); +Assert::same($a, $d['e']->lookup(null)); Assert::same('c-d-e', $d['e']->lookupPath('B')); Assert::same($b, $d['e']->lookup('B')); @@ -91,30 +106,25 @@ Notes::fetch(); // clear class FooForm extends TestClass { - protected function validateParent(\Nette\ComponentModel\IContainer $parent) { parent::validateParent($parent); $this->monitor(__CLASS__); } - } class FooControl extends TestClass { - protected function validateParent(\Nette\ComponentModel\IContainer $parent) { parent::validateParent($parent); $this->monitor('FooPresenter'); $this->monitor('TestClass'); // double } - } class FooPresenter extends TestClass { - } $presenter = new FooPresenter(); diff --git a/tests/ComponentModel/Container.clone.phpt b/tests/ComponentModel/Container.clone.phpt index c27ee5c..9baf34e 100644 --- a/tests/ComponentModel/Container.clone.phpt +++ b/tests/ComponentModel/Container.clone.phpt @@ -14,39 +14,45 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container implements ArrayAccess { - function attached($obj) + public function attached($obj) { Notes::add(get_class($this) . '::ATTACHED(' . get_class($obj) . ')'); } - function detached($obj) + + public function detached($obj) { Notes::add(get_class($this) . '::detached(' . get_class($obj) . ')'); } - function offsetSet($name, $component) + + public function offsetSet($name, $component) { $this->addComponent($component, $name); } - function offsetGet($name) + + public function offsetGet($name) { - return $this->getComponent($name, TRUE); + return $this->getComponent($name, true); } - function offsetExists($name) + + public function offsetExists($name) { - return $this->getComponent($name) !== NULL; + return $this->getComponent($name) !== null; } - function offsetUnset($name) + + public function offsetUnset($name) { - $this->removeComponent($this->getComponent($name, TRUE)); + $this->removeComponent($this->getComponent($name, true)); } } -function export($obj) { +function export($obj) +{ $res = ['(' . get_class($obj) . ')' => $obj->getName()]; if ($obj instanceof IContainer) { foreach ($obj->getComponents() as $name => $child) { @@ -54,14 +60,24 @@ function export($obj) { } } return $res; -}; +} -class A extends TestClass {} -class B extends TestClass {} -class C extends TestClass {} -class D extends TestClass {} -class E extends TestClass {} +class A extends TestClass +{ +} +class B extends TestClass +{ +} +class C extends TestClass +{ +} +class D extends TestClass +{ +} +class E extends TestClass +{ +} $a = new A; $a['b'] = new B; @@ -78,7 +94,7 @@ Assert::same([ 'C::ATTACHED(A)', ], Notes::fetch()); -Assert::same('b-c-d-e', $a['b']['c']['d']['e']->lookupPath('A', FALSE)); +Assert::same('b-c-d-e', $a['b']['c']['d']['e']->lookupPath('A', false)); // ==> clone 'c' @@ -88,9 +104,9 @@ Assert::same([ 'C::detached(A)', ], Notes::fetch()); -Assert::null($dolly['d']['e']->lookupPath('A', FALSE)); +Assert::null($dolly['d']['e']->lookupPath('A', false)); -Assert::same('d-e', $dolly['d']['e']->lookupPath('C', FALSE)); +Assert::same('d-e', $dolly['d']['e']->lookupPath('C', false)); // ==> clone 'b' @@ -111,7 +127,7 @@ Assert::same([ ], Notes::fetch()); Assert::same([ - '(A)' => NULL, + '(A)' => null, 'children' => [ 'b' => [ '(B)' => 'b', diff --git a/tests/ComponentModel/Container.commonFactory.addComponent.phpt b/tests/ComponentModel/Container.commonFactory.addComponent.phpt index 8c4a3af..eeabc91 100644 --- a/tests/ComponentModel/Container.commonFactory.addComponent.phpt +++ b/tests/ComponentModel/Container.commonFactory.addComponent.phpt @@ -13,12 +13,10 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponent($name) { $this->addComponent(new self, $name); } - } diff --git a/tests/ComponentModel/Container.commonFactory.addComponentWithreturn.phpt b/tests/ComponentModel/Container.commonFactory.addComponentWithreturn.phpt index 042c0f9..8419622 100644 --- a/tests/ComponentModel/Container.commonFactory.addComponentWithreturn.phpt +++ b/tests/ComponentModel/Container.commonFactory.addComponentWithreturn.phpt @@ -13,13 +13,11 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponent($name) { $this->addComponent($component = new self, $name); return $component; } - } diff --git a/tests/ComponentModel/Container.commonFactory.error.parent.phpt b/tests/ComponentModel/Container.commonFactory.error.parent.phpt index 9f27df9..910ee8a 100644 --- a/tests/ComponentModel/Container.commonFactory.error.parent.phpt +++ b/tests/ComponentModel/Container.commonFactory.error.parent.phpt @@ -13,12 +13,10 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponent($name) { return $this->getComponent('a'); } - } diff --git a/tests/ComponentModel/Container.commonFactory.error.type.phpt b/tests/ComponentModel/Container.commonFactory.error.type.phpt index 4979d52..e6fd3d5 100644 --- a/tests/ComponentModel/Container.commonFactory.error.type.phpt +++ b/tests/ComponentModel/Container.commonFactory.error.type.phpt @@ -13,12 +13,10 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponent($name) { return new stdClass; } - } diff --git a/tests/ComponentModel/Container.commonFactory.return.phpt b/tests/ComponentModel/Container.commonFactory.return.phpt index bd2514d..92021fc 100644 --- a/tests/ComponentModel/Container.commonFactory.return.phpt +++ b/tests/ComponentModel/Container.commonFactory.return.phpt @@ -13,12 +13,10 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponent($name) { return new self; } - } diff --git a/tests/ComponentModel/Container.factory.addComponent.phpt b/tests/ComponentModel/Container.factory.addComponent.phpt index f8a095e..c5b1882 100644 --- a/tests/ComponentModel/Container.factory.addComponent.phpt +++ b/tests/ComponentModel/Container.factory.addComponent.phpt @@ -13,12 +13,10 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponentB($name) { $this->addComponent(new self, $name); } - } diff --git a/tests/ComponentModel/Container.factory.addComponentWithreturn.phpt b/tests/ComponentModel/Container.factory.addComponentWithreturn.phpt index fef53b6..5e5364c 100644 --- a/tests/ComponentModel/Container.factory.addComponentWithreturn.phpt +++ b/tests/ComponentModel/Container.factory.addComponentWithreturn.phpt @@ -13,13 +13,11 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponentB($name) { $this->addComponent($component = new self, $name); return $component; } - } diff --git a/tests/ComponentModel/Container.factory.error.phpt b/tests/ComponentModel/Container.factory.error.phpt index a905880..6679b22 100644 --- a/tests/ComponentModel/Container.factory.error.phpt +++ b/tests/ComponentModel/Container.factory.error.phpt @@ -13,11 +13,9 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponentB($name) { } - } diff --git a/tests/ComponentModel/Container.factory.remove.phpt b/tests/ComponentModel/Container.factory.remove.phpt index 51362aa..0456588 100644 --- a/tests/ComponentModel/Container.factory.remove.phpt +++ b/tests/ComponentModel/Container.factory.remove.phpt @@ -13,14 +13,12 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponentB($name) { $this->addComponent($b = new self, $name); $this->removeComponent($b); return new self; } - } diff --git a/tests/ComponentModel/Container.factory.return.phpt b/tests/ComponentModel/Container.factory.return.phpt index e76afb5..77c4a3f 100644 --- a/tests/ComponentModel/Container.factory.return.phpt +++ b/tests/ComponentModel/Container.factory.return.phpt @@ -13,12 +13,10 @@ require __DIR__ . '/../bootstrap.php'; class TestClass extends Container { - public function createComponentB($name) { return new self; } - } diff --git a/tests/ComponentModel/Container.iterator.phpt b/tests/ComponentModel/Container.iterator.phpt index 6a9a526..f1c0350 100644 --- a/tests/ComponentModel/Container.iterator.phpt +++ b/tests/ComponentModel/Container.iterator.phpt @@ -20,7 +20,7 @@ class ComponentX extends Component { } -$c = new Container(NULL, 'top'); +$c = new Container(null, 'top'); $c->addComponent(new Container, 'one'); $c->addComponent(new ComponentX, 'two'); @@ -41,7 +41,7 @@ Assert::same([ // Filter -$list = $c->getComponents(FALSE, 'Button'); +$list = $c->getComponents(false, 'Button'); Assert::same([ 'button1', ], array_keys(iterator_to_array($list))); @@ -60,7 +60,7 @@ Assert::same([ // Recursive -$list = $c->getComponents(TRUE); +$list = $c->getComponents(true); Assert::same([ 'one', 'inner', @@ -84,7 +84,7 @@ Assert::same([ // Recursive & filter I -$list = $c->getComponents(TRUE, 'Button'); +$list = $c->getComponents(true, 'Button'); Assert::same([ 'button2', 'button1', @@ -92,7 +92,7 @@ Assert::same([ // Recursive & filter II -$list = $c->getComponents(TRUE, Nette\ComponentModel\Container::class); +$list = $c->getComponents(true, Nette\ComponentModel\Container::class); Assert::same([ 'one', 'inner2', diff --git a/tests/ComponentModel/Container.suggestions.phpt b/tests/ComponentModel/Container.suggestions.phpt index cc963ae..45386f5 100644 --- a/tests/ComponentModel/Container.suggestions.phpt +++ b/tests/ComponentModel/Container.suggestions.phpt @@ -13,23 +13,24 @@ require __DIR__ . '/../bootstrap.php'; class TestContainer extends Container { - public function createComponentPublic() { } + public static function createComponentPublicStatic() { } + protected function createComponentProtected() { } + private function createComponentPrivate() { } - } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 39183ee..2d4fa00 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -17,16 +17,17 @@ class Notes { public static $notes = []; + public static function add($message) { self::$notes[] = $message; } + public static function fetch() { $res = self::$notes; self::$notes = []; return $res; } - }