Applied code style to tests/

This commit is contained in:
Jan Böhmer 2020-01-05 15:55:16 +01:00
parent f861de791f
commit fe0f69f762
44 changed files with 427 additions and 306 deletions

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -99,7 +102,7 @@ class AttachmentTest extends TestCase
//This must not throw an exception
$attachment->setElement($element);
$this->assertEquals($element, $attachment->getElement());
$this->assertSame($element, $attachment->getElement());
}
/**
@ -141,11 +144,11 @@ class AttachmentTest extends TestCase
/**
* @dataProvider externalDataProvider
*/
public function testIsExternal($path, $expected)
public function testIsExternal($path, $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->assertEquals($expected, $attachment->isExternal());
$this->assertSame($expected, $attachment->isExternal());
}
public function extensionDataProvider()
@ -167,12 +170,12 @@ class AttachmentTest extends TestCase
/**
* @dataProvider extensionDataProvider
*/
public function testGetExtension($path, $originalFilename, $expected)
public function testGetExtension($path, $originalFilename, $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->setProtectedProperty($attachment, 'original_filename', $originalFilename);
$this->assertEquals($expected, $attachment->getExtension());
$this->assertSame($expected, $attachment->getExtension());
}
public function pictureDataProvider()
@ -192,11 +195,11 @@ class AttachmentTest extends TestCase
/**
* @dataProvider pictureDataProvider
*/
public function testIsPicture($path, $expected)
public function testIsPicture($path, $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->assertEquals($expected, $attachment->isPicture());
$this->assertSame($expected, $attachment->isPicture());
}
public function builtinDataProvider()
@ -214,11 +217,11 @@ class AttachmentTest extends TestCase
/**
* @dataProvider builtinDataProvider
*/
public function testIsBuiltIn($path, $expected)
public function testIsBuiltIn($path, $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->assertEquals($expected, $attachment->isBuiltIn());
$this->assertSame($expected, $attachment->isBuiltIn());
}
public function hostDataProvider()
@ -233,11 +236,11 @@ class AttachmentTest extends TestCase
/**
* @dataProvider hostDataProvider
*/
public function testGetHost($path, $expected)
public function testGetHost($path, $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->assertEquals($expected, $attachment->getHost());
$this->assertSame($expected, $attachment->getHost());
}
public function filenameProvider()
@ -252,15 +255,15 @@ class AttachmentTest extends TestCase
/**
* @dataProvider filenameProvider
*/
public function testGetFilename($path, $original_filename, $expected)
public function testGetFilename($path, $original_filename, $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->setProtectedProperty($attachment, 'original_filename', $original_filename);
$this->assertEquals($expected, $attachment->getFilename());
$this->assertSame($expected, $attachment->getFilename());
}
public function testIsURL()
public function testIsURL(): void
{
$url = '%MEDIA%/test.txt';
$this->assertFalse(Attachment::isURL($url));
@ -279,10 +282,8 @@ class AttachmentTest extends TestCase
* @param object $object - instance in which protected value is being modified
* @param string $property - property on instance being modified
* @param mixed $value - new value of the property being modified
*
* @return void
*/
public function setProtectedProperty($object, $property, $value)
public function setProtectedProperty($object, $property, $value): void
{
$reflection = new ReflectionClass($object);
$reflection_property = $reflection->getProperty($property);

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -27,7 +30,7 @@ use PHPUnit\Framework\TestCase;
class AttachmentTypeTest extends TestCase
{
public function testEmptyState()
public function testEmptyState(): void
{
$attachment_type = new AttachmentType();
$this->assertInstanceOf(Collection::class, $attachment_type->getAttachmentsForType());

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -26,7 +29,7 @@ use PHPUnit\Framework\TestCase;
class PartLotTest extends TestCase
{
public function testIsExpired()
public function testIsExpired(): void
{
$lot = new PartLot();
$this->assertNull($lot->isExpired(), 'Lot must be return null when no Expiration date is set!');

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -29,7 +32,7 @@ use PHPUnit\Framework\TestCase;
class PartTest extends TestCase
{
public function testAddRemovePartLot()
public function testAddRemovePartLot(): void
{
$part = new Part();
$this->assertInstanceOf(Collection::class, $part->getPartLots());
@ -38,33 +41,33 @@ class PartTest extends TestCase
//Add element
$lot = new PartLot();
$part->addPartLot($lot);
$this->assertEquals($part, $lot->getPart());
$this->assertEquals(1, $part->getPartLots()->count());
$this->assertSame($part, $lot->getPart());
$this->assertSame(1, $part->getPartLots()->count());
//Remove element
$part->removePartLot($lot);
$this->assertTrue($part->getPartLots()->isEmpty());
}
public function testGetSetMinamount()
public function testGetSetMinamount(): void
{
$part = new Part();
$measurement_unit = new MeasurementUnit();
//Without an set measurement unit the part must return an int
$part->setMinAmount(1.345);
$this->assertEquals(1, $part->getMinAmount());
$this->assertSame(1.0, $part->getMinAmount());
//If an non int-based unit is assigned, an float is returned
$part->setPartUnit($measurement_unit);
$this->assertEquals(1.345, $part->getMinAmount());
$this->assertSame(1.345, $part->getMinAmount());
//If an int-based unit is assigned an int is returned
$measurement_unit->setIsInteger(true);
$this->assertEquals(1, $part->getMinAmount());
$this->assertSame(1.0, $part->getMinAmount());
}
public function testUseFloatAmount()
public function testUseFloatAmount(): void
{
$part = new Part();
$measurement_unit = new MeasurementUnit();
@ -79,13 +82,13 @@ class PartTest extends TestCase
$this->assertFalse($part->useFloatAmount());
}
public function testGetAmountSum()
public function testGetAmountSum(): void
{
$part = new Part();
$measurement_unit = new MeasurementUnit();
$datetime = new \DateTime();
$this->assertEquals(0, $part->getAmountSum());
$this->assertSame(0.0, $part->getAmountSum());
$part->addPartLot((new PartLot())->setAmount(3.141));
$part->addPartLot((new PartLot())->setAmount(10.0));
@ -96,15 +99,15 @@ class PartTest extends TestCase
->setExpirationDate($datetime->setTimestamp(strtotime('now -1 hour')))
);
$this->assertEquals(13, $part->getAmountSum());
$this->assertSame(13.0, $part->getAmountSum());
$part->setPartUnit($measurement_unit);
$this->assertEquals(13.141, $part->getAmountSum());
$this->assertSame(13.141, $part->getAmountSum());
//1 billion part lot
$part->addPartLot((new PartLot())->setAmount(1000000000));
$this->assertEquals(1000000013.141, $part->getAmountSum());
$this->assertSame(1000000013.141, $part->getAmountSum());
$measurement_unit->setIsInteger(true);
$this->assertEquals(1000000013, $part->getAmountSum());
$this->assertSame(1000000013.0, $part->getAmountSum());
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -26,7 +29,7 @@ use PHPUnit\Framework\TestCase;
class CurrencyTest extends TestCase
{
public function testGetInverseExchangeRate()
public function testGetInverseExchangeRate(): void
{
$currency = new Currency();
@ -37,6 +40,6 @@ class CurrencyTest extends TestCase
$this->assertNull($currency->getInverseExchangeRate());
$currency->setExchangeRate('1.45643');
$this->assertEquals('0.68661', $currency->getInverseExchangeRate());
$this->assertSame('0.68661', $currency->getInverseExchangeRate());
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -28,7 +31,7 @@ use PHPUnit\Framework\TestCase;
class OrderdetailTest extends TestCase
{
public function testAddRemovePricdetails()
public function testAddRemovePricdetails(): void
{
$orderdetail = new Orderdetail();
$this->assertInstanceOf(Collection::class, $orderdetail->getPricedetails());
@ -36,15 +39,15 @@ class OrderdetailTest extends TestCase
$pricedetail = new Pricedetail();
$orderdetail->addPricedetail($pricedetail);
$this->assertEquals($orderdetail, $pricedetail->getOrderdetail());
$this->assertEquals(1, $orderdetail->getPricedetails()->count());
$this->assertSame($orderdetail, $pricedetail->getOrderdetail());
$this->assertSame(1, $orderdetail->getPricedetails()->count());
//After removal of the pricedetail, the orderdetail must be empty again
$orderdetail->removePricedetail($pricedetail);
$this->assertTrue($orderdetail->getPricedetails()->isEmpty());
}
public function testFindPriceForQty()
public function testFindPriceForQty(): void
{
$price0 = (new Pricedetail())->setMinDiscountQuantity(0.23);
$price1 = (new Pricedetail())->setMinDiscountQuantity(1);
@ -54,10 +57,10 @@ class OrderdetailTest extends TestCase
$this->assertNull($orderdetail->findPriceForQty(0));
$this->assertNull($orderdetail->findPriceForQty(0.1));
$this->assertEquals($price0, $orderdetail->findPriceForQty(0.5));
$this->assertEquals($price1, $orderdetail->findPriceForQty(1));
$this->assertEquals($price1, $orderdetail->findPriceForQty(1.5));
$this->assertEquals($price5, $orderdetail->findPriceForQty(5.3));
$this->assertEquals($price5, $orderdetail->findPriceForQty(10000));
$this->assertSame($price0, $orderdetail->findPriceForQty(0.5));
$this->assertSame($price1, $orderdetail->findPriceForQty(1));
$this->assertSame($price1, $orderdetail->findPriceForQty(1.5));
$this->assertSame($price5, $orderdetail->findPriceForQty(5.3));
$this->assertSame($price5, $orderdetail->findPriceForQty(10000));
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -28,23 +31,23 @@ use PHPUnit\Framework\TestCase;
class PricedetailTest extends TestCase
{
public function testGetPricePerUnit()
public function testGetPricePerUnit(): void
{
$pricedetail = new Pricedetail();
$pricedetail->setPrice('100.234');
$this->assertEquals('100.23400', $pricedetail->getPricePerUnit());
$this->assertSame('100.23400', $pricedetail->getPricePerUnit());
$pricedetail->setPriceRelatedQuantity('2.3');
$this->assertEquals('43.58000', $pricedetail->getPricePerUnit());
$this->assertEquals('139.45600', $pricedetail->getPricePerUnit('3.2'));
$pricedetail->setPriceRelatedQuantity(2.3);
$this->assertSame('43.58000', $pricedetail->getPricePerUnit());
$this->assertSame('139.45600', $pricedetail->getPricePerUnit('3.2'));
$pricedetail->setPrice('10000000.2345'); //Ten million
$pricedetail->setPriceRelatedQuantity(1.234e9); //100 billion
$this->assertEquals('0.00810', $pricedetail->getPricePerUnit());
$this->assertSame('0.00810', $pricedetail->getPricePerUnit());
}
public function testGetPriceRelatedQuantity()
public function testGetPriceRelatedQuantity(): void
{
$pricedetail = new Pricedetail();
$part = $this->createMock(Part::class);
@ -58,21 +61,21 @@ class PricedetailTest extends TestCase
$orderdetail2->method('getPart')->willReturn($part2);
//By default a price detail returns 1
$this->assertEquals(1, $pricedetail->getPriceRelatedQuantity());
$this->assertSame(1.0, $pricedetail->getPriceRelatedQuantity());
$pricedetail->setOrderdetail($orderdetail);
$pricedetail->setPriceRelatedQuantity(10.23);
$this->assertEquals(10, $pricedetail->getPriceRelatedQuantity());
$this->assertSame(10.0, $pricedetail->getPriceRelatedQuantity());
//Price related quantity must not be zero!
$pricedetail->setPriceRelatedQuantity(0.23);
$this->assertEquals(1, $pricedetail->getPriceRelatedQuantity());
$this->assertSame(1.0, $pricedetail->getPriceRelatedQuantity());
//With an part that has an float amount unit, also values like 0.23 can be returned
$pricedetail->setOrderdetail($orderdetail2);
$this->assertEquals(0.23, $pricedetail->getPriceRelatedQuantity());
$this->assertSame(0.23, $pricedetail->getPriceRelatedQuantity());
}
public function testGetMinDiscountQuantity()
public function testGetMinDiscountQuantity(): void
{
$pricedetail = new Pricedetail();
$part = $this->createMock(Part::class);
@ -86,17 +89,17 @@ class PricedetailTest extends TestCase
$orderdetail2->method('getPart')->willReturn($part2);
//By default a price detail returns 1
$this->assertEquals(1, $pricedetail->getMinDiscountQuantity());
$this->assertSame(1.0, $pricedetail->getMinDiscountQuantity());
$pricedetail->setOrderdetail($orderdetail);
$pricedetail->setMinDiscountQuantity(10.23);
$this->assertEquals(10, $pricedetail->getMinDiscountQuantity());
$this->assertSame(10.0, $pricedetail->getMinDiscountQuantity());
//Price related quantity must not be zero!
$pricedetail->setMinDiscountQuantity(0.23);
$this->assertEquals(1, $pricedetail->getMinDiscountQuantity());
$this->assertSame(1.0, $pricedetail->getMinDiscountQuantity());
//With an part that has an float amount unit, also values like 0.23 can be returned
$pricedetail->setOrderdetail($orderdetail2);
$this->assertEquals(0.23, $pricedetail->getMinDiscountQuantity());
$this->assertSame(0.23, $pricedetail->getMinDiscountQuantity());
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -39,7 +42,7 @@ class StructuralDBElementTest extends TestCase
protected $child1_1;
protected $child1_2;
public function setUp(): void
protected function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
@ -58,14 +61,14 @@ class StructuralDBElementTest extends TestCase
$this->child1_2->setName('child1_2')->setParent($this->child1);
}
public function testIsRoot()
public function testIsRoot(): void
{
$this->assertTrue($this->root->isRoot());
$this->assertFalse($this->child1->isRoot());
$this->assertFalse($this->child1_2->isRoot());
}
public function testIsChildOf()
public function testIsChildOf(): void
{
//Root must not be the child of any other node
$this->assertFalse($this->root->isChildOf($this->child1));
@ -79,14 +82,14 @@ class StructuralDBElementTest extends TestCase
$this->assertTrue($this->child1_2->isChildOf($this->root));
}
public function testChildOfDifferentClasses()
public function testChildOfDifferentClasses(): void
{
$this->expectException(\InvalidArgumentException::class);
$category = new Category();
$this->root->isChildOf($category);
}
public function testChildOfExtendedClass()
public function testChildOfExtendedClass(): void
{
//Doctrine extends the entities for proxy classes so the isChildOf mus also work for inheritance types
$inheritance = new class() extends AttachmentType {
@ -96,25 +99,25 @@ class StructuralDBElementTest extends TestCase
$this->assertFalse($this->root->isChildOf($inheritance));
}
public function testGetLevel()
public function testGetLevel(): void
{
$this->assertEquals(0, $this->root->getLevel());
$this->assertEquals(1, $this->child1->getLevel());
$this->assertSame(0, $this->root->getLevel());
$this->assertSame(1, $this->child1->getLevel());
$this->assertSame(1, $this->child2->getLevel());
$this->assertSame(2, $this->child1_2->getLevel());
$this->assertSame(2, $this->child1_1->getLevel());
}
public function testGetFullPath()
public function testGetFullPath(): void
{
$this->assertSame('root/child1/child1_1', $this->child1_1->getFullPath('/'));
$this->assertSame('root#child2', $this->child2->getFullPath('#'));
}
public function testGetPathArray()
public function testGetPathArray(): void
{
$this->assertEquals([$this->root, $this->child1, $this->child1_1], $this->child1_1->getPathArray());
$this->assertEquals([$this->root, $this->child1], $this->child1->getPathArray());
$this->assertEquals([$this->root], $this->root->getPathArray());
$this->assertSame([$this->root, $this->child1, $this->child1_1], $this->child1_1->getPathArray());
$this->assertSame([$this->root, $this->child1], $this->child1->getPathArray());
$this->assertSame([$this->root], $this->root->getPathArray());
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -27,7 +30,7 @@ use PHPUnit\Framework\TestCase;
class PermissionsEmbedTest extends TestCase
{
public function testGetPermissionValue()
public function testGetPermissionValue(): void
{
$embed = new PermissionsEmbed();
//For newly created embedded, all things should be set to inherit => null
@ -71,7 +74,7 @@ class PermissionsEmbedTest extends TestCase
$this->assertNull($embed->getPermissionValue(PermissionsEmbed::PARTS, 6));
}
public function testGetBitValue()
public function testGetBitValue(): void
{
$embed = new PermissionsEmbed();
@ -83,14 +86,14 @@ class PermissionsEmbedTest extends TestCase
$property->setValue($embed, 0b11011000); // 11 01 10 00
//Test if function is working correctly
$this->assertEquals(PermissionsEmbed::INHERIT, $embed->getBitValue(PermissionsEmbed::PARTS, 0));
$this->assertEquals(PermissionsEmbed::DISALLOW, $embed->getBitValue(PermissionsEmbed::PARTS, 2));
$this->assertEquals(PermissionsEmbed::ALLOW, $embed->getBitValue(PermissionsEmbed::PARTS, 4));
$this->assertSame(PermissionsEmbed::INHERIT, $embed->getBitValue(PermissionsEmbed::PARTS, 0));
$this->assertSame(PermissionsEmbed::DISALLOW, $embed->getBitValue(PermissionsEmbed::PARTS, 2));
$this->assertSame(PermissionsEmbed::ALLOW, $embed->getBitValue(PermissionsEmbed::PARTS, 4));
// 11 is reserved, but it should be also treat as INHERIT.
$this->assertEquals(0b11, $embed->getBitValue(PermissionsEmbed::PARTS, 6));
$this->assertSame(0b11, $embed->getBitValue(PermissionsEmbed::PARTS, 6));
}
public function testInvalidPermissionName()
public function testInvalidPermissionName(): void
{
$embed = new PermissionsEmbed();
//When encoutering an unknown permission name the class must throw an exception
@ -98,7 +101,7 @@ class PermissionsEmbedTest extends TestCase
$embed->getPermissionValue('invalid', 0);
}
public function testInvalidBit1()
public function testInvalidBit1(): void
{
$embed = new PermissionsEmbed();
//When encoutering an negative bit the class must throw an exception
@ -106,7 +109,7 @@ class PermissionsEmbedTest extends TestCase
$embed->getPermissionValue('parts', -1);
}
public function testInvalidBit2()
public function testInvalidBit2(): void
{
$embed = new PermissionsEmbed();
//When encoutering an odd bit number it must throw an error.
@ -114,7 +117,7 @@ class PermissionsEmbedTest extends TestCase
$embed->getPermissionValue('parts', 1);
}
public function testInvalidBit3()
public function testInvalidBit3(): void
{
$embed = new PermissionsEmbed();
//When encoutering an too high bit number it must throw an error.
@ -145,33 +148,33 @@ class PermissionsEmbedTest extends TestCase
/**
* @dataProvider getStatesBINARY
*/
public function testsetBitValue($value)
public function testTestsetBitValue($value): void
{
$embed = new PermissionsEmbed();
//Check if it returns itself, for chaining.
$this->assertEquals($embed, $embed->setBitValue(PermissionsEmbed::PARTS, 0, $value));
$this->assertEquals($value, $embed->getBitValue(PermissionsEmbed::PARTS, 0));
$this->assertSame($embed, $embed->setBitValue(PermissionsEmbed::PARTS, 0, $value));
$this->assertSame($value, $embed->getBitValue(PermissionsEmbed::PARTS, 0));
}
/**
* @dataProvider getStatesBOOL
*/
public function testSetPermissionValue($value)
public function testSetPermissionValue($value): void
{
$embed = new PermissionsEmbed();
//Check if it returns itself, for chaining.
$this->assertEquals($embed, $embed->setPermissionValue(PermissionsEmbed::PARTS, 0, $value));
$this->assertEquals($value, $embed->getPermissionValue(PermissionsEmbed::PARTS, 0));
$this->assertSame($embed, $embed->setPermissionValue(PermissionsEmbed::PARTS, 0, $value));
$this->assertSame($value, $embed->getPermissionValue(PermissionsEmbed::PARTS, 0));
}
public function testSetRawPermissionValue()
public function testSetRawPermissionValue(): void
{
$embed = new PermissionsEmbed();
$embed->setRawPermissionValue(PermissionsEmbed::PARTS, 10);
$this->assertEquals(10, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
$this->assertSame(10, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
}
public function testSetRawPermissionValues()
public function testSetRawPermissionValues(): void
{
$embed = new PermissionsEmbed();
$embed->setRawPermissionValues([
@ -180,9 +183,9 @@ class PermissionsEmbedTest extends TestCase
PermissionsEmbed::CATEGORIES => 1304,
]);
$this->assertEquals(0, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
$this->assertEquals(100, $embed->getRawPermissionValue(PermissionsEmbed::USERS));
$this->assertEquals(1304, $embed->getRawPermissionValue(PermissionsEmbed::CATEGORIES));
$this->assertSame(0, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
$this->assertSame(100, $embed->getRawPermissionValue(PermissionsEmbed::USERS));
$this->assertSame(1304, $embed->getRawPermissionValue(PermissionsEmbed::CATEGORIES));
//Test second method to pass perm names and values
$embed->setRawPermissionValues(
@ -190,8 +193,8 @@ class PermissionsEmbedTest extends TestCase
[0, 100, 1304]
);
$this->assertEquals(0, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
$this->assertEquals(100, $embed->getRawPermissionValue(PermissionsEmbed::USERS));
$this->assertEquals(1304, $embed->getRawPermissionValue(PermissionsEmbed::CATEGORIES));
$this->assertSame(0, $embed->getRawPermissionValue(PermissionsEmbed::PARTS));
$this->assertSame(100, $embed->getRawPermissionValue(PermissionsEmbed::USERS));
$this->assertSame(1304, $embed->getRawPermissionValue(PermissionsEmbed::CATEGORIES));
}
}

View file

@ -1,4 +1,7 @@
<?php
declare(strict_types=1);
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
@ -27,15 +30,15 @@ use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
public function testGetFullName()
public function testGetFullName(): void
{
$user = new User();
$user->setName('username');
$user->setFirstName('John');
$user->setLastName('Doe');
$this->assertEquals('John Doe', $user->getFullName(false));
$this->assertEquals('John Doe (username)', $user->getFullName(true));
$this->assertSame('John Doe', $user->getFullName(false));
$this->assertSame('John Doe (username)', $user->getFullName(true));
}
public function googleAuthenticatorEnabledDataProvider(): array
@ -50,7 +53,7 @@ class UserTest extends TestCase
/**
* @dataProvider googleAuthenticatorEnabledDataProvider
*/
public function testIsGoogleAuthenticatorEnabled(?string $secret, bool $expected)
public function testIsGoogleAuthenticatorEnabled(?string $secret, bool $expected): void
{
$user = new User();
$user->setGoogleAuthenticatorSecret($secret);
@ -60,14 +63,14 @@ class UserTest extends TestCase
/**
* @requires PHPUnit 8
*/
public function testSetBackupCodes()
public function testSetBackupCodes(): void
{
$user = new User();
$codes = ['test', 'invalid', 'test'];
$user->setBackupCodes($codes);
// Backup Codes generation date must be changed!
$this->assertEqualsWithDelta(new \DateTime(), $user->getBackupCodesGenerationDate(), 0.1);
$this->assertEquals($codes, $user->getBackupCodes());
$this->assertSame($codes, $user->getBackupCodes());
//Test what happens if we delete the backup keys
$user->setBackupCodes([]);
@ -75,7 +78,7 @@ class UserTest extends TestCase
$this->assertNull($user->getBackupCodesGenerationDate());
}
public function testIsBackupCode()
public function testIsBackupCode(): void
{
$user = new User();
$codes = ['aaaa', 'bbbb', 'cccc', 'dddd'];
@ -88,7 +91,7 @@ class UserTest extends TestCase
$this->assertFalse($user->isBackupCode('zzzz'));
}
public function testInvalidateBackupCode()
public function testInvalidateBackupCode(): void
{
$user = new User();
$codes = ['aaaa', 'bbbb', 'cccc', 'dddd'];
@ -106,7 +109,7 @@ class UserTest extends TestCase
$user->invalidateBackupCode('zzzz');
}
public function testInvalidateTrustedDeviceTokens()
public function testInvalidateTrustedDeviceTokens(): void
{
$user = new User();
$old_value = $user->getTrustedTokenVersion();
@ -115,7 +118,7 @@ class UserTest extends TestCase
$this->assertGreaterThan($old_value, $user->getTrustedTokenVersion());
}
public function testIsU2fEnabled()
public function testIsU2fEnabled(): void
{
$user = new User();
$user->addU2FKey(new U2FKey());