Skip to content

Commit

Permalink
test(MysqlServerTest) update expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Aug 19, 2024
1 parent df7cb51 commit a019dbb
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions tests/unit/lucatume/WPBrowser/ManagedProcess/MysqlServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use PharData;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\AssertionFailedError;
use ReflectionMethod;

class MysqlServerTest extends Unit
{
Expand Down Expand Up @@ -459,11 +458,7 @@ function (string $url, string $file) use ($mysqlServer): void {
return $mockProcessStep === 'started';
},
'getPid' => 2389,
'stop' => function () use (&$mockProcessStep): int {
Assert::assertTrue(in_array($mockProcessStep, ['started', 'stopped'], true));
$mockProcessStep = 'stopped';
return 0;
}
'stop' => 0
]
)
);
Expand Down Expand Up @@ -914,12 +909,16 @@ public function testStopThrowsIfPidFileCannotBeUnlinked(): void

// Mock the PID file write.
$pidFileExists = false;
$this->setFunctionReturn('file_put_contents', function (string $file, $pid) use ($pidFile,&$pidFileExists): bool {
Assert::assertEquals($pidFile, $file);
Assert::assertEquals(2389, $pid);
$pidFileExists = true;
return true;
}, true);
$this->setFunctionReturn(
'file_put_contents',
function (string $file, $pid) use ($pidFile, &$pidFileExists): bool {
Assert::assertEquals($pidFile, $file);
Assert::assertEquals(2389, $pid);
$pidFileExists = true;
return true;
},
true
);

// The PID file exists.
$this->setFunctionReturn('is_file', function (string $file) use (&$pidFileExists, $pidFile): bool {
Expand All @@ -938,7 +937,15 @@ public function testStopThrowsIfPidFileCannotBeUnlinked(): void
'exec' => 1
]));

$mysqlServer = new MysqlServer($dir, 12345, 'someDatabase', 'root', 'secret','/usr/bin/mysqld', '/some/share/dir');
$mysqlServer = new MysqlServer(
$dir,
12345,
'someDatabase',
'root',
'secret',
'/usr/bin/mysqld',
'/some/share/dir'
);
$mysqlServer->start();

$this->expectException(RuntimeException::class);
Expand Down Expand Up @@ -1036,13 +1043,10 @@ function (string $url, string $file) use ($mysqlServer): void {
return $mockProcessStep === 'started';
},
'getPid' => 2389,
'stop' => function () use (&$mockProcessStep): int {
Assert::assertTrue(in_array($mockProcessStep, ['started', 'stopped'], true));
$mockProcessStep = 'stopped';
return 0;
}
'stop' => 0
]
));
)
);

// Mock the PDO connection.
$queries = [];
Expand Down

0 comments on commit a019dbb

Please sign in to comment.