PHP code example of helbrary / nette-tester-extension

1. Go to this page and download the library: Download helbrary/nette-tester-extension library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

helbrary / nette-tester-extension example snippets




e __DIR__ . '/../../vendor/helbrary/nette-tester-extension/src/BasePresenterTester.php';

final class TestPresenterActions extends \Helbrary\NetteTesterExtension\BaseMultiPresenterTester
{

    /**
     * TestGoodsPresenter constructor.
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function testActions()
    {
        $actions = [
            'Core:Customers' => [
                'actions' => [
                    [
                        'parameters' => ['action' => 'default'], // optional - default is empty array
                        'method' => 'GET', // optional - default is GET
                        'userId' => NULL, // optional - default is NULL
                        'userRole' => NULL, // optional - default is NULL
                        'identityData' => NULL, // optional - default is NULL
                    ],
                    [
                        'parameters' => ['id' => 1, 'action' => 'default'],
                    ],

                ]
            ]
        ];

        $this->checkWihtoutErorrs($actions);
    }
}

$testCase = new TestPresenterActions();
$testCase->run();
sh


__DIR__ . '/../../../../vendor/helbrary/nette-tester-extension/src/BasePresenterTester.php';

final class TestAccountPresenter extends \Helbrary\NetteTesterExtension\BasePresenterTester
{

	/**
	 * @var \Model\UserModel
	 */
	private $userModel;

	/**
	 * @var bool|\Model\User
	 */
	private $testingUser;

	/**
	 * TestGoodsPresenter constructor.
	 */
	public function __construct()
	{
		parent::__construct('Front:Account'); // Here is defined presenter which we want test
		$this->userModel = $this->container->getByType('\Model\UserModel');
		$this->testingUser = $this->userModel->find()->fetch(); // get some user from db
	}

	/**
	 * Test detail action of account presenter
	 */
	public function testDetail()
	{
		// if no user is logged in, expected redirect to Sign in
		$this->checkRedirectTo(array(
			'action' => 'detail',
			'id' => 8, // parameter id for action detail
		), 'Front:Sign:in');

		// if some user is logged in, expected that action detail will be render without error
		// after send this request is logged in user with id $this->testingUser->id
		$this->checkRequestNoError(array(
			'action' => 'detail',
		), 'GET', $this->testingUser->id);
	}
}

$testCase = new TestAccountPresenter();
$testCase->run();