Skip to content

Commit 0acea47

Browse files
committed
More feature tests
1 parent 45174a0 commit 0acea47

File tree

11 files changed

+157
-24
lines changed

11 files changed

+157
-24
lines changed

tests/Functional/BasicPatchingTest.php

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,45 @@
44

55
class BasicPatchingTest extends SandboxTestCase
66
{
7+
const PACKAGEA_PATCH1_APPLICATIONS = [
8+
'/vendor/test/package-a/src/test.php' => 'patched-in-echo'
9+
];
10+
11+
const PACKAGEA_PATCH2_APPLICATIONS = [
12+
'/vendor/test/package-a/src/test.php' => [
13+
'layered-patch-line-1',
14+
'layered-patch-line-2',
15+
'layered-patch-line-3'
16+
]
17+
];
18+
719
public function testSimplePatchingDuringFirstInstallWorks()
820
{
921
$project = $this->getSandbox()->createProjectSandBox('test/project-template', 'dev-master', [
1022
'require' => [
1123
'test/patchset'=> '~1.0',
12-
'test/simple-package'=> 'dev-master',
24+
'test/package-a'=> 'dev-master',
1325
'creativestyle/composer-plugin-patchset'=> 'dev-master'
1426
]
1527
]);
1628

1729
$run = $project->runComposerCommand('install');
1830

19-
$this->assertThatComposerRunHasAppliedPatches($run, [
20-
'/vendor/test/simple-package/src/test.php' => 'patched-in-echo'
21-
]);
31+
$this->assertThatComposerRunHasAppliedPatches($run, self::PACKAGEA_PATCH1_APPLICATIONS);
2232
}
2333

2434
public function testPatchingPluginIsInstalledAndExecutedWhenPulledAsPatchsetDependency()
2535
{
2636
$project = $this->getSandbox()->createProjectSandBox('test/project-template', 'dev-master', [
2737
'require' => [
2838
'test/patchset'=> '~1.0',
29-
'test/simple-package'=> 'dev-master',
39+
'test/package-a'=> 'dev-master',
3040
]
3141
]);
3242

3343
$run = $project->runComposerCommand('install');
3444

35-
$this->assertThatComposerRunHasAppliedPatches($run, [
36-
'/vendor/test/simple-package/src/test.php' => 'patched-in-echo'
37-
]);
45+
$this->assertThatComposerRunHasAppliedPatches($run, self::PACKAGEA_PATCH1_APPLICATIONS);
3846
}
3947

4048
public function testPatchesAreAppliedWhenPackageIsAddedToExistingProject()
@@ -50,10 +58,54 @@ public function testPatchesAreAppliedWhenPackageIsAddedToExistingProject()
5058
$this->assertThatComposerRunWasSuccessful($installRun);
5159

5260
// At this point nothing to patch so no patches shall be applied
53-
$requireRun = $project->runComposerCommand('require', 'test/simple-package', 'dev-master');
61+
$requireRun = $project->runComposerCommand('require', 'test/package-a', 'dev-master');
5462

55-
$this->assertThatComposerRunHasAppliedPatches($requireRun, [
56-
'/vendor/test/simple-package/src/test.php' => 'patched-in-echo'
63+
$this->assertThatComposerRunHasAppliedPatches($requireRun, self::PACKAGEA_PATCH1_APPLICATIONS);
64+
}
65+
66+
public function testThatPatchesAreNotReappliedOnUpdate()
67+
{
68+
$project = $this->getSandbox()->createProjectSandBox('test/project-template', 'dev-master', [
69+
'require' => [
70+
'test/patchset'=> '~1.0',
71+
'test/package-a'=> 'dev-master',
72+
'creativestyle/composer-plugin-patchset'=> 'dev-master'
73+
]
5774
]);
75+
76+
$installRun = $project->runComposerCommand('install');
77+
78+
$this->assertThatComposerRunHasAppliedPatches($installRun, self::PACKAGEA_PATCH1_APPLICATIONS);
79+
80+
$updateRun = $project->runComposerCommand('update');
81+
82+
$this->assertContains('No patches to apply or clean', $updateRun->getFullOutput(), 'no patches were removed', true);
83+
$this->assertNotContains('Applied patch', $updateRun->getFullOutput(), 'no patches were applied', true);
5884
}
85+
86+
public function testThatLayeredPatchesAreAppliedInCorrectOrder()
87+
{
88+
$project = $this->getSandbox()->createProjectSandBox('test/project-template', 'dev-master', [
89+
'require' => [
90+
'test/patchset-extra'=> '~1.0',
91+
'test/package-a'=> 'dev-master',
92+
'creativestyle/composer-plugin-patchset'=> 'dev-master'
93+
]
94+
]);
95+
96+
$installRun = $project->runComposerCommand('install');
97+
98+
$this->assertThatComposerRunHasAppliedPatches($installRun,
99+
array_merge_recursive(
100+
self::PACKAGEA_PATCH1_APPLICATIONS,
101+
self::PACKAGEA_PATCH2_APPLICATIONS
102+
)
103+
);
104+
105+
$updateRun = $project->runComposerCommand('update');
106+
107+
$this->assertContains('No patches to apply or clean', $updateRun->getFullOutput(), 'no patches were removed', true);
108+
$this->assertNotContains('Applied patch', $updateRun->getFullOutput(), 'no patches were applied', true);
109+
}
110+
59111
}

tests/Functional/Fixtures/packages/simple-package/composer.json renamed to tests/Functional/Fixtures/packages/package-a/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "test/simple-package",
2+
"name": "test/package-a",
33
"type": "library",
44
"version": "dev-master",
55
"require": {}

tests/Functional/Fixtures/packages/simple-package/src/test.php renamed to tests/Functional/Fixtures/packages/package-a/src/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

33
echo 'first-echo';
4-
echo 'last-echo;
4+
echo 'last-echo';
55

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "test/package-b",
3+
"type": "library",
4+
"version": "dev-master",
5+
"require": {}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
echo 'first-echo';
4+
echo 'last-echo';
5+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "test/patchset-extra",
3+
"type": "patchset",
4+
"version": "1.0",
5+
"require": {
6+
"creativestyle/composer-plugin-patchset": "dev-master"
7+
},
8+
"extra": {
9+
"patchset": {
10+
"test/package-a": [
11+
{
12+
"description": "Patch in echo in the middle",
13+
"filename": "patches/package-a-patch-1.diff"
14+
},
15+
{
16+
"description": "Patch in echo at the end",
17+
"filename": "patches/package-a-patch-2.diff"
18+
}
19+
]
20+
}
21+
}
22+
}

tests/Functional/Fixtures/packages/patchset/v1.0/patches/simple-package-patch.diff renamed to tests/Functional/Fixtures/packages/patchset-extra/patches/package-a-patch-1.diff

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
diff --git a/src/test.php b/src/test.php
2-
index 3ef7f20..537fe08 100644
31
--- a/src/test.php
42
+++ b/src/test.php
53
@@ -1,5 +1,6 @@
64
<?php
75

86
echo 'first-echo';
97
+echo 'patched-in-echo';
10-
echo 'last-echo;
8+
echo 'last-echo';
119

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
diff --git a/src/test.php b/src/test.php
2+
index 6cb2e72..255f36b 100644
3+
--- a/src/test.php
4+
+++ b/src/test.php
5+
@@ -1,6 +1,9 @@
6+
<?php
7+
8+
+echo 'layered-patch-line-1';
9+
echo 'first-echo';
10+
echo 'patched-in-echo';
11+
+echo 'layered-patch-line-2';
12+
echo 'last-echo';
13+
+echo 'layered-patch-line-3';
14+

tests/Functional/Fixtures/packages/patchset/v1.0/composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
"type": "patchset",
44
"version": "1.0",
55
"require": {
6-
"creativestyle/composer-plugin-patchset": "*"
6+
"creativestyle/composer-plugin-patchset": "dev-master"
77
},
88
"extra": {
99
"patchset": {
10-
"test/simple-package": [
10+
"test/package-a": [
1111
{
1212
"description": "Patch in echo in the middle",
13-
"filename": "patches/simple-package-patch.diff",
14-
"version_constraint": "*"
13+
"filename": "patches/package-a-patch-1.diff"
1514
}
1615
]
1716
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- a/src/test.php
2+
+++ b/src/test.php
3+
@@ -1,5 +1,6 @@
4+
<?php
5+
6+
echo 'first-echo';
7+
+echo 'patched-in-echo';
8+
echo 'last-echo';
9+

0 commit comments

Comments
 (0)