Skip to content

Commit 280ee1e

Browse files
committed
Merge branch 'develop'
* develop: specify next release update actions version directly use output diff when path is a directory use blackbox 5 use psalm 5 test against php 8.2 and 8.3 remove test config
2 parents 8ab1c47 + 004e85d commit 280ee1e

10 files changed

Lines changed: 112 additions & 48 deletions

File tree

.github/workflows/ci.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, macOS-latest]
11-
php-version: ['8.1']
11+
php-version: ['8.2', '8.3']
1212
dependencies: ['lowest', 'highest']
1313
name: 'PHPUnit'
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
@@ -26,19 +26,19 @@ jobs:
2626
dependency-versions: ${{ matrix.dependencies }}
2727
- name: PHPUnit
2828
run: vendor/bin/phpunit --coverage-clover=coverage.clover
29-
- uses: codecov/codecov-action@v1
29+
- uses: codecov/codecov-action@v3
3030
with:
3131
token: ${{ secrets.CODECOV_TOKEN }}
3232
psalm:
3333
runs-on: ubuntu-latest
3434
strategy:
3535
matrix:
36-
php-version: ['8.1']
36+
php-version: ['8.2', '8.3']
3737
dependencies: ['lowest', 'highest']
3838
name: 'Psalm'
3939
steps:
4040
- name: Checkout
41-
uses: actions/checkout@v2
41+
uses: actions/checkout@v4
4242
- name: Setup PHP
4343
uses: shivammathur/setup-php@v2
4444
with:
@@ -54,11 +54,11 @@ jobs:
5454
runs-on: ubuntu-latest
5555
strategy:
5656
matrix:
57-
php-version: ['8.1']
57+
php-version: ['8.2']
5858
name: 'CS'
5959
steps:
6060
- name: Checkout
61-
uses: actions/checkout@v2
61+
uses: actions/checkout@v4
6262
- name: Setup PHP
6363
uses: shivammathur/setup-php@v2
6464
with:

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## 3.2.0 - 2023-11-12
4+
5+
### Added
6+
7+
- `Innmind\FileWatch\Watch\Kind`
8+
9+
### Changed
10+
11+
- Directly use an output diff when the watched path targets a directory
12+
13+
### Removed
14+
15+
- Support for PHP `8.1`
16+
317
## 3.1.0 - 2023-01-29
418

519
### Changed

composer.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
"issues": "http://github.com/Innmind/FileWatch/issues"
1616
},
1717
"require": {
18-
"php": "~8.1",
18+
"php": "~8.2",
1919
"innmind/url": "~4.0",
2020
"innmind/server-control": "~5.0",
2121
"innmind/time-warp": "~3.0",
2222
"innmind/time-continuum": "~3.0",
2323
"psr/log": "~3.0"
2424
},
25-
"minimum-stability": "dev",
26-
"prefer-stable": true,
2725
"autoload": {
2826
"psr-4": {
2927
"Innmind\\FileWatch\\": "src/"
@@ -35,9 +33,9 @@
3533
}
3634
},
3735
"require-dev": {
38-
"phpunit/phpunit": "~9.0",
39-
"vimeo/psalm": "~4.17",
36+
"phpunit/phpunit": "~10.2",
37+
"vimeo/psalm": "~5.12",
4038
"innmind/coding-standard": "~2.0",
41-
"innmind/black-box": "^4.17"
39+
"innmind/black-box": "~5.5"
4240
}
4341
}

phpunit.xml.dist

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd">
3+
<extensions>
4+
<bootstrap class="Innmind\BlackBox\PHPUnit\Extension">
5+
</bootstrap>
6+
</extensions>
7+
<coverage/>
8+
<testsuites>
9+
<testsuite name="Test suite">
10+
<directory>./tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
<source>
414
<include>
515
<directory>.</directory>
616
</include>
717
<exclude>
818
<directory>./tests</directory>
919
<directory>./vendor</directory>
1020
</exclude>
11-
</coverage>
12-
<testsuites>
13-
<testsuite name="Test suite">
14-
<directory>./tests</directory>
15-
</testsuite>
16-
</testsuites>
21+
</source>
1722
</phpunit>

psalm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<psalm
33
errorLevel="1"
44
resolveFromConfigFile="true"
5+
findUnusedCode="false"
6+
findUnusedBaselineEntry="true"
57
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
68
xmlns="https://getpsalm.org/schema/config"
79
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

src/Factory.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ public static function build(
1717
Halt $halt,
1818
Period $interval = null,
1919
): Watch {
20-
return new Watch\Fallback(
21-
new Watch\Tailf($processes),
22-
new Watch\Stat(
23-
$processes,
24-
$halt,
25-
$interval ?? new Second(1),
20+
$files = new Watch\Tailf($processes);
21+
$directories = new Watch\Stat(
22+
$processes,
23+
$halt,
24+
$interval ?? new Second(1),
25+
);
26+
27+
return new Watch\Kind(
28+
new Watch\Fallback(
29+
$files,
30+
$directories,
2631
),
32+
$directories,
2733
);
2834
}
2935
}

src/Ping/OutputDiff.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function __invoke(mixed $carry, callable $ping): Either
7373
);
7474
} while ($continue);
7575

76+
/** @var Either<Failed|L, C> */
7677
return $previous
7778
->map(static fn($state) => $state[1])
7879
->otherwise($this->switchStopValue(...));
@@ -140,9 +141,9 @@ private function diff(Output $previous, Output $now): bool
140141
*/
141142
private function switchStopValue(mixed $value): Either
142143
{
143-
return match ($value instanceof Stop) {
144-
true => Either::right($value->value()),
145-
false => Either::left($value),
144+
return match (true) {
145+
$value instanceof Stop => Either::right($value->value()),
146+
default => Either::left($value),
146147
};
147148
}
148149
}

src/Ping/ProcessOutput.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,24 @@ public function __construct(Processes $processes, Command $command)
2828
$this->command = $command;
2929
}
3030

31+
/**
32+
* @template C
33+
* @template L
34+
*
35+
* @param C $carry
36+
* @param callable(C): Either<L|Stop<C>, C> $ping
37+
*
38+
* @return Either<Failed|L, C>
39+
*/
3140
public function __invoke(mixed $carry, callable $ping): Either
3241
{
3342
$process = $this->processes->execute($this->command);
3443

3544
try {
45+
/**
46+
* @psalm-suppress InvalidArgument Due to the reduce where Either types are not enterily defined
47+
* @var Either<Failed|L, C>
48+
*/
3649
return $process
3750
->output()
3851
->reduce(
@@ -91,9 +104,9 @@ private function kill(Process $process): void
91104
*/
92105
private function switchStopValue(mixed $value): Either
93106
{
94-
return match ($value instanceof Stop) {
95-
true => Either::right($value->value()),
96-
false => Either::left($value),
107+
return match (true) {
108+
$value instanceof Stop => Either::right($value->value()),
109+
default => Either::left($value),
97110
};
98111
}
99112
}

src/Watch/Kind.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
namespace Innmind\FileWatch\Watch;
5+
6+
use Innmind\FileWatch\{
7+
Watch,
8+
Ping,
9+
};
10+
use Innmind\Url\Path;
11+
12+
final class Kind implements Watch
13+
{
14+
private Watch $files;
15+
private Watch $directories;
16+
17+
public function __construct(Watch $files, Watch $directories)
18+
{
19+
$this->files = $files;
20+
$this->directories = $directories;
21+
}
22+
23+
public function __invoke(Path $file): Ping
24+
{
25+
return match ($file->directory()) {
26+
true => ($this->directories)($file),
27+
false => ($this->files)($file),
28+
};
29+
}
30+
}

tests/FunctionalTest.php

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,22 +203,17 @@ public function testLog()
203203
$inner = Factory::build($processes, new Usleep);
204204
$watch = Logger::psr($inner, $logger = $this->createMock(LoggerInterface::class));
205205
$logger
206-
->expects($this->exactly(3))
206+
->expects($matcher = $this->exactly(3))
207207
->method('info')
208-
->withConsecutive(
209-
[
210-
'Starting to watch {path}',
211-
['path' => '/tmp/innmind/watch-file'],
212-
],
213-
[
214-
'Content at {path} changed',
215-
['path' => '/tmp/innmind/watch-file'],
216-
],
217-
[
218-
'Content at {path} changed',
219-
['path' => '/tmp/innmind/watch-file'],
220-
],
221-
);
208+
->willReturnCallback(function($message, $context) use ($matcher) {
209+
match ($matcher->numberOfInvocations()) {
210+
1 => $this->assertSame('Starting to watch {path}', $message),
211+
2 => $this->assertSame('Content at {path} changed', $message),
212+
3 => $this->assertSame('Content at {path} changed', $message),
213+
};
214+
215+
$this->assertSame(['path' => '/tmp/innmind/watch-file'], $context);
216+
});
222217

223218
$either = $watch(Path::of('/tmp/innmind/watch-file'))(0, static function($count) {
224219
++$count;

0 commit comments

Comments
 (0)