Skip to content

Commit cc12325

Browse files
chore: Test cleanup.
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
1 parent 01ae2ef commit cc12325

File tree

67 files changed

+1229
-1176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1229
-1176
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Jitesoft\Exceptions\Security;
4+
5+
use Jitesoft\Exceptions\JitesoftException;
6+
use Throwable;
7+
8+
/**
9+
* Class AuthorizationException
10+
*
11+
* General AuthorizationException.
12+
*/
13+
class AuthorizationException extends JitesoftException {
14+
15+
/**
16+
* AuthorizationException constructor.
17+
*
18+
* @param string $message
19+
* @param int $code
20+
* @param Throwable|null $previous
21+
*/
22+
public function __construct(string $message = 'Authorization failed.',
23+
int $code = 0,
24+
?Throwable $previous = null) {
25+
parent::__construct($message, $code, $previous);
26+
}
27+
28+
}

tests/ArraySubsetConstraint.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
use SebastianBergmann\Comparator\ComparisonFailure;
1313
use Traversable;
1414

15-
final class ArraySubsetConstraint extends Constraint
16-
{
17-
/** @var iterable|mixed[] */
18-
private $subset;
15+
final class ArraySubsetConstraint extends Constraint {
16+
private iterable $subset;
1917
private bool $strict;
2018

21-
public function __construct(iterable $subset, bool $strict = false)
22-
{
19+
public function __construct(iterable $subset, bool $strict = false) {
2320
$this->strict = $strict;
2421
$this->subset = $subset;
2522
}
@@ -31,6 +28,7 @@ public function evaluate($other, string $description = '', bool $returnResult =
3128
if ($this->strict) {
3229
$result = $other === $patched;
3330
} else {
31+
/** @noinspection TypeUnsafeComparisonInspection */
3432
$result = $other == $patched;
3533
}
3634
if ($returnResult) {
@@ -47,6 +45,8 @@ public function evaluate($other, string $description = '', bool $returnResult =
4745
var_export($other, true)
4846
);
4947
$this->fail($other, $description, $f);
48+
49+
return null;
5050
}
5151

5252
public function toString(): string {

tests/Assertions/AssertionExceptionTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,33 @@
1111

1212
class AssertionExceptionTest extends ExceptionTestCase {
1313

14-
protected static function getTestProperties() {
14+
protected static function getTestProperties(): array {
1515
return array_merge(parent::getTestProperties(), [ 'actual', 'expected' ]);
1616
}
1717

18-
protected function throwDefaultException() {
18+
protected function throwDefaultException(): void {
1919
throw new AssertionException();
2020
}
2121

22-
public function throwMessageException(string $message) {
22+
public function throwMessageException(string $message): void {
2323
throw new AssertionException($message, "string", "array");
2424
}
2525

26-
public function testGetActual() {
26+
public function testGetActual(): void {
2727
try {
2828
$this->throwMessageException("Hi!");
2929
} catch (AssertionException $ex) {
30-
$this->assertEquals('string', $ex->getActual());
31-
$this->assertEquals('string', $ex->actual);
30+
self::assertEquals('string', $ex->getActual());
31+
self::assertEquals('string', $ex->actual);
3232
}
3333
}
3434

35-
public function testGetExpected() {
35+
public function testGetExpected(): void {
3636
try {
3737
$this->throwMessageException("Hi!");
3838
} catch (AssertionException $ex) {
39-
$this->assertEquals('array', $ex->getExpected());
40-
$this->assertEquals('array', $ex->expected);
39+
self::assertEquals('array', $ex->getExpected());
40+
self::assertEquals('array', $ex->expected);
4141
}
4242
}
4343

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
<?php
2-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3-
DatabaseExceptionTest.php - Part of the php-exceptions project.
4-
5-
© - Jitesoft 2017
6-
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7-
namespace Jitesoft\Exceptions\Tests\Database;
8-
9-
use Jitesoft\Exceptions\Database\DatabaseException;
10-
use Jitesoft\Exceptions\Tests\ExceptionTestCase;
11-
12-
/**
13-
* @group Exceptions
14-
* @group DatabaseExceptions
15-
* @group RuntimeExceptions
16-
*/
17-
class DatabaseExceptionTest extends ExceptionTestCase {
18-
19-
protected function throwDefaultException() {
20-
throw new DatabaseException();
21-
}
22-
23-
public function throwMessageException(string $message) {
24-
throw new DatabaseException($message);
25-
}
26-
}
1+
<?php
2+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3+
DatabaseExceptionTest.php - Part of the php-exceptions project.
4+
5+
© - Jitesoft 2017
6+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7+
namespace Jitesoft\Exceptions\Tests\Database;
8+
9+
use Jitesoft\Exceptions\Database\DatabaseException;
10+
use Jitesoft\Exceptions\Tests\ExceptionTestCase;
11+
12+
/**
13+
* @group Exceptions
14+
* @group DatabaseExceptions
15+
* @group RuntimeExceptions
16+
*/
17+
class DatabaseExceptionTest extends ExceptionTestCase {
18+
19+
protected function throwDefaultException(): void {
20+
throw new DatabaseException();
21+
}
22+
23+
public function throwMessageException(string $message): void {
24+
throw new DatabaseException($message);
25+
}
26+
}

tests/Database/Entity/DuplicateEntityExceptionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
class DuplicateEntityExceptionTest extends EntityExceptionTest {
1212

13-
protected function throwDefaultException() {
13+
protected function throwDefaultException(): void {
1414
throw new DuplicateEntityException();
1515
}
1616

17-
public function throwMessageException(string $message) {
17+
public function throwMessageException(string $message): void {
1818
throw new DuplicateEntityException($message, "TestEntity", 123);
1919
}
2020

tests/Database/Entity/EntityExceptionTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616
*/
1717
class EntityExceptionTest extends ExceptionTestCase {
1818

19-
protected static function getTestProperties() {
19+
protected static function getTestProperties(): array {
2020
return array_merge(parent::getTestProperties(), ['entity_id', 'entity_name']);
2121
}
2222

23-
protected function throwDefaultException() {
23+
protected function throwDefaultException(): void {
2424
throw new EntityException();
2525
}
2626

27-
public function throwMessageException(string $message) {
27+
public function throwMessageException(string $message): void {
2828
throw new EntityException($message, "TestEntity", 123);
2929
}
3030

31-
public function testGetEntityId() {
31+
public function testGetEntityId(): void {
3232
try {
3333
$this->throwMessageException('test');
3434
} catch (EntityException $ex) {
35-
$this->assertEquals(123, $ex->getEntityId());
36-
$this->assertEquals(123, $ex->entityId);
35+
self::assertEquals(123, $ex->getEntityId());
36+
self::assertEquals(123, $ex->entityId);
3737
}
3838
}
3939

40-
public function testGetEntityName() {
40+
public function testGetEntityName(): void {
4141
try {
4242
$this->throwMessageException('test');
4343
} catch (EntityException $ex) {
44-
$this->assertEquals("TestEntity", $ex->getEntityName());
45-
$this->assertEquals("TestEntity", $ex->entityName);
44+
self::assertEquals("TestEntity", $ex->getEntityName());
45+
self::assertEquals("TestEntity", $ex->entityName);
4646
}
4747
}
4848

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
<?php
2-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3-
UniqueConstraintExceptionTest.php - Part of the php-exceptions project.
4-
5-
© - Jitesoft 2018
6-
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7-
namespace Jitesoft\Exceptions\Tests\Database\Entity;
8-
9-
use Jitesoft\Exceptions\Database\Entity\UniqueConstraintException;
10-
11-
class UniqueConstraintExceptionTest extends EntityExceptionTest {
12-
13-
public function throwDefaultException() {
14-
throw new UniqueConstraintException();
15-
}
16-
17-
public function throwMessageException(string $message) {
18-
throw new UniqueConstraintException($message, 'TestEntity', 123);
19-
}
20-
21-
}
1+
<?php
2+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3+
UniqueConstraintExceptionTest.php - Part of the php-exceptions project.
4+
5+
© - Jitesoft 2018
6+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7+
namespace Jitesoft\Exceptions\Tests\Database\Entity;
8+
9+
use Jitesoft\Exceptions\Database\Entity\UniqueConstraintException;
10+
11+
class UniqueConstraintExceptionTest extends EntityExceptionTest {
12+
13+
public function throwDefaultException(): void {
14+
throw new UniqueConstraintException();
15+
}
16+
17+
public function throwMessageException(string $message): void {
18+
throw new UniqueConstraintException($message, 'TestEntity', 123);
19+
}
20+
21+
}

tests/ExceptionTestCase.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
*/
1818
abstract class ExceptionTestCase extends TestCase {
1919

20-
public final function testGetDefaultMessage() {
20+
final public function testGetDefaultMessage(): void {
2121
try {
2222
$this->throwDefaultException();
2323
} catch (JitesoftException $ex) {
2424

2525
$message = array_filter(
2626
(new ReflectionClass(get_class($ex)))->getConstructor()->getParameters(),
27-
function(ReflectionParameter $parm) {
27+
static function(ReflectionParameter $parm) {
2828
return $parm->getName() === "message";
2929
}
3030
);
@@ -41,7 +41,7 @@ function(ReflectionParameter $parm) {
4141
}
4242
}
4343

44-
public final function testGetNoneDefaultMessage() {
44+
final public function testGetNoneDefaultMessage(): void {
4545
try {
4646
$this->throwMessageException("Test");
4747
} catch (JitesoftException $ex) {
@@ -52,14 +52,14 @@ public final function testGetNoneDefaultMessage() {
5252
/**
5353
* @throws JitesoftException
5454
*/
55-
protected abstract function throwDefaultException();
55+
abstract protected function throwDefaultException(): void;
5656

5757
/**
5858
* @throws JitesoftException
5959
*/
60-
protected abstract function throwMessageException(string $message);
60+
abstract protected function throwMessageException(string $message): void;
6161

62-
protected static function getTestProperties() {
62+
protected static function getTestProperties(): array {
6363
return [
6464
"type",
6565
"error",
@@ -71,7 +71,10 @@ protected static function getTestProperties() {
7171
];
7272
}
7373

74-
public final function testHasProperties() {
74+
/**
75+
* @return void
76+
*/
77+
final public function testHasProperties(): void {
7578
try {
7679
$this->throwDefaultException();
7780
} catch (JitesoftException $ex) {
@@ -82,8 +85,9 @@ public final function testHasProperties() {
8285
/**
8386
* @param array $ex
8487
* @param array $properties
88+
* @return void
8589
*/
86-
protected final function assertHasProperties(array $ex, array $properties) {
90+
final protected function assertHasProperties(array $ex, array $properties): void {
8791
foreach ($properties as $property) {
8892
$o = self::arrayHasKey($property);
8993
if (!$o->evaluate($ex, '', true)) {
Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
<?php
2-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3-
HttpBadRequestExceptionTest.php - Part of the php-exceptions project.
4-
5-
© - Jitesoft 2017
6-
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7-
namespace Jitesoft\Exceptions\Tests\Http\Client;
8-
9-
use Jitesoft\Exceptions\Http\Client\HttpBadRequestException;
10-
use Jitesoft\Exceptions\Tests\Http\HttpExceptionTest;
11-
12-
/**
13-
* @group Exceptions
14-
* @group HttpExceptions
15-
* @group RuntimeExceptions
16-
* @group HttpClientExceptions
17-
*/
18-
class HttpBadRequestExceptionTest extends HttpExceptionTest {
19-
20-
protected $expectedErrorCode = 400;
21-
22-
protected function throwDefaultException() {
23-
throw new HttpBadRequestException();
24-
}
25-
26-
public function throwMessageException(string $message) {
27-
throw new HttpBadRequestException($message);
28-
}
29-
30-
}
1+
<?php
2+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3+
HttpBadRequestExceptionTest.php - Part of the php-exceptions project.
4+
5+
© - Jitesoft 2017
6+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7+
namespace Jitesoft\Exceptions\Tests\Http\Client;
8+
9+
use Jitesoft\Exceptions\Http\Client\HttpBadRequestException;
10+
use Jitesoft\Exceptions\Tests\Http\HttpExceptionTest;
11+
12+
/**
13+
* @group Exceptions
14+
* @group HttpExceptions
15+
* @group RuntimeExceptions
16+
* @group HttpClientExceptions
17+
*/
18+
class HttpBadRequestExceptionTest extends HttpExceptionTest {
19+
20+
protected $expectedErrorCode = 400;
21+
22+
protected function throwDefaultException(): void {
23+
throw new HttpBadRequestException();
24+
}
25+
26+
public function throwMessageException(string $message): void {
27+
throw new HttpBadRequestException($message);
28+
}
29+
30+
}

0 commit comments

Comments
 (0)