2
2
3
3
/**
4
4
* @file
5
- * Contains \DrupalComposer\DrupalScaffold\Tests\PluginTest .
5
+ * Contains \DrupalComposer\DrupalScaffold\Tests\HandlerTest .
6
6
*/
7
7
8
8
namespace DrupalComposer \DrupalScaffold \Tests ;
9
9
10
- use Composer \Util \Filesystem ;
11
-
12
10
/**
13
11
* Tests composer plugin functionality.
14
12
*/
15
- class HandlerTest extends \PHPUnit_Framework_TestCase {
16
-
17
- /**
18
- * @var \Composer\Util\Filesystem
19
- */
20
- protected $ fs ;
21
-
22
- /**
23
- * @var string
24
- */
25
- protected $ tmpDir ;
26
-
27
- /**
28
- * @var string
29
- */
30
- protected $ rootDir ;
31
-
32
- /**
33
- * @var string
34
- */
35
- protected $ tmpReleaseTag ;
36
-
37
- /**
38
- * SetUp test
39
- */
40
- public function setUp () {
41
- $ this ->rootDir = realpath (realpath (__DIR__ . '/.. ' ));
42
-
43
- // Prepare temp directory.
44
- $ this ->fs = new Filesystem ();
45
- $ this ->tmpDir = realpath (sys_get_temp_dir ()) . DIRECTORY_SEPARATOR . 'drupal-scaffold ' ;
46
- $ this ->ensureDirectoryExistsAndClear ($ this ->tmpDir );
47
-
48
- $ this ->writeTestReleaseTag ();
49
- $ this ->writeComposerJSON ();
50
-
51
- chdir ($ this ->tmpDir );
52
- }
53
-
54
- /**
55
- * tearDown
56
- *
57
- * @return void
58
- */
59
- public function tearDown ()
60
- {
61
- $ this ->fs ->removeDirectory ($ this ->tmpDir );
62
- $ this ->git (sprintf ('tag -d "%s" ' , $ this ->tmpReleaseTag ));
63
- }
13
+ class HandlerTest extends BaseTest {
64
14
65
15
/**
66
16
* Tests that files for dev environments are downloaded only in dev mode.
@@ -79,87 +29,14 @@ public function testDevFiles() {
79
29
}
80
30
81
31
/**
82
- * Writes the default composer json to the temp direcoty.
83
- */
84
- protected function writeComposerJSON () {
85
- $ json = json_encode ($ this ->composerJSONDefaults (), JSON_PRETTY_PRINT );
86
- // Write composer.json.
87
- file_put_contents ($ this ->tmpDir . '/composer.json ' , $ json );
88
- }
89
-
90
- /**
91
- * Writes a tag for the current commit, so we can reference it directly in the
92
- * composer.json.
93
- */
94
- protected function writeTestReleaseTag () {
95
- // Tag the current state.
96
- $ this ->tmpReleaseTag = '999.0. ' . time ();
97
- $ this ->git (sprintf ('tag -a "%s" -m "%s" ' , $ this ->tmpReleaseTag , 'Tag for testing this exact commit ' ));
98
- }
99
-
100
- /**
101
- * Provides the default composer.json data.
32
+ * Add prefer-stable true to speed up tests.
102
33
*
103
34
* @return array
104
35
*/
105
36
protected function composerJSONDefaults () {
106
- return array (
107
- 'repositories ' => array (
108
- array (
109
- 'type ' => 'vcs ' ,
110
- 'url ' => $ this ->rootDir ,
111
- )
112
- ),
113
- 'require ' => array (
114
- 'drupal-composer/drupal-scaffold ' => $ this ->tmpReleaseTag ,
115
- 'composer/installers ' => '^1.0.20 ' ,
116
- 'drupal/core ' => '8.0.0 ' ,
117
- ),
118
- 'scripts ' => array (
119
- 'drupal-scaffold ' => 'DrupalComposer \\DrupalScaffold \\Plugin::scaffold '
120
- ),
121
- 'minimum-stability ' => 'dev ' ,
122
- 'prefer-stable ' => true ,
123
- );
37
+ $ composerJsonDefault = parent ::composerJSONDefaults ();
38
+ $ composerJsonDefault ['prefer-stable ' ] = true ;
39
+ return $ composerJsonDefault ;
124
40
}
125
41
126
- /**
127
- * Wrapper for the composer command.
128
- *
129
- * @param string $command
130
- * Composer command name, arguments and/or options
131
- */
132
- protected function composer ($ command ) {
133
- chdir ($ this ->tmpDir );
134
- passthru (escapeshellcmd ($ this ->rootDir . '/vendor/bin/composer ' . $ command ), $ exit_code );
135
- if ($ exit_code !== 0 ) {
136
- throw new \Exception ('Composer returned a non-zero exit code ' );
137
- }
138
- }
139
-
140
- /**
141
- * Wrapper for git command in the root directory.
142
- *
143
- * @param $command
144
- * Git command name, arguments and/or options.
145
- */
146
- protected function git ($ command ) {
147
- chdir ($ this ->rootDir );
148
- passthru (escapeshellcmd ('git ' . $ command ), $ exit_code );
149
- if ($ exit_code !== 0 ) {
150
- throw new \Exception ('Git returned a non-zero exit code ' );
151
- }
152
- }
153
-
154
- /**
155
- * Makes sure the given directory exists and has no content.
156
- *
157
- * @param string $directory
158
- */
159
- protected function ensureDirectoryExistsAndClear ($ directory ) {
160
- if (is_dir ($ directory )) {
161
- $ this ->fs ->removeDirectory ($ directory );
162
- }
163
- mkdir ($ directory , 0777 , true );
164
- }
165
42
}
0 commit comments