1
+ <?php
2
+
3
+ use PHPUnit \Framework \TestCase ;
4
+ use optimistex \deploy \DeployApplication ;
5
+
6
+ class DeployApplicationTest extends TestCase
7
+ {
8
+ private $ fileName = 'git-deploy-log.txt ' ;
9
+
10
+ public function setUp ()
11
+ {
12
+ parent ::setUp ();
13
+ @unlink ($ this ->fileName );
14
+ }
15
+
16
+ public function tearDown ()
17
+ {
18
+ @unlink ($ this ->fileName );
19
+ parent ::tearDown ();
20
+ }
21
+
22
+ public function testKeyIsEmpty ()
23
+ {
24
+ $ app = new DeployApplication ('123 ' , '. ' , $ this ->fileName );
25
+
26
+ $ this ->assertFileNotExists ($ this ->fileName );
27
+ $ app ->run (['echo 111 ' ]);
28
+
29
+ $ this ->assertFileNotExists ($ this ->fileName );
30
+ $ app ->begin ();
31
+ $ app ->execute (['echo 111 ' ]);
32
+ $ app ->end ();
33
+ $ this ->assertFileNotExists ($ this ->fileName );
34
+ }
35
+
36
+ public function testKeyInvalid ()
37
+ {
38
+ $ _GET ['key ' ] = 'sdfg ' ;
39
+ $ _SERVER ['HTTP_HOST ' ] = 'test.domain ' ;
40
+ $ app = new DeployApplication ('123 ' , '. ' , $ this ->fileName );
41
+
42
+ $ this ->assertFileNotExists ($ this ->fileName );
43
+ $ app ->execute (['echo testing_echo ' ]);
44
+ $ this ->assertFileExists ($ this ->fileName );
45
+ $ log = file_get_contents ($ this ->fileName );
46
+ $ this ->assertRegExp ('/====+.+DENY.+test.domain/s ' , $ log );
47
+ }
48
+
49
+ public function testKeyValid1 ()
50
+ {
51
+ $ _GET ['key ' ] = '123 ' ;
52
+ $ _SERVER ['HTTP_HOST ' ] = 'test.domain ' ;
53
+ $ app = new DeployApplication ('123 ' , '. ' , $ this ->fileName );
54
+
55
+ $ this ->assertFileNotExists ($ this ->fileName );
56
+ $ app ->execute ();
57
+ $ this ->assertFileExists ($ this ->fileName );
58
+ $ log = file_get_contents ($ this ->fileName );
59
+ $ this ->assertRegExp ('/.+ACCESS IS OBTAINED.+Executing shell commands.+\$ git branch.+\$ git pull/si ' , $ log );
60
+ }
61
+
62
+ public function testKeyValid2 ()
63
+ {
64
+ $ _GET ['key ' ] = '123 ' ;
65
+ $ _SERVER ['HTTP_HOST ' ] = 'test.domain ' ;
66
+ $ app = new DeployApplication ('123 ' , '. ' , $ this ->fileName );
67
+
68
+ $ this ->assertFileNotExists ($ this ->fileName );
69
+ $ app ->execute (['echo testing_echo ' ]);
70
+ $ this ->assertFileExists ($ this ->fileName );
71
+ $ log = file_get_contents ($ this ->fileName );
72
+ $ this ->assertRegExp ('/.+ACCESS IS OBTAINED.+Executing shell commands.+\$ echo testing_echo.+testing_echo/si ' , $ log );
73
+ }
74
+ }
0 commit comments