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

Environment: File can be undefined. #411

Merged
merged 1 commit into from Sep 9, 2019
Merged

Environment: File can be undefined. #411

merged 1 commit into from Sep 9, 2019

Conversation

janbarasek
Copy link
Contributor

@janbarasek janbarasek commented Sep 9, 2019

  • bug fix
  • BC break? yes

In case of Doctrine ORM Schema update when all entities are loaded automatically, $trace with index file can be undefined.

Snímek obrazovky 2019-09-09 v 13 54 22

@dg
Copy link
Member

@dg dg commented Sep 9, 2019

Thanks

@dg dg merged commit 6c3cf4e into nette:master Sep 9, 2019
1 of 2 checks passed
@dg
Copy link
Member

@dg dg commented Sep 9, 2019

What is the reason that there is not file? Could you dump the trace here?

@janbarasek
Copy link
Contributor Author

@janbarasek janbarasek commented Sep 9, 2019

@dg In case of:

/**
 * Returns current test annotations.
 */
public static function getTestAnnotations(): array
{
	$trace = debug_backtrace();
	$file = $trace[count($trace) - 1]['file'] ?? null;
	if ($file === null) {
		echo \Tracy\Dumper::toTerminal($trace);
	}
	return Helpers::parseDocComment($file ? file_get_contents($file) : '') + ['file' => $file];
}

First part looks ok:

Snímek obrazovky 2019-09-09 v 17 54 29

But last part not:

Snímek obrazovky 2019-09-09 v 17 55 23

Source:

Snímek obrazovky 2019-09-09 v 17 58 15

Source code: https://github.com/baraja-core/doctrine/blob/master/src/OrmSchemaUpdateTool.php#L24

Called command in Terminal: php www/index.php o:s:u -f --dump-sql

I think the bug is in my TestCase class, because I should use if (isset(... in this construction here:

if (isset($_SERVER['NETTE_TESTER_RUNNER'])) {
	$di = Booting::bootForTests()->createContainer();

	(new QueryToLatexTest(
		$di->getByType(Tokenizer::class),
		$di->getByType(QueryNormalizer::class)
	))->run();
}

I think it's relatively complex problem. Do you understand the principle?

@dg
Copy link
Member

@dg dg commented Sep 9, 2019

And what is in www/index.php? How is OrmSchemaUpdateTool::run() called?

@janbarasek
Copy link
Contributor Author

@janbarasek janbarasek commented Sep 9, 2019

@dg I use Nette sandbox:

<?php

declare(strict_types=1);

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

App\Booting::boot()
	->createContainer()
	->getByType(Nette\Application\Application::class)
	->run();

But in Container in initialize() method is (in Container specific for CLI):

OrmSchemaUpdateTool::setContainer($this);
register_shutdown_function([OrmSchemaUpdateTool::class, 'run']);

When I think about it, it wasn't very smart. I use it as a hack to call a specific piece of code in CLI mode.

@dg
Copy link
Member

@dg dg commented Sep 10, 2019

So it is called via register_shutdown_function(), thats why file is missing.

dg pushed a commit that referenced this issue Sep 10, 2019
@janbarasek
Copy link
Contributor Author

@janbarasek janbarasek commented Sep 10, 2019

I think yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants