aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/test/PHPGit/Command/StashCommandTest.php
blob: bb87e48ea060f8954a9473a29e76f801055bd9ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php

use PHPGit\Git;
use Symfony\Component\Filesystem\Filesystem;

require_once __DIR__ . '/../BaseTestCase.php';

class StashCommandTest extends BaseTestCase
{

    public function testStash()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash();

        $this->assertEquals('hello', file_get_contents($this->directory.'/README.md'));
    }

    public function testStashSave()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash->save('stash test');

        $this->assertEquals('hello', file_get_contents($this->directory.'/README.md'));
    }

    public function testStashList()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash();

        $stashes = $git->stash->lists();

        $this->assertCount(1, $stashes);
        $this->assertEquals('master', $stashes[0]['branch']);
        $this->assertStringEndsWith('Initial commit', $stashes[0]['message']);
    }

    public function testStashShow()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash();
        $git->stash->show('stash@{0}');
    }

    public function testStashDrop()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash();
        $git->stash->drop();

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash();
        $git->stash->drop('stash@{0}');

        $this->assertCount(0, $git->stash->lists());
    }

    public function testStashPop()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash->save('stash#1');

        $filesystem->dumpFile($this->directory . '/README.md', 'bar');
        $git->stash->save('stash#2');
        $git->stash->pop('stash@{1}');

        $this->assertEquals('hi!', file_get_contents($this->directory.'/README.md'));
        $this->assertCount(1, $git->stash->lists());
    }

    public function testStashApply()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash->save('stash#1');

        $filesystem->dumpFile($this->directory . '/README.md', 'bar');
        $git->stash->save('stash#2');
        $git->stash->apply('stash@{1}');

        $this->assertEquals('hi!', file_get_contents($this->directory.'/README.md'));
        $this->assertCount(2, $git->stash->lists());
    }

    public function testStashBranch()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash();

        $git->stash->branch('dev', 'stash@{0}');
        $status = $git->status();

        $this->assertEquals('dev', $status['branch']);
        $this->assertEquals('hi!', file_get_contents($this->directory.'/README.md'));
    }

    public function testStashClear()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $git->stash();
        $git->stash->clear();

        $this->assertCount(0, $git->stash->lists());
    }

    public function testStashCreate()
    {
        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);
        $filesystem->dumpFile($this->directory . '/README.md', 'hello');
        $git->add('.');
        $git->commit('Initial commit');

        $filesystem->dumpFile($this->directory . '/README.md', 'hi!');
        $object = $git->stash->create();

        $this->assertNotEmpty($object);
    }

}