Skip to content

Commit 75676fd

Browse files
committed
Beautify tests
1 parent d12f5ec commit 75676fd

File tree

4 files changed

+67
-53
lines changed

4 files changed

+67
-53
lines changed

tests/MigratorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
use Arxy\FilesBundle\NamingStrategy;
99
use Arxy\FilesBundle\Storage\FlysystemStorage;
1010
use League\Flysystem\FilesystemOperator;
11+
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\TestCase;
1213

1314
class MigratorTest extends TestCase
1415
{
16+
/** @var FilesystemOperator & MockObject */
1517
private FilesystemOperator $filesystem;
1618
private NamingStrategy $oldNamingStrategy;
1719
private NamingStrategy $newNamingStrategy;

tests/PathResolverManagerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use SplFileObject;
1313
use SplTempFileObject;
1414

15+
use function fopen;
16+
1517
class PathResolverManagerTest extends TestCase
1618
{
1719
/** @var ManagerInterface & MockObject */
@@ -59,10 +61,12 @@ public function testRead(): void
5961
public function testReadStream(): void
6062
{
6163
$file = new File('filename', 125, '098f6bcd4621d373cade4e832627b4f6', 'image/jpeg');
62-
$this->decorated->expects(self::once())->method('readStream')->with($file)->willReturn('!!!');
64+
65+
$stream = fopen('php://memory', 'r');
66+
$this->decorated->expects(self::once())->method('readStream')->with($file)->willReturn($stream);
6367

6468
$actual = $this->decorator->readStream($file);
65-
self::assertSame('!!!', $actual);
69+
self::assertSame($stream, $actual);
6670
}
6771

6872
public function testMove(): void

tests/Preview/DimensionTest.php

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,74 @@
1111

1212
class DimensionTest extends TestCase
1313
{
14-
public function constructorDataProvider()
14+
public function constructorDataProvider(): iterable
1515
{
16-
return [
17-
[1, 1],
18-
[5, 5],
19-
[
20-
0,
21-
1,
22-
InvalidArgumentException::class,
23-
'Length of either side cannot be 0 or negative, current size is 0x1',
24-
],
25-
[
26-
1,
27-
0,
28-
InvalidArgumentException::class,
29-
'Length of either side cannot be 0 or negative, current size is 1x0',
30-
],
31-
[
32-
0,
33-
0,
34-
InvalidArgumentException::class,
35-
'Length of either side cannot be 0 or negative, current size is 0x0',
36-
],
37-
[
38-
-1,
39-
1,
40-
InvalidArgumentException::class,
41-
'Length of either side cannot be 0 or negative, current size is -1x1',
42-
],
43-
[
44-
1,
45-
-1,
46-
InvalidArgumentException::class,
47-
'Length of either side cannot be 0 or negative, current size is 1x-1',
48-
],
49-
[
50-
-1,
51-
-1,
52-
InvalidArgumentException::class,
53-
'Length of either side cannot be 0 or negative, current size is -1x-1',
54-
],
55-
[null, 1, TypeError::class],
56-
[1, null, TypeError::class],
57-
];
16+
yield [1, 1];
17+
yield [5, 5];
5818
}
5919

6020
/**
6121
* @dataProvider constructorDataProvider
6222
*/
63-
public function testConstructor(
23+
public function testConstructor(int $width, int $height): void
24+
{
25+
$this->expectNotToPerformAssertions();
26+
new Dimension($width, $height);
27+
}
28+
29+
public function constructorExceptionsDataProvider(): iterable
30+
{
31+
yield [
32+
0,
33+
1,
34+
InvalidArgumentException::class,
35+
'Length of either side cannot be 0 or negative, current size is 0x1',
36+
];
37+
yield [
38+
1,
39+
0,
40+
InvalidArgumentException::class,
41+
'Length of either side cannot be 0 or negative, current size is 1x0',
42+
];
43+
yield [
44+
0,
45+
0,
46+
InvalidArgumentException::class,
47+
'Length of either side cannot be 0 or negative, current size is 0x0',
48+
];
49+
yield [
50+
-1,
51+
1,
52+
InvalidArgumentException::class,
53+
'Length of either side cannot be 0 or negative, current size is -1x1',
54+
];
55+
yield [
56+
1,
57+
-1,
58+
InvalidArgumentException::class,
59+
'Length of either side cannot be 0 or negative, current size is 1x-1',
60+
];
61+
yield [
62+
-1,
63+
-1,
64+
InvalidArgumentException::class,
65+
'Length of either side cannot be 0 or negative, current size is -1x-1',
66+
];
67+
yield [null, 1, TypeError::class];
68+
yield [1, null, TypeError::class];
69+
}
70+
71+
/**
72+
* @dataProvider constructorExceptionsDataProvider
73+
*/
74+
public function testConstructorExceptions(
6475
?int $width,
6576
?int $height,
66-
?string $expectException = null,
77+
string $expectException,
6778
?string $expectExceptionMessage = null
6879
): void {
69-
if ($expectException !== null) {
70-
$this->expectException($expectException);
71-
$this->expectExceptionMessage($expectExceptionMessage);
72-
} else {
73-
$this->expectNotToPerformAssertions();
74-
}
80+
$this->expectException($expectException);
81+
$this->expectExceptionMessage($expectExceptionMessage);
7582

7683
new Dimension($width, $height);
7784
}

tests/Repository/ORMTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Arxy\FilesBundle\Repository\ORM;
88
use Doctrine\ORM\AbstractQuery;
99
use Doctrine\ORM\QueryBuilder;
10+
use PHPUnit\Framework\MockObject\MockObject;
1011
use PHPUnit\Framework\TestCase;
1112

1213
class ORMTest extends TestCase

0 commit comments

Comments
 (0)