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 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

This comment has been minimized.

Copy link
Member

dg commented Sep 9, 2019

Thanks

@dg dg merged commit 6c3cf4e into nette:master Sep 9, 2019
1 of 2 checks passed
1 of 2 checks passed
continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@dg

This comment has been minimized.

Copy link
Member

dg commented Sep 9, 2019

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

@janbarasek

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Member

dg commented Sep 9, 2019

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

@janbarasek

This comment has been minimized.

Copy link
Contributor Author

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

This comment has been minimized.

Copy link
Member

dg commented Sep 10, 2019

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

dg added a commit that referenced this pull request Sep 10, 2019
…_shutdown_function() (#411)
@janbarasek

This comment has been minimized.

Copy link
Contributor Author

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
Projects
None yet
2 participants
You can’t perform that action at this time.