88
99class 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 */
127120class RemoteExecutorTestHelper extends RemoteExecutor
128121{
129122 public function __construct ()
130123 {
131- // Bypass parent constructor
124+ // Skip parent constructor
132125 }
133126}
0 commit comments