Skip to content

Commit a30bf81

Browse files
committed
mock the processes in order to test the watchers
1 parent a6919c6 commit a30bf81

5 files changed

Lines changed: 155 additions & 19 deletions

File tree

tests/Agent/WatchFixturesTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
OperatingSystem,
1717
Config,
1818
};
19+
use Innmind\Server\Control\{
20+
Server,
21+
Server\Process\Builder,
22+
};
1923
use Innmind\Filesystem\{
2024
Adapter,
2125
Directory,
2226
};
23-
use Innmind\FileWatch\Watch;
2427
use Innmind\Url\Path;
25-
use Innmind\Immutable\Set;
28+
use Innmind\Immutable\{
29+
Set,
30+
Attempt,
31+
};
2632
use PHPUnit\Framework\TestCase;
2733

2834
class WatchFixturesTest extends TestCase
@@ -44,10 +50,28 @@ public function testSendMessageWhenFixturesAreModified()
4450
->add(Directory::named('fixtures'))
4551
->unwrap();
4652

53+
$count = 0;
4754
$os = OperatingSystem::new(
4855
Config::new()
4956
->mountFilesystemVia(static fn() => Attempt::result($adapter))
50-
->useFileWatch(Watch::via()), // todo simulate file change
57+
->useServerControl(Server::via(
58+
function($command) use (&$count) {
59+
$this->assertSame(
60+
"find '/vendor/package/fixtures/' '-type' 'f' | xargs '-n' '1' '-r' 'stat' '-f' '%Sm %N' '-t' '%Y-%m-%dT%H-%M-%S'",
61+
$command->toString(),
62+
);
63+
64+
$builder = Builder::foreground(2);
65+
$builder = match ($count) {
66+
0 => $builder->success([['output', 'output']]),
67+
1 => $builder->success([['changed', 'output']]),
68+
2 => $builder->failed(),
69+
};
70+
++$count;
71+
72+
return Attempt::result($builder->build());
73+
},
74+
)),
5175
);
5276

5377
$activities = Activities::new(

tests/Agent/WatchProofsTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
OperatingSystem,
1717
Config,
1818
};
19+
use Innmind\Server\Control\{
20+
Server,
21+
Server\Process\Builder,
22+
};
1923
use Innmind\Filesystem\{
2024
Adapter,
2125
Directory,
2226
};
23-
use Innmind\FileWatch\Watch;
2427
use Innmind\Url\Path;
25-
use Innmind\Immutable\Set;
28+
use Innmind\Immutable\{
29+
Set,
30+
Attempt,
31+
};
2632
use PHPUnit\Framework\TestCase;
2733

2834
class WatchProofsTest extends TestCase
@@ -44,10 +50,28 @@ public function testSendMessageWhenProofsAreModified()
4450
->add(Directory::named('proofs'))
4551
->unwrap();
4652

53+
$count = 0;
4754
$os = OperatingSystem::new(
4855
Config::new()
4956
->mountFilesystemVia(static fn() => Attempt::result($adapter))
50-
->useFileWatch(Watch::via()), // todo simulate file change
57+
->useServerControl(Server::via(
58+
function($command) use (&$count) {
59+
$this->assertSame(
60+
"find '/vendor/package/proofs/' '-type' 'f' | xargs '-n' '1' '-r' 'stat' '-f' '%Sm %N' '-t' '%Y-%m-%dT%H-%M-%S'",
61+
$command->toString(),
62+
);
63+
64+
$builder = Builder::foreground(2);
65+
$builder = match ($count) {
66+
0 => $builder->success([['output', 'output']]),
67+
1 => $builder->success([['changed', 'output']]),
68+
2 => $builder->failed(),
69+
};
70+
++$count;
71+
72+
return Attempt::result($builder->build());
73+
},
74+
)),
5175
);
5276

5377
$activities = Activities::new(

tests/Agent/WatchPropertiesTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
OperatingSystem,
1717
Config,
1818
};
19+
use Innmind\Server\Control\{
20+
Server,
21+
Server\Process\Builder,
22+
};
1923
use Innmind\Filesystem\{
2024
Adapter,
2125
Directory,
2226
};
23-
use Innmind\FileWatch\Watch;
2427
use Innmind\Url\Path;
25-
use Innmind\Immutable\Set;
28+
use Innmind\Immutable\{
29+
Set,
30+
Attempt,
31+
};
2632
use PHPUnit\Framework\TestCase;
2733

2834
class WatchPropertiesTest extends TestCase
@@ -44,10 +50,28 @@ public function testSendMessageWhenSourcesAreModified()
4450
->add(Directory::named('properties'))
4551
->unwrap();
4652

53+
$count = 0;
4754
$os = OperatingSystem::new(
4855
Config::new()
4956
->mountFilesystemVia(static fn() => Attempt::result($adapter))
50-
->useFileWatch(Watch::via()), // todo simulate file change
57+
->useServerControl(Server::via(
58+
function($command) use (&$count) {
59+
$this->assertSame(
60+
"find '/vendor/package/properties/' '-type' 'f' | xargs '-n' '1' '-r' 'stat' '-f' '%Sm %N' '-t' '%Y-%m-%dT%H-%M-%S'",
61+
$command->toString(),
62+
);
63+
64+
$builder = Builder::foreground(2);
65+
$builder = match ($count) {
66+
0 => $builder->success([['output', 'output']]),
67+
1 => $builder->success([['changed', 'output']]),
68+
2 => $builder->failed(),
69+
};
70+
++$count;
71+
72+
return Attempt::result($builder->build());
73+
},
74+
)),
5175
);
5276

5377
$activities = Activities::new(

tests/Agent/WatchSourcesTest.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@
1616
OperatingSystem,
1717
Config,
1818
};
19-
use Innmind\Filesystem\Adapter;
20-
use Innmind\FileWatch\Watch;
19+
use Innmind\Server\Control\{
20+
Server,
21+
Server\Process\Builder,
22+
};
23+
use Innmind\Filesystem\{
24+
Adapter,
25+
Directory,
26+
};
2127
use Innmind\Url\Path;
22-
use Innmind\Immutable\Set;
28+
use Innmind\Immutable\{
29+
Set,
30+
Attempt,
31+
};
2332
use PHPUnit\Framework\TestCase;
2433

2534
class WatchSourcesTest extends TestCase
@@ -36,10 +45,33 @@ public function testSendMessageWhenSourcesAreModified()
3645
{
3746
$agent = new WatchSources;
3847

48+
$adapter = Adapter::inMemory();
49+
$_ = $adapter
50+
->add(Directory::named('src'))
51+
->unwrap();
52+
53+
$count = 0;
3954
$os = OperatingSystem::new(
4055
Config::new()
41-
->mountFilesystemVia(static fn() => Attempt::result(Adapter::inMemory()))
42-
->useFileWatch(Watch::via()), // todo simulate file change
56+
->mountFilesystemVia(static fn() => Attempt::result($adapter))
57+
->useServerControl(Server::via(
58+
function($command) use (&$count) {
59+
$this->assertSame(
60+
"find '/vendor/package/src/' '-type' 'f' | xargs '-n' '1' '-r' 'stat' '-f' '%Sm %N' '-t' '%Y-%m-%dT%H-%M-%S'",
61+
$command->toString(),
62+
);
63+
64+
$builder = Builder::foreground(2);
65+
$builder = match ($count) {
66+
0 => $builder->success([['output', 'output']]),
67+
1 => $builder->success([['changed', 'output']]),
68+
2 => $builder->failed(),
69+
};
70+
++$count;
71+
72+
return Attempt::result($builder->build());
73+
},
74+
)),
4375
);
4476

4577
$activities = Activities::new(

tests/Agent/WatchTestsTest.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@
1616
OperatingSystem,
1717
Config,
1818
};
19-
use Innmind\Filesystem\Adapter;
20-
use Innmind\FileWatch\Watch;
19+
use Innmind\Server\Control\{
20+
Server,
21+
Server\Process\Builder,
22+
};
23+
use Innmind\Filesystem\{
24+
Adapter,
25+
Directory,
26+
};
2127
use Innmind\Url\Path;
22-
use Innmind\Immutable\Set;
28+
use Innmind\Immutable\{
29+
Set,
30+
Attempt,
31+
};
2332
use PHPUnit\Framework\TestCase;
2433

2534
class WatchTestsTest extends TestCase
@@ -36,10 +45,33 @@ public function testSendMessageWhenSourcesAreModified()
3645
{
3746
$agent = new WatchTests;
3847

48+
$adapter = Adapter::inMemory();
49+
$_ = $adapter
50+
->add(Directory::named('tests'))
51+
->unwrap();
52+
53+
$count = 0;
3954
$os = OperatingSystem::new(
4055
Config::new()
41-
->mountFilesystemVia(static fn() => Attempt::result(Adapter::inMemory()))
42-
->useFileWatch(Watch::via()), // todo simulate file change
56+
->mountFilesystemVia(static fn() => Attempt::result($adapter))
57+
->useServerControl(Server::via(
58+
function($command) use (&$count) {
59+
$this->assertSame(
60+
"find '/vendor/package/tests/' '-type' 'f' | xargs '-n' '1' '-r' 'stat' '-f' '%Sm %N' '-t' '%Y-%m-%dT%H-%M-%S'",
61+
$command->toString(),
62+
);
63+
64+
$builder = Builder::foreground(2);
65+
$builder = match ($count) {
66+
0 => $builder->success([['output', 'output']]),
67+
1 => $builder->success([['changed', 'output']]),
68+
2 => $builder->failed(),
69+
};
70+
++$count;
71+
72+
return Attempt::result($builder->build());
73+
},
74+
)),
4375
);
4476

4577
$activities = Activities::new(

0 commit comments

Comments
 (0)