Fixings & add tests
This commit is contained in:
parent
ed184bd592
commit
690369cc4b
4 changed files with 132 additions and 23 deletions
|
@ -68,7 +68,6 @@ class Introduction extends BaseDepository
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'uid' => $introduction->uid,
|
'uid' => $introduction->uid,
|
||||||
'fid' => $introduction->fid,
|
|
||||||
'contact-id' => $introduction->cid,
|
'contact-id' => $introduction->cid,
|
||||||
'suggest-cid' => $introduction->sid,
|
'suggest-cid' => $introduction->sid,
|
||||||
'knowyou' => $introduction->knowyou ? 1 : 0,
|
'knowyou' => $introduction->knowyou ? 1 : 0,
|
||||||
|
|
|
@ -26,7 +26,6 @@ use Friendica\BaseEntity;
|
||||||
/**
|
/**
|
||||||
* @property-read int $uid
|
* @property-read int $uid
|
||||||
* @property-read int $sid
|
* @property-read int $sid
|
||||||
* @property-read int|null $fid
|
|
||||||
* @property-read int|null $cid
|
* @property-read int|null $cid
|
||||||
* @property-read bool $knowyou
|
* @property-read bool $knowyou
|
||||||
* @property-read bool $duplex
|
* @property-read bool $duplex
|
||||||
|
@ -43,8 +42,6 @@ class Introduction extends BaseEntity
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $sid;
|
protected $sid;
|
||||||
/** @var int|null */
|
/** @var int|null */
|
||||||
protected $fid;
|
|
||||||
/** @var int|null */
|
|
||||||
protected $cid;
|
protected $cid;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $knowyou;
|
protected $knowyou;
|
||||||
|
@ -64,7 +61,6 @@ class Introduction extends BaseEntity
|
||||||
/**
|
/**
|
||||||
* @param int $uid
|
* @param int $uid
|
||||||
* @param int $sid
|
* @param int $sid
|
||||||
* @param int|null $fid
|
|
||||||
* @param int|null $cid
|
* @param int|null $cid
|
||||||
* @param bool $knowyou
|
* @param bool $knowyou
|
||||||
* @param bool $duplex
|
* @param bool $duplex
|
||||||
|
@ -74,16 +70,16 @@ class Introduction extends BaseEntity
|
||||||
* @param bool $ignore
|
* @param bool $ignore
|
||||||
* @param int|null $id
|
* @param int|null $id
|
||||||
*/
|
*/
|
||||||
public function __construct(int $uid, int $sid, ?int $fid, ?int $cid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
|
public function __construct(int $uid, int $sid, ?int $cid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
|
||||||
{
|
{
|
||||||
$this->uid = $uid;
|
$this->uid = $uid;
|
||||||
$this->sid = $sid;
|
$this->sid = $sid;
|
||||||
$this->fid = $fid;
|
|
||||||
$this->cid = $cid;
|
$this->cid = $cid;
|
||||||
$this->knowyou = $knowyou;
|
$this->knowyou = $knowyou;
|
||||||
$this->duplex = $duplex;
|
$this->duplex = $duplex;
|
||||||
$this->note = $note;
|
$this->note = $note;
|
||||||
$this->hash = $hash;
|
$this->hash = $hash;
|
||||||
|
$this->datetime = $datetime;
|
||||||
$this->ignore = $ignore;
|
$this->ignore = $ignore;
|
||||||
$this->id = $id;
|
$this->id = $id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
|
||||||
return new Entity\Introduction(
|
return new Entity\Introduction(
|
||||||
$row['uid'] ?? 0,
|
$row['uid'] ?? 0,
|
||||||
$row['suggest-cid'] ?? 0,
|
$row['suggest-cid'] ?? 0,
|
||||||
$row['fid'] ?? null,
|
|
||||||
$row['contact-id'] ?? null,
|
$row['contact-id'] ?? null,
|
||||||
!empty($row['knowyou']),
|
!empty($row['knowyou']),
|
||||||
!empty($row['duplex']),
|
!empty($row['duplex']),
|
||||||
|
@ -51,18 +50,16 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
|
||||||
|
|
||||||
public function createNew(
|
public function createNew(
|
||||||
int $uid,
|
int $uid,
|
||||||
int $cid,
|
int $sid,
|
||||||
string $note,
|
string $note,
|
||||||
int $fid = null,
|
int $cid = null,
|
||||||
int $sid = null,
|
|
||||||
bool $knowyou = false,
|
bool $knowyou = false,
|
||||||
bool $duplex = false
|
bool $duplex = false
|
||||||
): Entity\Introduction {
|
): Entity\Introduction {
|
||||||
return $this->createFromTableRow([
|
return $this->createFromTableRow([
|
||||||
'uid' => $uid,
|
'uid' => $uid,
|
||||||
'fid' => $fid,
|
|
||||||
'contact-id' => $cid,
|
|
||||||
'suggest-cid' => $sid,
|
'suggest-cid' => $sid,
|
||||||
|
'contact-id' => $cid,
|
||||||
'knowyou' => $knowyou,
|
'knowyou' => $knowyou,
|
||||||
'duplex' => $duplex,
|
'duplex' => $duplex,
|
||||||
'note' => $note,
|
'note' => $note,
|
||||||
|
@ -72,7 +69,7 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createDummy(int $id): Entity\Introduction
|
public function createDummy(?int $id): Entity\Introduction
|
||||||
{
|
{
|
||||||
return $this->createFromTableRow(['id' => $id]);
|
return $this->createFromTableRow(['id' => $id]);
|
||||||
}
|
}
|
||||||
|
|
117
tests/src/Contact/Introduction/Factory/IntroductionTest.php
Normal file
117
tests/src/Contact/Introduction/Factory/IntroductionTest.php
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Friendica\Test\src\Contact\Introduction\Factory;
|
||||||
|
|
||||||
|
use Friendica\Contact\Introduction\Factory\Introduction;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Log\NullLogger;
|
||||||
|
|
||||||
|
class IntroductionTest extends TestCase
|
||||||
|
{
|
||||||
|
public function dataRow()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'default' => [
|
||||||
|
'input' => [
|
||||||
|
'uid' => 42,
|
||||||
|
'suggest-cid' => 13,
|
||||||
|
'contact-id' => 24,
|
||||||
|
'knowyou' => 1,
|
||||||
|
'duplex' => 1,
|
||||||
|
'note' => 'a note',
|
||||||
|
'hash' => '12345',
|
||||||
|
'datetime' => '1970-01-01 00:00:00',
|
||||||
|
'ignore' => 0,
|
||||||
|
'id' => 56,
|
||||||
|
],
|
||||||
|
'assertion' => [
|
||||||
|
'uid' => 42,
|
||||||
|
'suggest-cid' => 13,
|
||||||
|
'contact-id' => 24,
|
||||||
|
'knowyou' => true,
|
||||||
|
'duplex' => true,
|
||||||
|
'note' => 'a note',
|
||||||
|
'hash' => '12345',
|
||||||
|
'datetime' => new \DateTime('1970-01-01 00:00:00', new \DateTimeZone('UTC')),
|
||||||
|
'ignore' => false,
|
||||||
|
'id' => 56,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'empty' => [
|
||||||
|
'input' => [
|
||||||
|
],
|
||||||
|
'assertion' => [
|
||||||
|
'uid' => 0,
|
||||||
|
'suggest-cid' => 0,
|
||||||
|
'contact-id' => null,
|
||||||
|
'knowyou' => false,
|
||||||
|
'duplex' => false,
|
||||||
|
'note' => '',
|
||||||
|
'ignore' => false,
|
||||||
|
'id' => null,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assertIntro(\Friendica\Contact\Introduction\Entity\Introduction $intro, array $assertion)
|
||||||
|
{
|
||||||
|
self::assertEquals($intro->id, $assertion['id'] ?? null);
|
||||||
|
self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
|
||||||
|
self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? 0);
|
||||||
|
self::assertEquals($intro->cid, $assertion['contact-id'] ?? null);
|
||||||
|
self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
|
||||||
|
self::assertEquals($intro->duplex, $assertion['duplex'] ?? false);
|
||||||
|
self::assertEquals($intro->note, $assertion['note'] ?? '');
|
||||||
|
if (isset($assertion['hash'])) {
|
||||||
|
self::assertEquals($intro->hash, $assertion['hash']);
|
||||||
|
} else {
|
||||||
|
self::assertIsString($intro->hash);
|
||||||
|
}
|
||||||
|
if (isset($assertion['datetime'])) {
|
||||||
|
self::assertEquals($intro->datetime, $assertion['datetime']);
|
||||||
|
} else {
|
||||||
|
self::assertInstanceOf(\DateTime::class, $intro->datetime);
|
||||||
|
}
|
||||||
|
self::assertEquals($intro->ignore, $assertion['ignore'] ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataRow
|
||||||
|
*/
|
||||||
|
public function testCreateFromTableRow(array $input, array $assertion)
|
||||||
|
{
|
||||||
|
$factory = new Introduction(new NullLogger());
|
||||||
|
|
||||||
|
$intro = $factory->createFromTableRow($input);
|
||||||
|
$this->assertIntro($intro, $assertion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataRow
|
||||||
|
*/
|
||||||
|
public function testCreateNew(array $input, array $assertion)
|
||||||
|
{
|
||||||
|
$factory = new Introduction(new NullLogger());
|
||||||
|
|
||||||
|
$intro = $factory->createNew($input['uid'] ?? 0, $input['sid'] ?? 0, $input['note'] ?? '');
|
||||||
|
|
||||||
|
$this->assertIntro($intro, [
|
||||||
|
'uid' => $input['uid'] ?? 0,
|
||||||
|
'sid' => $input['sid'] ?? 0,
|
||||||
|
'note' => $input['note'] ?? '',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider dataRow
|
||||||
|
*/
|
||||||
|
public function testCreateDummy(array $input, array $assertion)
|
||||||
|
{
|
||||||
|
$factory = new Introduction(new NullLogger());
|
||||||
|
|
||||||
|
$intro = $factory->createDummy($input['id'] ?? null);
|
||||||
|
|
||||||
|
$this->assertIntro($intro, ['id' => $input['id'] ?? null]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue