Nette/Tester: php modules are not loaded

6 years ago

kedrigern
Member | 102
+
0
-

Hi,

i tried write some test for my project (writen in nette):

php -c /etc/php.ini vendor/nette/tester/Tester/tester.php -c /etc/php.ini tests

and

php -c /etc/php.ini vendor/nette/tester/Tester/tester.php -p /usr/bin/php -c /etc/php.ini tests

Result is always error:

Fatal error: Uncaught exception 'Nette\NotSupportedException' with message 'PHP extension Tokenizer is not loaded.' in /var/www/html/project/vendor/nette/nette/Nette/Loaders/RobotLoader.php:54

I tried:

$ php -c /etc/php.ini -i | grep tokenizer.ini
/etc/php.d/tokenizer.ini,

So the tokenizer is loaded with /etc/php.ini config file.

Configuration: Fedora 20, php 5.5.7, nette/tester 0.9.5

6 years ago

Jan Tvrdík
Nette guru | 2559
+
0
-

Try this =)

php -c /etc/php.ini vendor/nette/tester/Tester/tester.php -c /etc/php.ini tests -c /etc/php.ini

6 years ago

kedrigern
Member | 102
+
0
-

No :).

Another ideas? Some minimal working example of testing nette app (not just one standalone class)?

6 years ago

kedrigern
Member | 102
+
0
-

No one using Nette/Testing for testing model with real DI (bootstrap) or presenters?

(I know that is not unit testing, its more integration testing, but can help too.)

6 years ago

Milo
Nette Core | 1149
+
0
-

This should work. Could you show source code of your test?

6 years ago

Milo
Nette Core | 1149
+
0
-

And few tips.

Test should runs and pass without Tester runner, it is better for debugging, e.g. you can dump list of loaded extensions in test. So, you can try:

php -c /etc/php.ini path/to/test.phpt

And when it pass with plain PHP bin, try with runner:

vendor/bin/tester -c /etc/php.ini path/to/test.phpt

Last edited by Milo (2014-01-09 10:47)

6 years ago

kedrigern
Member | 102
+
0
-

File tests/bootstrap.php:

<?php

// Load Nette Framework or autoloader generated by Composer
require __DIR__ . '/../vendor/autoload.php';

// configure environment tests specific
Tester\Environment::setup();
date_default_timezone_set('Europe/Prague');

$configurator = new Nette\Configurator;

// Enable Nette Debugger for error visualisation & logging
//$configurator->setDebugMode(TRUE);
//$configurator->enableDebugger(__DIR__ . '/../log');

// Specify folder for cache
$configurator->setTempDirectory(__DIR__ . '/../temp');


// Enable RobotLoader - this will load all classes automatically
$configurator->createRobotLoader()
    ->addDirectory(__DIR__ . '/../app')
    ->addDirectory(__DIR__ . '/../vendor/others')
    ->register();

// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/../app/config/config.neon');
$configurator->addConfig(__DIR__ . '/config/config.local.neon');    // special config, where is defined testing DB etc.
$container = $configurator->createContainer();

return $container;

tests/exampleTest.php:

<?php
use Tester\Assert;

Assert::same( 'Hello John', 'Hello John' );
$container =  require __DIR__ . "/bootstrap.php";


This works: /usr/bin/php -c /etc/php.ini tests/exampleTest.phpt It is returns no result (everythink ok). If I change the assert line to: Assert::same( 'Hello John', '' );, return:

Failed: '' should be
    ... 'Hello John'

in Tester/Framework/Assert.php(370)
in Tester/Framework/Assert.php(52) Tester\Assert::fail()
in <project>/tests/exampleTest.phpt(6) Tester\Assert::same()

But if I run:

/usr/bin/php -c /etc/php.ini vendor/nette/tester/Tester/tester.php -c /etc/php.ini -p /usr/bin/php tests/exampleTest.phpt

I get:

PHP 5.5.7 | '/usr/bin/php' -n -c '/etc/php.ini' | 1 threads

F

-- FAILED: <project>/tests/exampleTest.phpt
   Exited with error code 255 (expected 0)
   Nette\NotSupportedException: PHP extension Tokenizer is not loaded.

   in Nette/Loaders/RobotLoader.php(54)
   in Nette/common/Configurator.php(139) Nette\Loaders\RobotLoader->__construct()
   in <project>/tests/bootstrap.php(21) Nette\Configurator->createRobotLoader()
   in <project>/tests/exampleTest.phpt(4) require()


FAILURES! (1 tests, 1 failures, 0.0 seconds)

6 years ago

kedrigern
Member | 102
+
0
-

And I think I find the problem! Why tester run:

/usr/bin/php' -n -c '/etc/php.ini

Parameter -n is “no config”!

Last edited by kedrigern (2014-01-09 16:24)

6 years ago

kedrigern
Member | 102
+
0
-

Ok, there is the problematic line in Nette/Tester:

$phpArgs = $options['-c'] ? '-n -c ' . escapeshellarg($options['-c']) : '-n';

I sent the pull request

Last edited by kedrigern (2014-01-09 16:50)

6 years ago

kedrigern
Member | 102
+
+1
-

OK, after disscusion at Github I prepare config inspirated by distribution one:

[PHP]
extension=json.so
extension=tokenizer.so
extension=mbstring.so
extension=iconv.so
extension=pdo.so
extension=pdo_sqlite.so

include_path = "/etc/php.ini"

[Zend]

and everythink is ok too.

Last edited by kedrigern (2014-01-09 19:18)