Skip to content

Commit 489c415

Browse files
committed
ittle fixes for phpstan, psalm and for the composer.json file
1 parent cc89d81 commit 489c415

File tree

7 files changed

+42
-21
lines changed

7 files changed

+42
-21
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# 2.x branch
22
## 2.10 branch
33
### 2.10.2
4-
* added tests for PHP 8.1.
4+
* added tests for PHP 8.1;
5+
* little fixes for phpstan, psalm and for the composer.json file.
56

67
### 2.10.1
78
* stable version;

phpstan-baseline.neon

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ parameters:
1111
path: src/TestSuite/TestCase.php
1212

1313
-
14-
message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(\\)\\: mixed\\)\\|null, 'self\\:\\:delete' given\\.$#"
15-
count: 2
16-
path: src/Utility/BackupManager.php
14+
message: "#^Property DatabaseBackup\\\\Test\\\\TestCase\\\\BackupTraitTest\\:\\:\\$Trait has no type specified\\.$#"
15+
count: 1
16+
path: tests/TestCase/BackupTraitTest.php
1717

1818
-
1919
message: "#^Ternary operator condition is always true\\.$#"
@@ -25,3 +25,8 @@ parameters:
2525
count: 2
2626
path: tests/TestCase/Utility/BackupImportTest.php
2727

28+
-
29+
message: "#^Ternary operator condition is always true\\.$#"
30+
count: 2
31+
path: tests/TestCase/Utility/BackupManagerTest.php
32+

src/BackupTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static function getDriver(?ConnectionInterface $connection = null): Drive
7272
{
7373
$connection = $connection ?: self::getConnection();
7474
$name = self::getDriverName($connection);
75+
/** @var class-string<\DatabaseBackup\Driver\Driver> $Driver */
7576
$Driver = App::classname('DatabaseBackup.' . $name, 'Driver');
7677
Exceptionist::isTrue($Driver, __d('database_backup', 'The `{0}` driver does not exist', $name), InvalidArgumentException::class);
7778

src/TestSuite/DriverTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ abstract class DriverTestCase extends TestCase
5555
protected $connection;
5656

5757
/**
58-
* @var array
58+
* @var array<string>
5959
*/
6060
public $fixtures = [
6161
'core.Articles',

src/Utility/BackupManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static function delete(string $filename): string
5959
*/
6060
public static function deleteAll(): array
6161
{
62-
return array_map('self::delete', self::index()->extract('filename')->toList());
62+
return array_map([__CLASS__, 'delete'], self::index()->extract('filename')->toList());
6363
}
6464

6565
/**
@@ -97,7 +97,7 @@ public static function rotate(int $rotate): array
9797
{
9898
Exceptionist::isPositive($rotate, __d('database_backup', 'Invalid rotate value'), InvalidArgumentException::class);
9999
$backupsToBeDeleted = self::index()->skip($rotate);
100-
array_map('self::delete', $backupsToBeDeleted->extract('filename')->toList());
100+
array_map([__CLASS__, 'delete'], $backupsToBeDeleted->extract('filename')->toList());
101101

102102
return $backupsToBeDeleted->toList();
103103
}

tests/TestCase/BackupTraitTest.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,40 @@
2929
*/
3030
class BackupTraitTest extends TestCase
3131
{
32-
use BackupTrait;
32+
/**
33+
* @psalm-var trait-string<\DatabaseBackup\BackupTrait>
34+
*/
35+
protected $Trait;
3336

3437
/**
3538
* Fixtures
36-
* @var array
39+
* @var array<string>
3740
*/
3841
public $fixtures = [
3942
'core.Articles',
4043
'core.Comments',
4144
];
4245

46+
/**
47+
* Called before every test method
48+
* @return void
49+
*/
50+
public function setUp(): void
51+
{
52+
parent::setUp();
53+
54+
$this->Trait = $this->Trait ?: $this->getMockForTrait(BackupTrait::class);
55+
}
56+
4357
/**
4458
* Test for `getAbsolutePath()` method
4559
* @test
4660
*/
4761
public function testGetAbsolutePath(): void
4862
{
4963
$expected = Configure::read('DatabaseBackup.target') . DS . 'file.txt';
50-
$this->assertEquals($expected, $this->getAbsolutePath('file.txt'));
51-
$this->assertEquals($expected, $this->getAbsolutePath(Configure::read('DatabaseBackup.target') . DS . 'file.txt'));
64+
$this->assertEquals($expected, $this->Trait->getAbsolutePath('file.txt'));
65+
$this->assertEquals($expected, $this->Trait->getAbsolutePath(Configure::read('DatabaseBackup.target') . DS . 'file.txt'));
5266
}
5367

5468
/**
@@ -65,7 +79,7 @@ public function testGetCompression(): void
6579
'backup.sql.gz' => 'gzip',
6680
'text.txt' => null,
6781
] as $filename => $expectedCompression) {
68-
$this->assertEquals($expectedCompression, $this->getCompression($filename));
82+
$this->assertEquals($expectedCompression, $this->Trait->getCompression($filename));
6983
}
7084
}
7185

@@ -76,13 +90,13 @@ public function testGetCompression(): void
7690
public function testGetConnection(): void
7791
{
7892
foreach ([null, Configure::read('DatabaseBackup.connection')] as $name) {
79-
$connection = $this->getConnection($name);
93+
$connection = $this->Trait->getConnection($name);
8094
$this->assertInstanceof(Connection::class, $connection);
8195
$this->assertEquals('test', $connection->config()['name']);
8296
}
8397

8498
ConnectionManager::setConfig('fake', ['url' => 'mysql://root:password@localhost/my_database']);
85-
$connection = $this->getConnection('fake');
99+
$connection = $this->Trait->getConnection('fake');
86100
$this->assertInstanceof(Connection::class, $connection);
87101
$this->assertEquals('fake', $connection->config()['name']);
88102

@@ -98,18 +112,18 @@ public function testGetConnection(): void
98112
public function testGetDriver(): void
99113
{
100114
foreach ([ConnectionManager::get('test'), null] as $driver) {
101-
$this->assertInstanceof(Driver::class, $this->getDriver($driver));
115+
$this->assertInstanceof(Driver::class, $this->Trait->getDriver($driver));
102116
}
103117

104118
//With a no existing driver
105119
$connection = $this->getMockBuilder(Connection::class)
106-
->setMethods(['__debuginfo', 'getDriver'])
120+
->onlyMethods(['__debuginfo', 'getDriver'])
107121
->disableOriginalConstructor()
108122
->getMock();
109123
$connection->method('getDriver')->will($this->returnValue(new Sqlserver()));
110124
$this->expectException(InvalidArgumentException::class);
111125
$this->expectExceptionMessage('The `Sqlserver` driver does not exist');
112-
$this->getDriver($connection);
126+
$this->Trait->getDriver($connection);
113127
}
114128

115129
/**
@@ -131,7 +145,7 @@ public function testGetExtension(): void
131145
'text' => null,
132146
'.txt' => null,
133147
] as $filename => $expectedExtension) {
134-
$this->assertEquals($expectedExtension, $this->getExtension($filename));
148+
$this->assertEquals($expectedExtension, $this->Trait->getExtension($filename));
135149
}
136150
}
137151

@@ -141,6 +155,6 @@ public function testGetExtension(): void
141155
*/
142156
public function testGetValidCompressions(): void
143157
{
144-
$this->assertNotEmpty($this->getValidCompressions());
158+
$this->assertNotEmpty($this->Trait->getValidCompressions());
145159
}
146160
}

tests/TestCase/Utility/BackupManagerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public function setUp(): void
5151
{
5252
parent::setUp();
5353

54-
$this->BackupExport = $this->BackupExport ?? new BackupExport();
55-
$this->BackupManager = $this->BackupManager ?? new BackupManager();
54+
$this->BackupExport = $this->BackupExport ?: new BackupExport();
55+
$this->BackupManager = $this->BackupManager ?: new BackupManager();
5656
}
5757

5858
/**

0 commit comments

Comments
 (0)