Nette Pro – Magazine 10/2017

by Honza Černý 8 months ago in Nette

Speed ​​up your websites

As you know, Nette Framework has excellent support for easy AJAX websites. So it's a shame that lots of sites built on Nette does not use this opportunity to speed up the web. The library of Vojta Dobeše nette.ajax.js which is currently a little bit old. Another help recently came up the Nittro, which grew up to version 2. Recently we have the Naja library.

Is it possible to try Nette Database without the whole framework, but with the beauty of DI and Tracy? Yes. New example in git repository

Jáchym Toušek (enumag) introduced an extensive package of Arachne libraries that brings some insights from the Symfony world or an alternative view of core Nette components.

In a Nutshell

Contribute – utils – an interesting widget, that can be used by several developers contributte/utils

Nextras – ORM – beta version of upcoming 3 nextras/orm

Dibi – v 3.1.0 dg/dibi/releases/tag/v3.1.0

Milo / Crypt — Simple class for encrypt and decrypt with signature gist/6fe7…813b

David Grudl – How to mock the final classes?…-final-tridy

In Conclusion

Thanks to partner of edition: Gamee

If you have ideas how to improve our next edition, please let me know. Have I forgotten something? Make sure to email me and we will include it in the next edition. We are still looking for partners who wish to address the growing community interested in our news.

Honza Cerny

Nette Pro – Magazine 9/2017

by Honza Černý 9 months ago in Nette

Support for PHP 7.2 is here!

For all who doesn't know about new type of versions of Nette Framewor 2.4, there is no planed 2.4.x version. All packages have their maintenance version, but Framework doesn’t have. There is build from (2017–08–29) with release notes, that is full compatible with incomming PHP version 7.2

We spent summer together at an extraordinary meeting Nette Camp and two excursions to Czech breweries. Definitely follow up the events next year. It's an interesting way to meet in an offline world. In September, the 90th anniversary Last Saturday is waiting for us.

In a Nutshell

Contribute — Minimalistic integration of Symfony/Console to Nette application contributte/console

Nextras — datagrid v 3.0.0rc nextras/datagrid/releases/tag/v3.0.0-rc2

Nextras — migration v3.0.5 & v3.1rc nextras/migrations/releases/tag/v3.0.5

PeckaDesign — asynchronous components

Nas — a component for nested selectbox NasExt/DependentSelectBox

In Conclusion

Thanks to partner of edition:

If you have ideas how to improve our next edition, please let me know. Have I forgotten something? Make sure to email me and we will include it in the next edition. We are still looking for partners who wish to address the growing community interested in our news.

Honza Cerny

PhpStorm and code completion for $this->template

by David Grudl 10 months ago in Nette

How to get rid of PhpStorm alerts on “undefined fields” and activate the code completion for $this->template in presenters?

So how to change this view with the underlined abc and the empty pop-up window:

Into this?

Simply. Just add the following annotation to the presenter (for example to BasePresenter):

 * @property-read \Nette\Bridges\ApplicationLatte\Template|\stdClass $template
abstract class BasePresenter extends Nette\Application\UI\Presenter

Note: In the latest versions of Nette, this annotation will be directly in the code.

Template class

The stdClass class in the annotation is a workaround for PhpStorm, which otherwise treats all variables as undefined. However, it is more interesting to create a class with a real list of the variables that the template uses, including their types. It may look like this:

class ArticleTemplate
    /** @var string */
    public $lang;

    /** @var int */
    public $page;

    /** @var string[] */
    public $menu;

    /** @var Model\Page */
    public $article;

And then put it in the annotation of a specific presenter instead of stdClass:

 * @property-read ArticleTemplate|\Nette\Bridges\ApplicationLatte\Template $template
final class ArticlePresenter extends Nette\Application\UI\Presenter

From now on, the message is perfect:

We still have to solve the suggestion in the template. So far, Latte plugin can't do it, but once it can, it could use the same template class. For example, there could be a new macro {template App\Presenters\ArticleTemplate} that will pass the template class name.

Nette Tester 2.0.0 is out

by Miloslav Hůla 10 months ago in Tester

Nette Tester 2 is finally out. I'll describe changes and new features in detail.


New Tester requires PHP in version 5.6 or newer and supports PHP 7.2. Simultaneously, support for HHVM has been dropped. There has been small opinion poll on this topic.

Changes in tests runner

Tester's default interpreter (when called without the -p option) is CLI now. It used to be CGI. You will see notice in console about it.

When you pass directory as a tester argument, it will find all *.phpt files as usual, but newly it will find all *Test.php files additionally.

The Tester used to run tests in order as they have been found. Now, it will run last time failing tests as first. For this purpose, the Tester uses temporary directory. Default is got by sys_get_temp_dir() and you can change it by explicit --temp <path> option. The --info call will help you find out currently used directory. Try to think about this new feature in relation to --stop-on-fail or --watch options. It may improve your workflow.

As mentioned in documentation, every test is run by PHP in separated process with -n option. So without php.ini file. Sometimes it is painful to tune up own php.ini file for tests. A new option -C is introduced, it causes that -n is not used and as a consequence, tests run with system-wide PHP settings.

Sometimes is good to know whether test is running by tester myTest.phpt or as an ordinary PHP script by php myTest.phpt. An environment variable will help you to recognize it:

if (getenv(Tester\Environment::RUNNER)) {
    # by Tester
} else {
    # other way

And when talking about environment variables, there is another one. When tests run in parallel, by default in 8 threads, you can be interested in a current thread number.

$threadNumber = getenv(Tester\Environment::THREAD);

Changes in testing framework

New modifiers for Assert::match() have been added. The %w% matches alphanumeric chars 0-9, a-z, A-Z and _ (underscore). The %% matches one % char.

Behavior of FileMock has been fixed, mainly in an append mode.

Another change concerns the TestCase. Now, the TestCase::tearDown() run always, even aften an error occurred in a testing method. Small BC break is that the TestCase::run() method does not accept arguments anymore. If you need to run a single testing method, use the TestCase::runTest($method, array $args = []) method.

New test file annotation @phpExtension has been added. When some of given extensions is not loaded, test will be skipped. You can use one annotation with multiple extensions, or split it to multiple annotations. For example:

 * @phpExtension pdo, pdo_pgsql
 * @phpExtension json

Completely new helper FileMutator has been added. Its purpose is to adjust source code of loaded files. The first real use case is removing final keyword from classes and class methods. Usage is simple. Call the Tester\Environment::bypassFinals() on the very top of a test file, it will setup FileMutator for you.

require 'bootstrap.php';
# Now, you can extend final classes or overload final class methods.

Changes in output formating

When other than expected exception is thrown in the Assert::exception(), its stack trace will be printed. It helps to find out, what is wrong.

If you are using Assert::match() with modifiers (%a%, %d% and so on), you will be pleasured by a new feature. In case of fail, modifiers are replaced by their matching values in output and dumps. An example will say more. Imagine test such:

$tested = "My name is Milo and I'm -65535 years old.";
Assert::match("My name is %S% and I'm %d% years old.", $tested);
# An output before the Tester 2
    Failed: 'My name is Milo and I'm -65535 years old.' should match
        ... 'My name is %S% and I'm %d% years old.'

# An output with new Tester
    Failed: 'My name is Milo and I'm -65535 years old.' should match
        ... 'My name is Milo and I'm %d% years old.'

Do you see that small difference? The %S% modifier is now replaced by a matching value and you don't need to decrypt where mismatch occurred. Very handy when matching long strings.

If you use code coverage functionality with a PHPDBG, some tests may fail due to a memory exhaustion. Coverage data collecting is a memory consuming operation. You can increase memory limits, or you can call Tester\CodeCoverage\Collector::flush(). It will write collected data into file and release occupied memory. Calling has no effect with Xdebug or when collecting is not running at all.

HTML output of code coverage has been facelifted. Check out an example.

And here we come with the biggest BC break in the Tester 2. Changes in the OutputHandler interface. Before I'll describe it, I have to make a short introduction how tests are handled internally by the Tester.

Inside the Tester, single test is represented by Test class instance. In a short, it contains test file path, test title, result code, captured standard output and so on. Check out the source code for details. These instances are passed to output handlers in the Tester 2. Refactored OutputHandler now looks as follows:

namespace Tester\Runner;

interface OutputHandler
    # Before testing, something like init phase.
    function begin();

    # When new test has been found. Called for every test before a testing starts.
    function prepare(Test $test);

    # Test achives some result.
    function finish(Test $test);

    # Called on a testing end. Not necessarily all tests have been run.
    function end();

Some other minor improvements have been done, like printing code coverage percent value into console, or dumping arrays in a short syntax.

In conclusion

The Tester's internal code went through more changes, but they are not important for end users. For example, Tester's code base now uses new Nette coding style with small true, false, null constants and use new code checker. Details can be found in commits history.

Documentation is up to date and is still on the same place as usual.

Many thanks to all contributors! Enjoy the new release!

Nette Pro / Magazine #4

by Honza Černý about a year ago in Nette

New Nette 2.4 is out

After a summer break, here comes a whole heap of news and info about what has been going on and what is in the picture. The hottest piece of news is the new version of Nette Framework 2.4. A complex overview of changes made to the framework, including all novelties related to versioning, can be found on the release webpage:…2-4-released. In short, in the future only respective packages will be versioned (such as the release described here:…4-2016-07-31). Other big changes that should be mentioned is Nette/Object replacement with traits, see David's talk from Hradec Králové:… and the fact the “guts” of Latte, a template system, have been rewritten (a video from Plzeň will be published on YouTube soon). Here is also a post bringing attention to what you need to be careful about when migrating:…nette-2-4-rc. If you're still unsure whether you should use the latest version of Nette Framework or not, why don't you read a short post from the Slevomat boys about changin to 2.4:…122388672512, there are more and more companies following the example. In case you run on 2.4 too, tweet with hashtag #nettefw.

Nette Camp

A four-day event filled with Nette and beer took place in a quaint village in Czech Paradise and judging from the reactions, it was a hit. Speaking on behalf of organisers, we have learnt yet a lot and let's hope it will be for the benefit of future events. You can expect Nette Camp 2017 again in the last two weeks of August. As a surprise we migrated to a new portal: .

Following several meetings with Tomáš Votruba, the Czech Symfony community care-taker, we put our heads together and we are starting to build a framework non specific php community. More news to be expected on twitter @pehapkari. Follow us for what's hot in the czech php world.

In a Nutshell

Nextras & Kdyby

Compatible extensions releases go hand in hand with the release of new Nette Framework version. Most packages are compatible with Nette 2.4 already, if sometimes in @dev versions for now. We are still waiting for some stable releases.


Petr Knap from Netpromotion released a simple PHP profiler with a Tracy extension:…ion/profiler

Nette and Webpack

Jirka Pudil wrote an article on how to interlink these two platforms in an easy way:…with-webpack

In Conclusion

If you have ideas how to improve our next edition, please let me know. Have I forgotten something? Make sure to email me and we will include it in the next edition. We are still looking for partners who wish to address the growing community interested in our news.

Honza Cerny

P.S.: David released a new framework version ready to support php 7.1 while I was writing my intro:…4-2016-09-30