Skip to content

Commit b2d0fe0

Browse files
Merge pull request #84 from mirko-pagliai/develop
Develop
2 parents 08e069f + 469c94d commit b2d0fe0

File tree

12 files changed

+69
-45
lines changed

12 files changed

+69
-45
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
php-version: ['7.2', '7.3', '7.4', '8.0']
15+
php-version: ['7.2', '7.3', '7.4', '8.0', '8.1']
1616
db-type: [sqlite, mysql, pgsql]
1717
prefer-lowest: ['']
1818
exclude:
@@ -39,6 +39,9 @@ jobs:
3939
- php-version: '8.0'
4040
db-type: 'mysql'
4141
prefer-lowest: 'prefer-lowest'
42+
- php-version: '8.1'
43+
db-type: 'mysql'
44+
prefer-lowest: 'prefer-lowest'
4245

4346
steps:
4447
- name: Setup Database
@@ -49,7 +52,7 @@ jobs:
4952
docker run --rm --name=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=test -p 5432:5432 -d postgres:9.6
5053
fi
5154
52-
- uses: actions/checkout@v2
55+
- uses: actions/checkout@v3
5356

5457
- name: Validate composer.json and composer.lock
5558
run: composer validate --strict
@@ -95,21 +98,21 @@ jobs:
9598
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export db_dsn='postgres://postgres:postgres@127.0.0.1/test'; fi
9699
97100
if [[ ${{ matrix.php-version }} == '8.0' ]]; then
98-
export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
101+
export XDEBUG_MODE=coverage && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
99102
else
100103
vendor/bin/phpunit
101104
fi
102105
103106
- name: Submit code coverage
104107
if: matrix.php-version == '8.0'
105-
uses: codecov/codecov-action@v1
108+
uses: codecov/codecov-action@v2
106109

107110
cs-stan:
108111
name: Coding Standard & Static Analysis
109112
runs-on: ubuntu-latest
110113

111114
steps:
112-
- uses: actions/checkout@v2
115+
- uses: actions/checkout@v3
113116

114117
- name: Setup PHP
115118
uses: shivammathur/setup-php@v2
@@ -118,17 +121,11 @@ jobs:
118121
coverage: none
119122
tools: cs2pr
120123

121-
- name: Cache Composer packages
122-
id: composer-cache
123-
uses: actions/cache@v2
124-
with:
125-
path: vendor
126-
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
127-
restore-keys: |
128-
${{ runner.os }}-php-
129-
130124
- name: Composer install
131-
run: composer stan-setup
125+
run: composer update
126+
127+
- name: Composer show
128+
run: composer show
132129

133130
- name: Run PHP CodeSniffer
134131
continue-on-error: true
@@ -139,7 +136,7 @@ jobs:
139136

140137
- name: Run psalm
141138
if: success() || failure()
142-
run: vendor/bin/psalm.phar --output-format=github
139+
run: vendor/bin/psalm.phar --output-format=github --php-version=8.0
143140

144141
- name: Run phpstan
145142
if: success() || failure()
@@ -155,7 +152,7 @@ jobs:
155152
PHP_VERSION: '7.4'
156153

157154
steps:
158-
- uses: actions/checkout@v2
155+
- uses: actions/checkout@v3
159156

160157
- name: Setup PHP
161158
uses: shivammathur/setup-php@v2

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 2.x branch
22
## 2.10 branch
3+
### 2.10.2
4+
* added tests for PHP 8.1;
5+
* little fixes for phpstan, psalm and for the composer.json file.
6+
37
### 2.10.1
48
* stable version;
59
* updated for `php-tools` 1.5.8.

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
"require-dev": {
1919
"cakephp/cakephp-codesniffer": "^4.4",
2020
"mirko-pagliai/me-tools": "^2.19.8",
21-
"phpunit/phpunit": "^8.5.14|^9.0"
21+
"phpunit/phpunit": "^8.5.23|^9.1|^9.5",
22+
"phpstan/phpstan": "^1.7",
23+
"psalm/phar": "^4.24"
2224
},
2325
"autoload": {
2426
"psr-4": {
@@ -46,13 +48,16 @@
4648
"test": "rm -f -r /tmp/cake* && phpunit && driver_test=sqlite phpunit && driver_test=postgres phpunit",
4749
"coverage": "XDEBUG_MODE=coverage phpunit --coverage-html=coverage",
4850
"phpstan": "phpstan.phar analyse",
49-
"psalm": "psalm.phar",
51+
"psalm": "psalm.phar --php-version=8.0",
5052
"stan": [
51-
"@stan-setup",
5253
"@phpstan",
5354
"@psalm"
5455
],
55-
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^0.12 psalm/phar:\"^3.18|^4\" && mv composer.backup composer.json",
5656
"update-lowest": "@composer update --prefer-lowest"
57+
},
58+
"config": {
59+
"allow-plugins": {
60+
"dealerdirect/phpcodesniffer-composer-installer": true
61+
}
5762
}
5863
}

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+

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ parameters:
1616
checkMissingIterableValueType: false
1717
treatPhpDocTypesAsCertain: false
1818

19-
excludes_analyse:
19+
excludePaths:
2020
- tests/test_app/

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/TestSuite/TestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
use DatabaseBackup\Utility\BackupExport;
2020
use DatabaseBackup\Utility\BackupManager;
2121
use MeTools\TestSuite\TestCase as BaseTestCase;
22-
use Tools\TestSuite\BackwardCompatibilityTrait;
2322

2423
/**
2524
* TestCase class
2625
*/
2726
abstract class TestCase extends BaseTestCase
2827
{
29-
use BackwardCompatibilityTrait;
3028
use BackupTrait;
3129

3230
/**

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
}

0 commit comments

Comments
 (0)