|
19 | 19 | ->with(Platform::cwd('.git/hooks/skip-once'))
|
20 | 20 | ->andReturnTrue();
|
21 | 21 |
|
| 22 | + $tmp_file = Platform::temp_test_path('whisky_test_commit_msg'); |
| 23 | + |
22 | 24 | File::shouldReceive('get')
|
23 | 25 | ->with(Platform::cwd('whisky.json'))
|
24 |
| - ->andReturn(<<<'JSON' |
| 26 | + ->andReturn(<<<"JSON" |
25 | 27 | {
|
26 | 28 | "disabled": [],
|
27 | 29 | "hooks": {
|
28 | 30 | "pre-commit": [
|
29 |
| - "echo \"poop\" > /tmp/whisky_test_commit_msg" |
| 31 | + "echo \"poop\" > {$tmp_file}" |
30 | 32 | ]
|
31 | 33 | }
|
32 | 34 | }
|
|
35 | 37 | $this->artisan('run pre-commit')
|
36 | 38 | ->assertExitCode(0);
|
37 | 39 |
|
38 |
| - expect(file_exists('/tmp/whisky_test_commit_msg')) |
| 40 | + expect(file_exists($tmp_file)) |
39 | 41 | ->toBeFalse();
|
40 | 42 | });
|
41 | 43 |
|
|
48 | 50 | ->with(Platform::cwd('.git/hooks/skip-once'))
|
49 | 51 | ->andReturnFalse();
|
50 | 52 |
|
| 53 | + $tmp_file = Platform::temp_test_path('whisky_test_commit_msg'); |
| 54 | + |
51 | 55 | /**
|
52 | 56 | * We need to send the output to the disk
|
53 | 57 | * otherwise the output is sent to the
|
54 | 58 | * test output and we can't check it.
|
55 | 59 | */
|
56 | 60 | File::shouldReceive('get')
|
57 | 61 | ->with(Platform::cwd('whisky.json'))
|
58 |
| - ->andReturn(<<<'JSON' |
| 62 | + ->andReturn(<<<"JSON" |
59 | 63 | {
|
60 | 64 | "disabled": [],
|
61 | 65 | "hooks": {
|
62 | 66 | "commit-msg": [
|
63 |
| - "echo \"$1\" > /tmp/whisky_test_commit_msg" |
| 67 | + "echo \"$1\" > {$tmp_file}" |
64 | 68 | ]
|
65 | 69 | }
|
66 | 70 | }
|
|
69 | 73 | $this->artisan('run commit-msg ".git/COMMIT_EDITMSG"')
|
70 | 74 | ->assertExitCode(0);
|
71 | 75 |
|
72 |
| - expect(file_get_contents('/tmp/whisky_test_commit_msg')) |
| 76 | + expect(file_get_contents($tmp_file)) |
73 | 77 | ->toContain('.git/COMMIT_EDITMSG');
|
74 | 78 |
|
75 |
| - unlink('/tmp/whisky_test_commit_msg'); |
| 79 | + unlink($tmp_file); |
76 | 80 | });
|
77 | 81 |
|
78 | 82 | it('still works if no arguments are passed to run command', function () {
|
|
84 | 88 | ->with(Platform::cwd('.git/hooks/skip-once'))
|
85 | 89 | ->andReturnFalse();
|
86 | 90 |
|
| 91 | + $tmp_file = Platform::temp_test_path('whisky_test_pre_commit'); |
| 92 | + |
87 | 93 | File::shouldReceive('get')
|
88 | 94 | ->with(Platform::cwd('whisky.json'))
|
89 |
| - ->andReturn(<<<'JSON' |
| 95 | + ->andReturn(<<<"JSON" |
90 | 96 | {
|
91 | 97 | "disabled": [],
|
92 | 98 | "hooks": {
|
93 | 99 | "pre-commit": [
|
94 |
| - "echo \"pre-commit\" > /dev/null" |
| 100 | + "echo \"pre-commit\" > {$tmp_file}" |
95 | 101 | ]
|
96 | 102 | }
|
97 | 103 | }
|
98 | 104 | JSON);
|
99 | 105 |
|
100 | 106 | $this->artisan('run pre-commit')
|
101 | 107 | ->assertExitCode(0);
|
| 108 | + |
| 109 | + unlink($tmp_file); |
102 | 110 | });
|
103 | 111 |
|
104 | 112 | it('handles a missing expected argument gracefully', function () {
|
|
110 | 118 | ->with(Platform::cwd('.git/hooks/skip-once'))
|
111 | 119 | ->andReturnFalse();
|
112 | 120 |
|
| 121 | + $tmp_file = Platform::temp_test_path('whisky_test_commit_msg'); |
| 122 | + |
113 | 123 | File::shouldReceive('get')
|
114 | 124 | ->with(Platform::cwd('whisky.json'))
|
115 |
| - ->andReturn(<<<'JSON' |
| 125 | + ->andReturn(<<<"JSON" |
116 | 126 | {
|
117 | 127 | "disabled": [],
|
118 | 128 | "hooks": {
|
119 | 129 | "commit-msg": [
|
120 |
| - "echo \"$1\" > /tmp/whisky_test_commit_msg" |
| 130 | + "echo \"$1\" > {$tmp_file}" |
121 | 131 | ]
|
122 | 132 | }
|
123 | 133 | }
|
|
126 | 136 | $this->artisan('run commit-msg')
|
127 | 137 | ->assertExitCode(0);
|
128 | 138 |
|
129 |
| - expect(file_get_contents('/tmp/whisky_test_commit_msg')) |
| 139 | + expect(file_get_contents($tmp_file)) |
130 | 140 | ->toBe("\n");
|
131 | 141 |
|
132 |
| - unlink('/tmp/whisky_test_commit_msg'); |
| 142 | + unlink($tmp_file); |
133 | 143 | });
|
0 commit comments