Пример #1
0
    public function setUp()
    {
        // Schema
        $schema = <<<SQL
        CREATE TABLE "admin" (
        "id" INTEGER PRIMARY KEY,
        "username" VARCHAR NOT NULL,
        "password" VARCHAR NOT NULL,
        "email" VARCHAR NOT NULL,
        "api_key" VARCHAR NOT NULL
        );
SQL;
        $this->di = new Container(new Factory());
        $this->di->set('db', function () {
            return new \PDO('sqlite::memory:');
        });
        $this->di->get('db')->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $this->di->get('db')->exec($schema);
        require_once __DIR__ . '/_files/Admin.php';
        require_once __DIR__ . '/_files/AdminRepository.php';
        require_once __DIR__ . '/_files/AdminDatamapper.php';
        require_once __DIR__ . '/_files/AdminManager.php';
        // Dependencies
        $this->manager = new \Reservat\Manager\AdminManager($this->di);
        $admins = [['username' => 'abc', 'email' => '*****@*****.**', 'password' => \Reservat\Admin::hash('test'), 'api_key' => '1234567890'], ['username' => 'test1', 'email' => '*****@*****.**', 'password' => \Reservat\Admin::hash(':poop:'), 'api_key' => '1277777890'], ['username' => 'test2', 'email' => '*****@*****.**', 'password' => \Reservat\Admin::hash('cake'), 'api_key' => '1234444456']];
        foreach ($admins as $admin) {
            $admin = \Reservat\Admin::createFromArray($admin);
            $this->manager->getDatamapper()->insert($admin);
        }
    }
Пример #2
0
    public function setUp()
    {
        require_once __DIR__ . '/_files/Admin.php';
        require_once __DIR__ . '/_files/AdminRepository.php';
        require_once __DIR__ . '/_files/AdminDatamapper.php';
        require_once __DIR__ . '/_files/AdminManager.php';
        // Schema
        $userSchema = <<<SQL
        CREATE TABLE "admin" (
        "id" INTEGER PRIMARY KEY,
        "username" VARCHAR NOT NULL,
        "password" VARCHAR NOT NULL,
        "email" VARCHAR NOT NULL,
        "api_key" VARCHAR NOT NULL
        );
SQL;
        $sessionSchema = <<<SQL
        CREATE TABLE "session" (
        "id" INTEGER PRIMARY KEY,
        "session_id" VARCHAR NOT NULL,
        "user_id" INT,
        "data" TEXT,
        "expires" INT
        );
SQL;
        $this->di = new Container(new Factory());
        $this->di->set('db', function () {
            return new \PDO('sqlite::memory:');
        });
        $this->di->set('session', function () {
            return new Session($this->di, 'PDO');
        });
        $this->di->get('db')->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $this->di->get('db')->exec($userSchema);
        $this->di->get('db')->exec($sessionSchema);
        $testSessionData = [1, 'k4o6898jdru8e8gah9mkv5fss5', 1, 'userId|i:1;', (new \DateTime())->getTimeStamp() + 1000];
        $sql = "INSERT INTO session (id, session_id, user_id, data, expires) VALUES ('" . implode("','", $testSessionData) . "')";
        $this->di->get('db')->exec($sql);
        // Dependencies
        $this->manager = new \Reservat\Manager\AdminManager($this->di);
        $admins = [['username' => 'abc', 'email' => '*****@*****.**', 'password' => \Reservat\Admin::hash('test'), 'api_key' => '123456789'], ['username' => 'test1', 'email' => '*****@*****.**', 'password' => \Reservat\Admin::hash(':poop:'), 'api_key' => '085632241'], ['username' => 'test2', 'email' => '*****@*****.**', 'password' => \Reservat\Admin::hash('cake'), 'api_key' => '987654321']];
        foreach ($admins as $admin) {
            $admin = \Reservat\Admin::createFromArray($admin);
            $this->manager->getDatamapper()->insert($admin);
        }
    }
Пример #3
0
 public function testBasicEntity()
 {
     $admin = $this->manager->getEntity(['username' => 'PWesterdale', 'email' => '*****@*****.**', 'password' => \Reservat\Admin::hash('cake'), 'api_key' => '012345678']);
     $this->assertEquals($admin->verify('cake'), true);
 }
Пример #4
0
 public function getEntity($args)
 {
     return Admin::createFromArray($args);
 }