Skip to content

Commit 2ba9285

Browse files
committed
All tests completed
1 parent dc4a575 commit 2ba9285

17 files changed

Lines changed: 2243 additions & 416 deletions

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^8.0.2",
21+
"php": "^8.1",
2222
"winter/storm": "^1.2",
2323
"phpseclib/phpseclib": "^3.0",
24-
"composer/installers": "~1.0"
24+
"composer/installers": "^2.2"
2525
},
2626
"autoload": {
2727
"psr-4": {
@@ -31,7 +31,8 @@
3131
"config": {
3232
"allow-plugins": {
3333
"composer/installers": true
34-
}
34+
},
35+
"sort-packages": true
3536
},
3637
"extra": {
3738
"installer-name": "syncops",

support/MysqlCommandBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static function dump(array $config, string $outputFile, bool $gzip = true
99
$db = escapeshellarg($config['database']);
1010
$limitTables = implode(' ', array_map('escapeshellarg', $tables));
1111

12-
$command = "mysqldump --skip-comments --replace -u{$user} -p{$pass} {$db} {$limitTables}";
12+
$command = trim("mysqldump --skip-comments --replace -u{$user} -p{$pass} {$db} {$limitTables}");
1313

1414
if ($gzip) {
1515
$command .= " | gzip > " . escapeshellarg($outputFile);

tests/HelpersTest.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ class HelpersTest extends PluginTestCase
1111
public function testFormatPathWithoutTrailingSlash(): void
1212
{
1313
$result = format_path('/var/www/html');
14-
15-
// Assert a trailing slash was added
16-
$this->assertEquals('/var/www/html/', $result);
14+
$this->assertSame('/var/www/html/', $result);
1715
}
1816

1917
/**
@@ -23,9 +21,7 @@ public function testFormatPathWithoutTrailingSlash(): void
2321
public function testFormatPathWithTrailingSlash(): void
2422
{
2523
$result = format_path('/var/www/html/');
26-
27-
// Assert the path remains unchanged
28-
$this->assertEquals('/var/www/html/', $result);
24+
$this->assertSame('/var/www/html/', $result);
2925
}
3026

3127
/**
@@ -35,9 +31,27 @@ public function testFormatPathWithTrailingSlash(): void
3531
public function testFormatPathWithMultipleTrailingSlashes(): void
3632
{
3733
$result = format_path('/var/www/html///');
34+
$this->assertSame('/var/www/html/', $result);
35+
}
3836

39-
// Assert only one trailing slash remains
40-
$this->assertEquals('/var/www/html/', $result);
37+
/**
38+
* Test function: format_path
39+
* Test formatting the root directory path.
40+
*/
41+
public function testFormatPathWithRootSlash(): void
42+
{
43+
$result = format_path('/');
44+
$this->assertSame('/', $result);
45+
}
46+
47+
/**
48+
* Test function: format_path
49+
* Ensure Windows-style backslashes are not modified unexpectedly.
50+
*/
51+
public function testFormatPathWithWindowsBackslashes(): void
52+
{
53+
$result = format_path('C:\\laragon\\www\\project');
54+
$this->assertSame('C:\\laragon\\www\\project/', $result);
4155
}
4256

4357
/**
@@ -47,8 +61,6 @@ public function testFormatPathWithMultipleTrailingSlashes(): void
4761
public function testFormatPathWithNull(): void
4862
{
4963
$result = format_path(null);
50-
51-
// Assert null is returned for null input
5264
$this->assertNull($result);
5365
}
5466

@@ -59,8 +71,6 @@ public function testFormatPathWithNull(): void
5971
public function testFormatPathWithEmptyString(): void
6072
{
6173
$result = format_path('');
62-
63-
// Assert null is returned for empty string
6474
$this->assertNull($result);
6575
}
6676
}

tests/classes/RemoteExecutorTest.php

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
class RemoteExecutorTest extends PluginTestCase
1010
{
11-
public function setUp(): void
12-
{
13-
parent::setUp();
14-
}
15-
1611
public function tearDown(): void
1712
{
1813
Mockery::close();
@@ -21,22 +16,22 @@ public function tearDown(): void
2116

2217
/**
2318
* Test function: __construct
24-
* Test that constructor throws an exception when server config is empty.
19+
* It should throw an exception when no config exists for the given server.
2520
*/
2621
public function testConstructorThrowsIfNoConfig(): void
2722
{
2823
$this->expectException(\RuntimeException::class);
29-
$this->expectExceptionMessage("No config for server invalid_server");
24+
$this->expectExceptionMessage('No config for server invalid_server');
3025

31-
// Provide empty array to satisfy typed property
32-
config()->set("syncops.connections.invalid_server", []);
26+
// Use empty array (null would cause TypeError before our check)
27+
config()->set('syncops.connections.invalid_server', []);
3328

3429
new RemoteExecutor('invalid_server');
3530
}
3631

3732
/**
3833
* Test function: __construct
39-
* Test that SSH and SFTP executors are created with password credentials.
34+
* When password credentials are provided, they should be used directly.
4035
*/
4136
public function testConstructorWithPassword(): void
4237
{
@@ -50,12 +45,9 @@ public function testConstructorWithPassword(): void
5045
'key_path' => '',
5146
]);
5247

53-
// Mock executors to avoid real connections
54-
$sshMock = Mockery::mock(SshExecutor::class)->makePartial();
55-
$sftpMock = Mockery::mock(SftpExecutor::class)->makePartial();
56-
57-
$this->app->bind(SshExecutor::class, fn() => $sshMock);
58-
$this->app->bind(SftpExecutor::class, fn() => $sftpMock);
48+
// Mock PublicKeyLoader to ensure it's not used
49+
$mockKeyLoader = Mockery::mock('alias:phpseclib3\Crypt\PublicKeyLoader');
50+
$mockKeyLoader->shouldNotReceive('load');
5951

6052
$executor = new RemoteExecutor($server);
6153

@@ -65,7 +57,7 @@ public function testConstructorWithPassword(): void
6557

6658
/**
6759
* Test function: __construct
68-
* Test that SSH and SFTP executors are created with public key credentials.
60+
* When key_path is set, PublicKeyLoader::load() should be called.
6961
*/
7062
public function testConstructorWithPublicKey(): void
7163
{
@@ -80,27 +72,23 @@ public function testConstructorWithPublicKey(): void
8072
'key_path' => $keyPath,
8173
]);
8274

83-
// Mock PublicKeyLoader
8475
$mockKeyLoader = Mockery::mock('alias:phpseclib3\Crypt\PublicKeyLoader');
85-
$mockKeyLoader->shouldReceive('load')->once()->andReturn('PUBLIC_KEY');
86-
87-
$sshMock = Mockery::mock(SshExecutor::class)->makePartial();
88-
$sftpMock = Mockery::mock(SftpExecutor::class)->makePartial();
89-
90-
$this->app->bind(SshExecutor::class, fn() => $sshMock);
91-
$this->app->bind(SftpExecutor::class, fn() => $sftpMock);
76+
$mockKeyLoader->shouldReceive('load')
77+
->once()
78+
->with('FAKE_KEY')
79+
->andReturn('PUBLIC_KEY');
9280

9381
$executor = new RemoteExecutor($server);
9482

9583
$this->assertInstanceOf(SshExecutor::class, $executor->ssh);
9684
$this->assertInstanceOf(SftpExecutor::class, $executor->sftp);
9785

98-
unlink($keyPath);
86+
@unlink($keyPath);
9987
}
10088

10189
/**
10290
* Test function: connectBoth
103-
* Test that connectBoth() calls connect() on both SSH and SFTP executors.
91+
* It should call connect() on both SSH and SFTP executors.
10492
*/
10593
public function testConnectBoth(): void
10694
{
@@ -116,18 +104,23 @@ public function testConnectBoth(): void
116104

117105
$executor->connectBoth();
118106

119-
// PHPUnit requires at least one assertion
120-
$this->assertTrue(true);
107+
// Verify that both connect() calls occurred
108+
$sshMock->shouldHaveReceived('connect')->once();
109+
$sftpMock->shouldHaveReceived('connect')->once();
110+
111+
// Add an explicit PHPUnit assertion to avoid "risky" flag
112+
$this->assertTrue(true, 'Mock expectations verified successfully.');
121113
}
122114
}
123115

124116
/**
125-
* Helper class to bypass RemoteExecutor constructor for connectBoth test.
117+
* Helper class that bypasses RemoteExecutor's constructor
118+
* so we can manually inject mock executors.
126119
*/
127120
class RemoteExecutorTestHelper extends RemoteExecutor
128121
{
129122
public function __construct()
130123
{
131-
// Bypass parent constructor
124+
// Skip parent constructor
132125
}
133126
}

0 commit comments

Comments
 (0)