Nette Tester neukazuje chybu, která nastala

Pavel Janda
Člen | 977
+
0
-

Ahoj,

rád bych se zeptal na věc – jak donutit nette/tester, aby ukazoval, k jaké chybě došlo. Mám následující kód:

<?php declare(strict_types = 1);

use Tester\TestCase;

$container = require __DIR__ . '/bootstrap.php';

final class FooTest extends TestCase
{

	public function testFoo()
	{
		Assert::same(1, 1); // zde je chyba - neznáme třídu Assert
	}
}

(new FooTest($container))->run();

Když nad tímto testem spustím tester, ukáže se mi:

 _____ ___  ___ _____ ___  ___
|_   _/ __)( __/_   _/ __)| _ )
  |_| \___ /___) |_| \___ |_|_\  v2.4.2

Note: No php.ini is used.
PHP 8.1.4 (cli) | php -n | 8 threads

F

-- FAILED: FooTest.php
   Error: This test forgets to execute an assertion.


FAILURES! (1 test, 1 failure, 0.0 seconds)

Chyba je v tom, že kód nezná třídu „Assert“. Jakmile ji uvedu v use-statementu, test proběhne OK.

Potřeboval bych se ale dozvědět od testeru, k čemu během běhu tesu došlo – k jaké chybě.

Lze ho nějak donutit, aby mi to řekl? Páč Error: This test forgets to execute an assertion. není úplně pravda a nic moc mi to neřekne. Díky za info

Editoval Pavel Janda (13. 4. 2022 16:43)

Pavel Janda
Člen | 977
+
0
-

Když si cca na tomto (https://github.com/…nner/Job.php#L125) místě přečtu stdout procesu, uvidím:

ERROR: Class "Assert" not found
Unable to log error. You may try enable debug mode to inspect the problem.

Ale naprosto netuším, jestli to lze z testeru dostat nějak normálně..?

David Grudl
Nette Core | 8082
+
0
-

Zvláštní, mně stejná verze píše

-- FAILED: x.phpt
   Exited with error code 255 (expected 0)
   Error: Class "Assert" not found
Pavel Janda
Člen | 977
+
0
-

Můj OS: Mac (aso to bude tím, Mac OS sucks)

Mám s takovým chováním už nějakou historickou zkušenost. Můžu s tím nějak víc pomoci?

David Grudl
Nette Core | 8082
+
0
-

Zkusil jsem Windows i Ubuntu, ale tvuj problém nenasimuluju. Problém bude asi v tom /bootstrap.php', nějaký vlastní error handler, nebo něco podobného, ne?

Pavel Janda
Člen | 977
+
0
-

bootstrap.php, který vrací aplikační container:

<?php declare(strict_types = 1);

use App\Bootstrap;
use Tester\Environment;

require __DIR__ . '/../../vendor/autoload.php';

Environment::setup();

return Bootstrap::getContainer();

App\Bootstrap:

<?php declare(strict_types = 1);

namespace App;

use Nette\DI\Compiler;
use Nette\DI\Container;
use Nette\DI\ContainerLoader;
use Nette\DI\Extensions\ExtensionsExtension;
use Nette\DI\Helpers;
use Tracy\Debugger;

final class Bootstrap
{

	public static function getContainer(): Container
	{
		Debugger::enable(false);
		Debugger::$showBar = false;

		$loader = new ContainerLoader(__DIR__ . '/../temp', $developmentMode);

		/**
		 * @var Container
		 */
		$class = $loader->load(function (Compiler $compiler): void {
			$compiler->addConfig(
				['parameters' => Helpers::escape(['appDir' => __DIR__])]
			);

			$compiler->addExtension('extensions', new ExtensionsExtension());
			$compiler->loadConfig(__DIR__ . '/../config/config.neon');
		});

		return new $class();
	}
}

Vlastní error handler tam není, je tam nicméně nette a tracy.

netolicak
Člen | 4
+
0
-

Narážel jsem na stejný problém, způsobovalo to volání: \Tracy\Debugger::enable(false); Tudíž v testeru jsem se s Tracy musel rozloučit.