PHP code example of englishdom / unitarum

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

    

englishdom / unitarum example snippets


class User
{
    protected $id;
    protected $name;
    protected $email;

    public function getId()
    {
        return $this->id;
    }

    public function setId($id)
    {
        $this->id = $id;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

$entity = new Entity\User();
$entity->setId(1);
$entity->setName('Test');
$entity->setEmail('[email protected]');

return ['table_name' => $entity];

use PHPUnit\Framework\TestCase;

class DatabaseTest extends TestCase
{
    protected static $unitarum;

    public static function setUpBeforeClass()
    {
        self::$unitarum = new Unitarum([
            OptionsInterface::FIXTURE_FOLDER_OPTION => '../data',
            OptionsInterface::DSN_OPTION => 'sqlite:data/sqlite.db',
        ]);
    }
}

class DatabaseTest extends TestCase
{
    protected static $unitarum;

    public static function setUpBeforeClass()
    {
        ...
    }
    
    public function setUp()
    {
        self::$unitarum->getDataBase()->startTransaction();
        // or notning
    }
    
    public function tearDown()
    {
        self::$unitarum->getDataBase()->rollbackTransaction();
        //or
        self::$unitarun->truncate();
    }
}

class DatabaseTest extends TestCase
{
    ...
    
    public function testApplication()
    {
        $user = new Entity\User();
        $user->setEmail('[email protected]');
        
        $role = new Entity\Role();
        $role->setRole('viewer');
        $role->setUserId($user->getId());
        
        self::$unitarum->user($user)->role($role);
        
        // test
        ...
    }
}