Я только проектирую систему, поэтому абстрактный пример
class User extends ActiveRecord
class UserManager
{
public function findByEmail($email)
{
return User::find()->where(['email' => $email])->one();
}
}
class SendPrivateMessage
{
public $emails = [];
public $message;
private $_userManager;
private $_currentUser;
public function __construct($userManager, $currentUser)
{
$this->_userManager = $userManager;
$this->_currentUser = $currentUser;
}
public function send()
{
foreach ($this->emails as $email)
{
$user = $this->findByEmail($email);
if ($user->privateMessageIsDisable()) {
$user->sendMessage($this->_currentUser, $this->message);
}
}
}
public function findByEmail($email)
{
return $this->_userManager->findByEmail($email);
}
}
Теперь как я вижу тестирование без базы данных
class UserManagerMock
{
public function findByEmail($email)
{
$data = AbstractBase::get($email); // Нужен этот механизм
return new UserMock($data);
}
}