PHP code example of tatter / imposter

1. Go to this page and download the library: Download tatter/imposter 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/ */

    

tatter / imposter example snippets


service('auth')->login($userId);
service('auth')->logout();

if ($user = service('auth')->user()) {
    echo 'Logged in!';
}

helper('auth');

if ($userId = user_id()) {
    return true;
}

throw new RuntimeException('You must be authenticated!');

$user = new \Tatter\Imposter\Entities\User();
$user->groups = ['Administrators', 'Editors'];



use CodeIgniter\Test\CIUnitTestCase;
use Tatter\Imposter\Factories\ImposterFactory;
use Tatter\Users\UserProvider;

final class UserWidgetTest extends CIUnitTestCase
{
    public static function setUpBeforeClass(): void
    {
        UserProvider::addFactory(ImposterFactory::class, ImposterFactory::class);
    }
...


    protected function setUp(): void
    {
        parent::setUp();

        $user = ImposterFactory::fake();
        $user->permissions = ['widgets.create'];
        UserFactory::add($user);

        $this->userId = ImposterFactory::index();
    }

    protected function tearDown(): void
    {
        parent::tearDown();

        ImposterFactory::reset();
    }

    public testUserCanCreateWidget()
    {
        $user = service('users')->findById($this->userId);
        service('auth')->login($user);
        ...