init
This commit is contained in:
43
vendor/codeception/base/tests/data/services/UserModel.php
vendored
Normal file
43
vendor/codeception/base/tests/data/services/UserModel.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
require_once __DIR__.'/../app/data.php';
|
||||
|
||||
class UserModel
|
||||
{
|
||||
protected $id;
|
||||
protected $data = array();
|
||||
protected $saved = false;
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->data['name'];
|
||||
}
|
||||
|
||||
function setName($name)
|
||||
{
|
||||
$this->data['name'] = 'Mr. '.$name;
|
||||
}
|
||||
|
||||
function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
function get($param)
|
||||
{
|
||||
if (!isset($this->data[$param])) throw new \Exception('Key does not exist!');
|
||||
return $this->data[$param];
|
||||
}
|
||||
|
||||
function set($param, $value)
|
||||
{
|
||||
$this->data[$param] = $value;
|
||||
}
|
||||
|
||||
function save()
|
||||
{
|
||||
if (!$this->id) $this->id = uniqid();
|
||||
data::set($this->id, $this->data);
|
||||
$this->saved = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
30
vendor/codeception/base/tests/data/services/UserService.php
vendored
Normal file
30
vendor/codeception/base/tests/data/services/UserService.php
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class UserService
|
||||
{
|
||||
/**
|
||||
* @var UserModel
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
function __construct(UserModel $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
function create($name)
|
||||
{
|
||||
$this->user->setName($name);
|
||||
$this->user->set('role','user');
|
||||
$this->user->set('email',$name.'@service.com');
|
||||
$this->user->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function validateName($name)
|
||||
{
|
||||
if ($name == 'admin') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user