Cannot load presenter ‚Homepage: default‘

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
motorcb
Člen | 552
+
0
-

Zdravím, stáhl jsem si poslední verzi sandboxu a napsal takovýto test:

<?php

namespace Test;

use Nette,
	Tester,
	Tester\Assert;

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

class RegistrationTest extends Tester\TestCase
{
	private $container;

	function __construct(Nette\DI\Container $container)
	{
		$this->container = $container;
	}

	function setUp()
	{
	}


    function testHomepage()
    {
        $presenterFactory = $this->container->getByType('Nette\Application\IPresenterFactory');

        $presenter = $presenterFactory->createPresenter('Homepage:default');

        $presenter->autoCanonicalize = FALSE;

        $response = $presenter->run();


    }

}

$test = new RegistrationTest($container);
$test->run();

Když ho spustím: vendor\bin\tester.bat -c tests/php-win.ini tests
tak mi padá na hlášce:

-- FAILED: sandbox\tests\RegistrationTest.phpt
   Exited with error code 255 (expected 0)
   Nette\Application\InvalidPresenterException: Cannot load presenter 'Homepage:default', class 'App\HomepageModule\Presenters\defaultPresenter' was not found.

   in src\Application\PresenterFactory.php(74)
   in src\Application\PresenterFactory.php(52) Nette\Application\PresenterFactory->getPresenterClass()
   in sandbox\tests\RegistrationTest.phpt(39) Nette\Application\PresenterFactory->createPresenter()
   in [internal function]Test\RegistrationTest->testHomepage()
   in src\Framework\TestCase.php(130) call_user_func_array()
   in src\Framework\TestCase.php(113) Tester\TestCase->runTest()
   in src\Framework\TestCase.php(48) Tester\TestCase->runMethod()
   in sandbox\tests\RegistrationTest.phpt(61) Tester\TestCase->run()


FAILURES! (2 tests, 1 failure, 0.2 seconds)

Proč tester hledá Homepage:default v App\HomepageModule\Presenters\defaultPresenter když nemám žádný modul?

Děkuji za rady

David Matějka
Moderator | 6445
+
+2
-

default je akce, ne soucast nazvu presenteru ⇒ do createPresenter posilej jen ‚Homepage‘

motorcb
Člen | 552
+
0
-

@DavidMatějka Díky, chyba u mne :-) Opravil jsem:

function testHomepage()
{
    // z DI kontejneru, který vytvořil bootstrap.php, získáme instanci PresenterFactory
    $presenterFactory = $this->container->getByType('Nette\Application\IPresenterFactory');

    // a vyrobíme presenter Sign
    $presenter = $presenterFactory->createPresenter('Homepage');

    $presenter->autoCanonicalize = FALSE;

		$request = new Nette\Application\Request('default', 'GET');
		$response = $presenter->run($request);

    Assert::true( $response instanceof Nette\Application\Responses\TextResponse );
    Assert::true( $response->getSource() instanceof Nette\Templating\ITemplate );

    $html = (string) $response->getSource();

    $dom = Tester\DomQuery::fromHtml($html);

    Assert::true( $dom->has('input[name="username"]') );
    Assert::true( $dom->has('input[name="password"]') );

}

Ale stále padám na hlášce:

-- FAILED: sandbox\tests\RegistrationTest.phpt
   Exited with error code 255 (expected 0)
   Nette\Application\BadRequestException: Page not found. Missing template 'C:\_temp\sandbox\app\presenters\templates\default\default.latte'.

   in Application\UI\Presenter.php(690)
   in Application\UI\Presenter.php(463) Nette\Application\UI\Presenter->error()
   in Application\UI\Presenter.php(223) Nette\Application\UI\Presenter->sendTemplate()
   in sandbox\tests\RegistrationTest.phpt(44) Nette\Application\UI\Presenter->run()
   in [internal function]Test\RegistrationTest->testHomepage()
   in src\Framework\TestCase.php(130) call_user_func_array()
   in src\Framework\TestCase.php(113) Tester\TestCase->runTest()
   in src\Framework\TestCase.php(48) Tester\TestCase->runMethod()
   in sandbox\tests\RegistrationTest.phpt(62) Tester\TestCase->run()

FAILURES! (2 tests, 1 failure, 0.2 seconds)

Router mám klasický ze sandboxu. Cache jsem smazal.
Proč se pokouší zobrazit šablonu presenters\templates\default\default.latte ?? Měl by zobrazit šablonu presenters/templates/Homepage/default.latte

David Matějka
Moderator | 6445
+
0
-

Request ma vypadat takto:

$request = new Nette\Application\Request('Homepage', 'GET', ['action' => 'default']);
motorcb
Člen | 552
+
0
-

@DavidMatějka paráda, díky moc, posunul jsem se dál. Jak opravit tohle?

Assert::true( $response->getSource() instanceof Nette\Templating\ITemplate );

ITemplate je depricated. Čím ji nahradit? Díky