remove some getter/setter

This commit is contained in:
Dennis Eichhorn 2020-11-24 17:31:20 +01:00
parent a440a1b5c0
commit 949593c2e0
14 changed files with 81 additions and 239 deletions

View File

@ -71,13 +71,13 @@ final class ApiController extends Controller
{ {
if (!empty($val = $this->validateQAQuestionCreate($request))) { if (!empty($val = $this->validateQAQuestionCreate($request))) {
$response->set('qa_question_create', new FormValidation($val)); $response->set('qa_question_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400); $response->header->status = RequestStatusCode::R_400;
return; return;
} }
$question = $this->createQAQuestionFromRequest($request, $response, $data); $question = $this->createQAQuestionFromRequest($request, $response, $data);
$this->createModel($request->getHeader()->getAccount(), $question, QAQuestionMapper::class, 'question', $request->getOrigin()); $this->createModel($request->header->account, $question, QAQuestionMapper::class, 'question', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Question', 'Question successfully created.', $question); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Question', 'Question successfully created.', $question);
} }
@ -97,12 +97,12 @@ final class ApiController extends Controller
$mardkownParser = new Markdown(); $mardkownParser = new Markdown();
$question = new QAQuestion(); $question = new QAQuestion();
$question->setName((string) $request->getData('title')); $question->name = (string) $request->getData('title');
$question->setQuestion((string) $request->getData('plain')); $question->question = (string) $request->getData('plain');
$question->setLanguage((string) $request->getData('language')); $question->setLanguage((string) $request->getData('language'));
$question->setCategory(new NullQACategory((int) $request->getData('category'))); $question->setCategory(new NullQACategory((int) $request->getData('category')));
$question->setStatus((int) $request->getData('status')); $question->setStatus((int) $request->getData('status'));
$question->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); $question->createdBy = new NullAccount($request->header->account);
if (!empty($tags = $request->getDataJson('tags'))) { if (!empty($tags = $request->getDataJson('tags'))) {
foreach ($tags as $tag) { foreach ($tags as $tag) {
@ -113,7 +113,7 @@ final class ApiController extends Controller
$internalResponse = new HttpResponse(); $internalResponse = new HttpResponse();
$this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse, $data); $this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse, $data);
$question->addTag($internalResponse->get($request->getUri()->__toString())['response']); $question->addTag($internalResponse->get($request->uri->__toString())['response']);
} else { } else {
$question->addTag(new NullTag((int) $tag['id'])); $question->addTag(new NullTag((int) $tag['id']));
} }
@ -167,13 +167,13 @@ final class ApiController extends Controller
{ {
if (!empty($val = $this->validateQAAnswerCreate($request))) { if (!empty($val = $this->validateQAAnswerCreate($request))) {
$response->set('qa_answer_create', new FormValidation($val)); $response->set('qa_answer_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400); $response->header->status = RequestStatusCode::R_400;
return; return;
} }
$answer = $this->createQAAnswerFromRequest($request); $answer = $this->createQAAnswerFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $answer, QAAnswerMapper::class, 'answer', $request->getOrigin()); $this->createModel($request->header->account, $answer, QAAnswerMapper::class, 'answer', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Answer', 'Answer successfully created.', $answer); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Answer', 'Answer successfully created.', $answer);
} }
@ -191,10 +191,10 @@ final class ApiController extends Controller
$mardkownParser = new Markdown(); $mardkownParser = new Markdown();
$answer = new QAAnswer(); $answer = new QAAnswer();
$answer->setAnswer((string) $request->getData('plain')); $answer->answer = (string) $request->getData('plain');
$answer->setQuestion(new NullQAQuestion((int) $request->getData('question'))); $answer->question = new NullQAQuestion((int) $request->getData('question'));
$answer->setStatus((int) $request->getData('status')); $answer->setStatus((int) $request->getData('status'));
$answer->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); $answer->createdBy = new NullAccount($request->header->account);
return $answer; return $answer;
} }
@ -241,21 +241,21 @@ final class ApiController extends Controller
{ {
if (!empty($val = $this->validateQACategoryCreate($request))) { if (!empty($val = $this->validateQACategoryCreate($request))) {
$response->set('qa_category_create', new FormValidation($val)); $response->set('qa_category_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400); $response->header->status = RequestStatusCode::R_400;
return; return;
} }
$category = $this->createQACategoryFromRequest($request); $category = $this->createQACategoryFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $category, QACategoryMapper::class, 'category', $request->getOrigin()); $this->createModel($request->header->account, $category, QACategoryMapper::class, 'category', $request->getOrigin());
$l11nRequest = new HttpRequest($request->getUri()); $l11nRequest = new HttpRequest($request->uri);
$l11nRequest->setData('category', $category->getId()); $l11nRequest->setData('category', $category->getId());
$l11nRequest->setData('name', $request->getData('name')); $l11nRequest->setData('name', $request->getData('name'));
$l11nRequest->setData('language', $request->getData('language')); $l11nRequest->setData('language', $request->getData('language'));
$l11nQACategory = $this->createQACategoryL11nFromRequest($l11nRequest); $l11nQACategory = $this->createQACategoryL11nFromRequest($l11nRequest);
$this->createModel($request->getHeader()->getAccount(), $l11nQACategory, QACategoryL11nMapper::class, 'tag_l11n', $request->getOrigin()); $this->createModel($request->header->account, $l11nQACategory, QACategoryL11nMapper::class, 'tag_l11n', $request->getOrigin());
$category->setName($l11nQACategory); $category->setName($l11nQACategory);
@ -277,7 +277,7 @@ final class ApiController extends Controller
//$category->setApp(new NullQAApp((int) ($request->getData('app') ?? 1))); //$category->setApp(new NullQAApp((int) ($request->getData('app') ?? 1)));
if ($request->getData('parent') !== null) { if ($request->getData('parent') !== null) {
$category->setParent(new NullQACategory((int) $request->getData('parent'))); $category->parent = new NullQACategory((int) $request->getData('parent'));
} }
return $category; return $category;
@ -340,13 +340,13 @@ final class ApiController extends Controller
{ {
if (!empty($val = $this->validateQACategoryL11nCreate($request))) { if (!empty($val = $this->validateQACategoryL11nCreate($request))) {
$response->set('qa_category_l11n_create', new FormValidation($val)); $response->set('qa_category_l11n_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400); $response->header->status = RequestStatusCode::R_400;
return; return;
} }
$l11nQACategory = $this->createQACategoryL11nFromRequest($request); $l11nQACategory = $this->createQACategoryL11nFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $l11nQACategory, QACategoryL11nMapper::class, 'qa_category_l11n', $request->getOrigin()); $this->createModel($request->header->account, $l11nQACategory, QACategoryL11nMapper::class, 'qa_category_l11n', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Category localization successfully created', $l11nQACategory); $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Category localization successfully created', $l11nQACategory);
} }
@ -367,7 +367,7 @@ final class ApiController extends Controller
$l11nQACategory->setLanguage((string) ( $l11nQACategory->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage() $request->getData('language') ?? $request->getLanguage()
)); ));
$l11nQACategory->setName((string) ($request->getData('name') ?? '')); $l11nQACategory->name = (string) ($request->getData('name') ?? '');
return $l11nQACategory; return $l11nQACategory;
} }

View File

@ -43,7 +43,7 @@ class QAAnswer implements \JsonSerializable
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private $answer = ''; public $answer = '';
/** /**
* Answer raw. * Answer raw.
@ -51,7 +51,7 @@ class QAAnswer implements \JsonSerializable
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private $answerRaw = ''; public $answerRaw = '';
/** /**
* Question * Question
@ -59,7 +59,7 @@ class QAAnswer implements \JsonSerializable
* @var QAQuestion * @var QAQuestion
* @since 1.0.0 * @since 1.0.0
*/ */
private QAQuestion $question; public QAQuestion $question;
/** /**
* Is accepted answer. * Is accepted answer.
@ -75,7 +75,7 @@ class QAAnswer implements \JsonSerializable
* @var Account * @var Account
* @since 1.0.0 * @since 1.0.0
*/ */
private Account $createdBy; public Account $createdBy;
/** /**
* Created at. * Created at.
@ -83,7 +83,7 @@ class QAAnswer implements \JsonSerializable
* @var \DateTimeImmutable * @var \DateTimeImmutable
* @since 1.0.0 * @since 1.0.0
*/ */
private \DateTimeImmutable $createdAt; public \DateTimeImmutable $createdAt;
/** /**
* Constructor. * Constructor.
@ -213,44 +213,6 @@ class QAAnswer implements \JsonSerializable
return $this->isAccepted; return $this->isAccepted;
} }
/**
* Get created by
*
* @return Account
*
* @since 1.0.0
*/
public function getCreatedBy() : Account
{
return $this->createdBy;
}
/**
* Set created by
*
* @param Account $account Creator
*
* @return void
*
* @since 1.0.0
*/
public function setCreatedBy(Account $account) : void
{
$this->createdBy = $account;
}
/**
* Get created at
*
* @return \DateTimeImmutable
*
* @since 1.0.0
*/
public function getCreatedAt() : \DateTimeImmutable
{
return $this->createdAt;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -45,10 +45,20 @@ class QACategory implements \JsonSerializable
/** /**
* Parent category. * Parent category.
* *
* @var null|QACategory * @var QACategory
* @since 1.0.0 * @since 1.0.0
*/ */
private ?self $parent = null; public self $parent;
/**
* Constructor.
*
* @sicne 1.0.0
*/
public function __construct()
{
$this->parent = new NullQACategory();
}
/** /**
* Get id. * Get id.
@ -88,40 +98,14 @@ class QACategory implements \JsonSerializable
if ($name instanceof QACategoryL11n) { if ($name instanceof QACategoryL11n) {
$this->name = $name; $this->name = $name;
} elseif ($this->name instanceof QACategoryL11n && \is_string($name)) { } elseif ($this->name instanceof QACategoryL11n && \is_string($name)) {
$this->name->setName($name); $this->name->name = $name;
} elseif (\is_string($name)) { } elseif (\is_string($name)) {
$this->name = new QACategoryL11n(); $this->name = new QACategoryL11n();
$this->name->setName($name); $this->name->name = $name;
$this->name->setLanguage($lang); $this->name->setLanguage($lang);
} }
} }
/**
* Get the parent category
*
* @return null|self
*
* @since 1.0.0
*/
public function getParent() : ?self
{
return $this->parent;
}
/**
* Set the parent category
*
* @param null|self $parent Parent category
*
* @return void
*
* @since 1.0.0
*/
public function setParent(?self $parent) : void
{
$this->parent = $parent;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -57,7 +57,7 @@ class QACategoryL11n implements \JsonSerializable, ArrayableInterface
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private string $name = ''; public string $name = '';
/** /**
* Constructor. * Constructor.
@ -148,20 +148,6 @@ class QACategoryL11n implements \JsonSerializable, ArrayableInterface
return $this->name; return $this->name;
} }
/**
* Set name
*
* @param string $name Name
*
* @return void
*
* @since 1.0.0
*/
public function setName(string $name) : void
{
$this->name = $name;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -42,7 +42,7 @@ class QAQuestion implements \JsonSerializable
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private string $name = ''; public string $name = '';
/** /**
* Question status. * Question status.
@ -58,7 +58,7 @@ class QAQuestion implements \JsonSerializable
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
private string $question = ''; public string $question = '';
/** /**
* Category. * Category.
@ -82,7 +82,7 @@ class QAQuestion implements \JsonSerializable
* @var Account * @var Account
* @since 1.0.0 * @since 1.0.0
*/ */
private Account $createdBy; public Account $createdBy;
/** /**
* Created at. * Created at.
@ -90,7 +90,7 @@ class QAQuestion implements \JsonSerializable
* @var \DateTimeImmutable * @var \DateTimeImmutable
* @since 1.0.0 * @since 1.0.0
*/ */
private \DateTimeImmutable $createdAt; public \DateTimeImmutable $createdAt;
/** /**
* Tags. * Tags.
@ -193,58 +193,6 @@ class QAQuestion implements \JsonSerializable
return false; return false;
} }
/**
* Get title.
*
* @return string
*
* @since 1.0.0
*/
public function getName() : string
{
return $this->name;
}
/**
* Set name.
*
* @param string $name Name
*
* @return void
*
* @since 1.0.0
*/
public function setName(string $name) : void
{
$this->name = $name;
}
/**
* Get the question.
*
* @return string
*
* @since 1.0.0
*/
public function getQuestion() : string
{
return $this->question;
}
/**
* Set the question
*
* @param string $question Question
*
* @return void
*
* @since 1.0.0
*/
public function setQuestion(string $question) : void
{
$this->question = $question;
}
/** /**
* Get the status * Get the status
* *
@ -297,44 +245,6 @@ class QAQuestion implements \JsonSerializable
$this->category = $category; $this->category = $category;
} }
/**
* Get created by
*
* @return Account
*
* @since 1.0.0
*/
public function getCreatedBy() : Account
{
return $this->createdBy;
}
/**
* Set created by
*
* @param Account $account Created by
*
* @return void
*
* @since 1.0.0
*/
public function setCreatedBy(Account $account) : void
{
$this->createdBy = $account;
}
/**
* Get created at date time
*
* @return \DateTimeImmutable
*
* @since 1.0.0
*/
public function getCreatedAt() : \DateTimeImmutable
{
return $this->createdAt;
}
/** /**
* Get tags * Get tags
* *

View File

@ -25,7 +25,7 @@ echo $this->getData('nav')->render(); ?>
<span class="score<?= $this->printHtml($question->hasAccepted() ? ' done' : ''); ?>"><?= $this->printHtml(\count($question->getAnswers())); ?></span> <span class="score<?= $this->printHtml($question->hasAccepted() ? ' done' : ''); ?>"><?= $this->printHtml(\count($question->getAnswers())); ?></span>
</div> </div>
<div class="title col-xs-11"> <div class="title col-xs-11">
<a href="<?= \phpOMS\Uri\UriFactory::build('{/prefix}qa/question?{?}&id=' . $question->getId()); ?>"><?= $this->printHtml($question->getName()); ?></a> <a href="<?= \phpOMS\Uri\UriFactory::build('{/prefix}qa/question?{?}&id=' . $question->getId()); ?>"><?= $this->printHtml($question->name); ?></a>
</div> </div>
</div> </div>
<div class="tags"> <div class="tags">

View File

@ -29,12 +29,12 @@ echo $this->getData('nav')->render();
<div class="row"> <div class="row">
<div class="col-xs-12"> <div class="col-xs-12">
<section class="box wf-100"> <section class="box wf-100">
<header><h1><?= $this->printHtml($question->getName()); ?></h1></header> <header><h1><?= $this->printHtml($question->name); ?></h1></header>
<div class="inner"> <div class="inner">
<?= $this->printHtml($question->getQuestion()); ?> <?= $this->printHtml($question->question); ?>
</div> </div>
<div class="inner"> <div class="inner">
<img alt="<?= $this->getHtml('AccountImage', '0', '0'); ?>" loading="lazy" src="<?= UriFactory::build('{/prefix}' . $question->getCreatedBy()->getImage()->getPath()); ?>"> <img alt="<?= $this->getHtml('AccountImage', '0', '0'); ?>" loading="lazy" src="<?= UriFactory::build('{/prefix}' . $question->createdBy->image->getPath()); ?>">
</div> </div>
</section> </section>
</div> </div>
@ -45,7 +45,7 @@ echo $this->getData('nav')->render();
<div class="col-xs-12"> <div class="col-xs-12">
<section class="box wf-100"> <section class="box wf-100">
<div class="inner"> <div class="inner">
<?= $this->printHtml($answer->getAnswer()); ?><?= $this->printHtml($answer->getCreatedAt()->format('Y-m-d')); ?><?= $this->printHtml($answer->getCreatedBy()->getId()); ?><?= $this->printHtml($answer->getStatus()); ?><?= $this->printHtml($answer->isAccepted()); ?> <?= $this->printHtml($answer->getAnswer()); ?><?= $this->printHtml($answer->getCreatedAt()->format('Y-m-d')); ?><?= $this->printHtml($answer->createdBy->getId()); ?><?= $this->printHtml($answer->getStatus()); ?><?= $this->printHtml($answer->isAccepted()); ?>
</div> </div>
</section> </section>
</div> </div>

View File

@ -40,7 +40,7 @@ echo $this->getData('nav')->render();
$url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/account/settings?{?}&id=' . $value->getId()); ?> $url = \phpOMS\Uri\UriFactory::build('{/prefix}admin/account/settings?{?}&id=' . $value->getId()); ?>
<tr tabindex="0" data-href="<?= $url; ?>"> <tr tabindex="0" data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getId()); ?></a> <td><a href="<?= $url; ?>"><?= $this->printHtml($value->getId()); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->getName()); ?></a> <td><a href="<?= $url; ?>"><?= $this->printHtml($value->name); ?></a>
<?php endforeach; ?> <?php endforeach; ?>
<?php if ($c === 0) : ?> <?php if ($c === 0) : ?>
<tr><td colspan="2" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?> <tr><td colspan="2" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>

View File

@ -51,7 +51,7 @@ class QACategoryMapperTest extends \PHPUnit\Framework\TestCase
$category = new QACategory(); $category = new QACategory();
$category->setName('Test Category2'); $category->setName('Test Category2');
$category->setParent(new NullQACategory(1)); $category->parent = new NullQACategory(1);
$id = QACategoryMapper::create($category); $id = QACategoryMapper::create($category);
self::assertGreaterThan(0, $category->getId()); self::assertGreaterThan(0, $category->getId());
@ -59,7 +59,7 @@ class QACategoryMapperTest extends \PHPUnit\Framework\TestCase
$categoryR = QACategoryMapper::get($category->getId()); $categoryR = QACategoryMapper::get($category->getId());
self::assertEquals($category->getName(), $categoryR->getName()); self::assertEquals($category->getName(), $categoryR->getName());
self::assertEquals($category->getParent()->getId(), $categoryR->getParent()->getId()); self::assertEquals($category->parent->getId(), $categoryR->parent->getId());
} }
/** /**

View File

@ -34,11 +34,11 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase
{ {
$question = new QAQuestion(); $question = new QAQuestion();
$question->setName('Question Name'); $question->name = 'Question Name';
$question->setQuestion('Question content'); $question->question = 'Question content';
$question->setStatus(QAQuestionStatus::ACTIVE); $question->setStatus(QAQuestionStatus::ACTIVE);
$question->setCategory(new NullQACategory(1)); $question->setCategory(new NullQACategory(1));
$question->setCreatedBy(new NullAccount(1)); $question->createdBy = new NullAccount(1);
$question->setLanguage('en'); $question->setLanguage('en');
$id = QAQuestionMapper::create($question); $id = QAQuestionMapper::create($question);
@ -46,12 +46,12 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase
self::assertEquals($id, $question->getId()); self::assertEquals($id, $question->getId());
$questionR = QAQuestionMapper::get($question->getId()); $questionR = QAQuestionMapper::get($question->getId());
self::assertEquals($question->getName(), $questionR->getName()); self::assertEquals($question->name, $questionR->name);
self::assertEquals($question->getQuestion(), $questionR->getQuestion()); self::assertEquals($question->question, $questionR->question);
self::assertEquals($question->getStatus(), $questionR->getStatus()); self::assertEquals($question->getStatus(), $questionR->getStatus());
self::assertEquals($question->getLanguage(), $questionR->getLanguage()); self::assertEquals($question->getLanguage(), $questionR->getLanguage());
self::assertEquals($question->getCategory()->getId(), $questionR->getCategory()->getId()); self::assertEquals($question->getCategory()->getId(), $questionR->getCategory()->getId());
self::assertEquals($question->getCreatedBy()->getId(), $questionR->getCreatedBy()->getId()); self::assertEquals($question->createdBy->getId(), $questionR->createdBy->getId());
} }
/** /**
@ -65,11 +65,11 @@ class QAQuestionMapperTest extends \PHPUnit\Framework\TestCase
$text = new Text(); $text = new Text();
$question = new QAQuestion(); $question = new QAQuestion();
$question->setName($text->generateText(\mt_rand(1, 3))); $question->name = $text->generateText(\mt_rand(1, 3));
$question->setQuestion($text->generateText(\mt_rand(100, 500))); $question->question = $text->generateText(\mt_rand(100, 500));
$question->setStatus(QAQuestionStatus::ACTIVE); $question->setStatus(QAQuestionStatus::ACTIVE);
$question->setCategory(new NullQACategory(\mt_rand(1, 9))); $question->setCategory(new NullQACategory(\mt_rand(1, 9)));
$question->setCreatedBy(new NullAccount(1)); $question->createdBy = new NullAccount(1);
$question->setLanguage('en'); $question->setLanguage('en');
$id = QAQuestionMapper::create($question); $id = QAQuestionMapper::create($question);

View File

@ -36,7 +36,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase
$answer->setAnswer('Answer content'); $answer->setAnswer('Answer content');
$answer->setStatus(QAAnswerStatus::ACTIVE); $answer->setStatus(QAAnswerStatus::ACTIVE);
$answer->setCreatedBy(new NullAccount(1)); $answer->createdBy = new NullAccount(1);
$answer->setQuestion(new NullQAQuestion(1)); $answer->setQuestion(new NullQAQuestion(1));
$answer->setAccepted(true); $answer->setAccepted(true);
@ -49,7 +49,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase
self::assertEquals($answer->getQuestion()->getId(), $answerR->getQuestion()->getId()); self::assertEquals($answer->getQuestion()->getId(), $answerR->getQuestion()->getId());
self::assertEquals($answer->getStatus(), $answerR->getStatus()); self::assertEquals($answer->getStatus(), $answerR->getStatus());
self::assertEquals($answer->isAccepted(), $answerR->isAccepted()); self::assertEquals($answer->isAccepted(), $answerR->isAccepted());
self::assertEquals($answer->getCreatedBy()->getId(), $answerR->getCreatedBy()->getId()); self::assertEquals($answer->createdBy->getId(), $answerR->createdBy->getId());
} }
/** /**
@ -64,7 +64,7 @@ class QAAnswerMapperTest extends \PHPUnit\Framework\TestCase
$answer = new QAAnswer(); $answer = new QAAnswer();
$answer->setAnswer($text->generateText(\mt_rand(100, 500))); $answer->setAnswer($text->generateText(\mt_rand(100, 500)));
$answer->setCreatedBy(new NullAccount(1)); $answer->createdBy = new NullAccount(1);
$answer->setStatus(QAAnswerStatus::ACTIVE); $answer->setStatus(QAAnswerStatus::ACTIVE);
$answer->setQuestion(new NullQAQuestion(1)); $answer->setQuestion(new NullQAQuestion(1));

View File

@ -37,8 +37,8 @@ class QAAnswerTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $answer->getQuestion()->getId()); self::assertEquals(0, $answer->getQuestion()->getId());
self::assertFalse($answer->isAccepted()); self::assertFalse($answer->isAccepted());
self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus()); self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus());
self::assertEquals(0, $answer->getCreatedBy()->getId()); self::assertEquals(0, $answer->createdBy->getId());
self::assertInstanceOf('\DateTimeImmutable', $answer->getCreatedAt()); self::assertInstanceOf('\DateTimeImmutable', $answer->createdAt);
} }
/** /**
@ -52,12 +52,12 @@ class QAAnswerTest extends \PHPUnit\Framework\TestCase
$answer->setAnswer('Answer content'); $answer->setAnswer('Answer content');
$answer->setStatus(QAAnswerStatus::ACTIVE); $answer->setStatus(QAAnswerStatus::ACTIVE);
$answer->setQuestion(new NullQAQuestion(3)); $answer->setQuestion(new NullQAQuestion(3));
$answer->setCreatedBy(new NullAccount(1)); $answer->createdBy = new NullAccount(1);
$answer->setAccepted(true); $answer->setAccepted(true);
self::assertEquals('Answer content', $answer->getAnswer()); self::assertEquals('Answer content', $answer->getAnswer());
self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus()); self::assertEquals(QAAnswerStatus::ACTIVE, $answer->getStatus());
self::assertEquals(1, $answer->getCreatedBy()->getId()); self::assertEquals(1, $answer->createdBy->getId());
self::assertEquals(3, $answer->getQuestion()->getId()); self::assertEquals(3, $answer->getQuestion()->getId());
self::assertTrue($answer->isAccepted()); self::assertTrue($answer->isAccepted());
} }

View File

@ -32,7 +32,7 @@ class QACategoryTest extends \PHPUnit\Framework\TestCase
self::assertEquals(0, $category->getId()); self::assertEquals(0, $category->getId());
self::assertEquals('', $category->getName()); self::assertEquals('', $category->getName());
self::assertNull($category->getParent()); self::assertEquals(0, $category->parent->getId());
} }
/** /**
@ -44,9 +44,9 @@ class QACategoryTest extends \PHPUnit\Framework\TestCase
$category = new QACategory(); $category = new QACategory();
$category->setName('Category Name'); $category->setName('Category Name');
$category->setParent(new NullQACategory(1)); $category->parent = new NullQACategory(1);
self::assertEquals('Category Name', $category->getName()); self::assertEquals('Category Name', $category->getName());
self::assertEquals(1, $category->getParent()->getId()); self::assertEquals(1, $category->parent->getId());
} }
} }

View File

@ -33,14 +33,14 @@ class QAQuestionTest extends \PHPUnit\Framework\TestCase
$question = new QAQuestion(); $question = new QAQuestion();
self::assertEquals(0, $question->getId()); self::assertEquals(0, $question->getId());
self::assertEquals('', $question->getName()); self::assertEquals('', $question->name);
self::assertEquals('', $question->getQuestion()); self::assertEquals('', $question->question);
self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus()); self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus());
self::assertEquals(0, $question->getCategory()->getId()); self::assertEquals(0, $question->getCategory()->getId());
self::assertEquals('', $question->getLanguage()); self::assertEquals('', $question->getLanguage());
self::assertEquals(0, $question->getCreatedBy()->getId()); self::assertEquals(0, $question->createdBy->getId());
self::assertInstanceOf('\DateTimeImmutable', $question->getCreatedAt()); self::assertInstanceOf('\DateTimeImmutable', $question->createdAt);
self::assertEquals([], $question->getBadges()); self::assertEquals([], $question->getTags());
} }
/** /**
@ -51,18 +51,18 @@ class QAQuestionTest extends \PHPUnit\Framework\TestCase
{ {
$question = new QAQuestion(); $question = new QAQuestion();
$question->setName('Question Name'); $question->name = 'Question Name';
$question->setQuestion('Question content'); $question->question = 'Question content';
$question->setStatus(QAQuestionStatus::ACTIVE); $question->setStatus(QAQuestionStatus::ACTIVE);
$question->setCategory(new NullQACategory(1)); $question->setCategory(new NullQACategory(1));
$question->setCreatedBy(new NullAccount(1)); $question->createdBy = new NullAccount(1);
$question->setLanguage('en'); $question->setLanguage('en');
self::assertEquals('Question Name', $question->getName()); self::assertEquals('Question Name', $question->name);
self::assertEquals('Question content', $question->getQuestion()); self::assertEquals('Question content', $question->question);
self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus()); self::assertEquals(QAQuestionStatus::ACTIVE, $question->getStatus());
self::assertEquals('en', $question->getLanguage()); self::assertEquals('en', $question->getLanguage());
self::assertEquals(1, $question->getCategory()->getId()); self::assertEquals(1, $question->getCategory()->getId());
self::assertEquals(1, $question->getCreatedBy()->getId()); self::assertEquals(1, $question->createdBy->getId());
} }
} }