Skip to content

Commit 5eb02ba

Browse files
author
Bastian Schwarz
committed
Added mockery in order to replace withConsecutive
1 parent c4e88d1 commit 5eb02ba

5 files changed

Lines changed: 26 additions & 30 deletions

File tree

.idea/deployer.base.iml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"symfony/console": "^6.1"
1616
},
1717
"require-dev": {
18+
"mockery/mockery": "^1.5",
1819
"roave/security-advisories": "dev-latest"
1920
},
2021
"autoload": {

test/task/deploy/updateCode/UploadTransferablesTest.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
use de\codenamephp\deployer\base\functions\iUpload;
2222
use de\codenamephp\deployer\base\task\deploy\updateCode\UploadTransferables;
2323
use de\codenamephp\deployer\base\transferable\iTransferable;
24+
use Mockery;
25+
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
2426
use PHPUnit\Framework\TestCase;
2527

2628
final class UploadTransferablesTest extends TestCase {
2729

30+
use MockeryPHPUnitIntegration;
31+
2832
private UploadTransferables $sut;
2933

3034
protected function setUp() : void {
@@ -35,15 +39,10 @@ protected function setUp() : void {
3539
}
3640

3741
public function test__invoke() : void {
38-
$this->sut->deployerFunctions = $this->createMock(iUpload::class);
39-
$this->sut->deployerFunctions
40-
->expects(self::exactly(3))
41-
->method('upload')
42-
->withConsecutive(
43-
['local path 1', 'remote path 1', ['config 1']],
44-
['local path 2', 'remote path 2', ['config 2']],
45-
['local path 3', 'remote path 3', ['config 3']],
46-
);
42+
$this->sut->deployerFunctions = Mockery::mock(iUpload::class);
43+
$this->sut->deployerFunctions->allows('upload')->with('local path 1', 'remote path 1', ['config 1'])->once()->ordered();
44+
$this->sut->deployerFunctions->allows('upload')->with('local path 2', 'remote path 2', ['config 2'])->once()->ordered();
45+
$this->sut->deployerFunctions->allows('upload')->with('local path 3', 'remote path 3', ['config 3'])->once()->ordered();
4746

4847
$transferable1 = $this->createMock(iTransferable::class);
4948
$transferable1->expects(self::once())->method('getLocalPath')->willReturn('local path 1');

test/task/media/CopyTest.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
use de\codenamephp\deployer\base\task\media\Copy;
2525
use de\codenamephp\deployer\base\transferable\iTransferable;
2626
use Deployer\Host\Host;
27+
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
2728
use PHPUnit\Framework\TestCase;
2829

2930
final class CopyTest extends TestCase {
3031

32+
use MockeryPHPUnitIntegration;
33+
3134
private Copy $sut;
3235

3336
protected function setUp() : void {
@@ -83,27 +86,16 @@ public function test__invoke() : void {
8386
$transferable2->expects(self::once())->method('getConfig')->willReturn(['options' => ['options2_1', 'options2_2']]);
8487
$this->sut->setTransferables($transferable1, $transferable2);
8588

86-
$deployerFunctions = $this->createMock(iAll::class);
87-
$deployerFunctions->expects(self::once())->method('getOption')->with(Copy::OPTION_SOURCE_HOST)->willReturn(1234);
88-
$deployerFunctions->expects(self::once())->method('firstHost')->with('1234')->willReturn($sourceHost);
89-
$deployerFunctions->expects(self::once())->method('currentHost')->willReturn($targetHost);
90-
$deployerFunctions
91-
->expects(self::exactly(4))
92-
->method('parseOnHost')
93-
->withConsecutive(
94-
[$sourceHost, 'source_path_1'],
95-
[$targetHost, 'target_path_1'],
96-
[$sourceHost, 'source_path_2'],
97-
[$targetHost, 'target_path_2'],
98-
)
99-
->willReturnOnConsecutiveCalls('parsed_source_path_1', 'parsed_target_path_1', 'parsed_source_path_2', 'parsed_target_path_2');
100-
$deployerFunctions
101-
->expects(self::exactly(2))
102-
->method('runLocally')
103-
->withConsecutive(
104-
['ssh source_ssh_arguments source_connection_string "rsync -e \'ssh -o StrictHostKeyChecking=no target_ssh_arguments\' -azP options1_1 options1_2 parsed_source_path_1 target_connection_string:parsed_target_path_1"'],
105-
['ssh source_ssh_arguments source_connection_string "rsync -e \'ssh -o StrictHostKeyChecking=no target_ssh_arguments\' -azP options2_1 options2_2 parsed_source_path_2 target_connection_string:parsed_target_path_2"']
106-
);
89+
$deployerFunctions = \Mockery::mock(iAll::class);
90+
$deployerFunctions->allows('getOption')->once()->with(Copy::OPTION_SOURCE_HOST)->andReturn(1234);
91+
$deployerFunctions->allows('firstHost')->once()->with('1234')->andReturn($sourceHost);
92+
$deployerFunctions->allows('currentHost')->once()->andReturn($targetHost);
93+
$deployerFunctions->allows('parseOnHost')->once()->ordered()->with($sourceHost, 'source_path_1')->andReturn('parsed_source_path_1');
94+
$deployerFunctions->allows('parseOnHost')->once()->ordered()->with($targetHost, 'target_path_1')->andReturn('parsed_target_path_1');
95+
$deployerFunctions->allows('runLocally')->once()->ordered()->with('ssh source_ssh_arguments source_connection_string "rsync -e \'ssh -o StrictHostKeyChecking=no target_ssh_arguments\' -azP options1_1 options1_2 parsed_source_path_1 target_connection_string:parsed_target_path_1"');
96+
$deployerFunctions->allows('parseOnHost')->once()->ordered()->with($sourceHost, 'source_path_2')->andReturn('parsed_source_path_2');
97+
$deployerFunctions->allows('parseOnHost')->once()->ordered()->with($targetHost, 'target_path_2')->andReturn('parsed_target_path_2');
98+
$deployerFunctions->allows('runLocally')->once()->ordered()->with('ssh source_ssh_arguments source_connection_string "rsync -e \'ssh -o StrictHostKeyChecking=no target_ssh_arguments\' -azP options2_1 options2_2 parsed_source_path_2 target_connection_string:parsed_target_path_2"');
10799
$this->sut->deployerFunctions = $deployerFunctions;
108100

109101
$this->sut->__invoke();

0 commit comments

Comments
 (0)