5
5
6
6
class WebTest extends WebTestCase
7
7
{
8
+ private $ client ;
9
+
8
10
public function createApplication ()
9
11
{
10
12
$ app = require __DIR__ .'/../../src/app.php ' ;
@@ -20,12 +22,17 @@ public function createApplication()
20
22
return $ app ;
21
23
}
22
24
23
- public function testRoot ()
25
+ public function setUp ()
24
26
{
25
- $ client = $ this -> createClient ();
27
+ parent :: setUp ();
26
28
27
- $ client ->request ('GET ' , '/ ' );
28
- $ response = $ client ->getResponse ();
29
+ $ this ->client = $ this ->createClient ();
30
+ }
31
+
32
+ public function testRoot ()
33
+ {
34
+ $ this ->client ->request ('GET ' , '/ ' );
35
+ $ response = $ this ->client ->getResponse ();
29
36
$ this ->assertTrue ($ response ->isOk (), '/ should return ok response ' );
30
37
$ this ->assertContains ('trashbin ' , $ response ->getContent ());
31
38
$ this ->assertContains ('simple pastebin ' , $ response ->getContent ());
@@ -35,55 +42,49 @@ public function testRoot()
35
42
36
43
public function testCreatePaste ()
37
44
{
38
- $ client = $ this ->createClient ();
39
- $ client ->setServerParameters (array ('REQUEST_TIME ' => 1337882841 ));
45
+ $ this ->client ->setServerParameters (array ('REQUEST_TIME ' => 1337882841 ));
40
46
41
- $ crawler = $ client ->request ('GET ' , '/ ' );
47
+ $ crawler = $ this -> client ->request ('GET ' , '/ ' );
42
48
43
49
$ form = $ crawler ->filter ('form ' )->form ();
44
50
$ form ['content ' ] = 'foobar ' ;
45
51
46
- $ crawler = $ client ->submit ($ form );
47
- $ crawler = $ client ->followRedirect ();
52
+ $ crawler = $ this -> client ->submit ($ form );
53
+ $ crawler = $ this -> client ->followRedirect ();
48
54
49
- $ response = $ client ->getResponse ();
55
+ $ response = $ this -> client ->getResponse ();
50
56
$ this ->assertTrue ($ response ->isOk ());
51
57
$ this ->assertContains ('foobar ' , $ response ->getContent ());
52
58
}
53
59
54
60
/** @test */
55
61
public function createPasteWithoutContentShouldFail ()
56
62
{
57
- $ client = $ this ->createClient ();
58
-
59
- $ crawler = $ client ->request ('GET ' , '/ ' );
63
+ $ crawler = $ this ->client ->request ('GET ' , '/ ' );
60
64
61
65
$ form = $ crawler ->filter ('form ' )->form ();
62
66
$ form ['content ' ] = '' ;
63
67
64
- $ client ->submit ($ form );
68
+ $ this -> client ->submit ($ form );
65
69
66
- $ response = $ client ->getResponse ();
70
+ $ response = $ this -> client ->getResponse ();
67
71
$ this ->assertSame (400 , $ response ->getStatusCode ());
68
72
}
69
73
70
74
public function testViewPaste ()
71
75
{
72
- $ client = $ this ->createClient ();
73
-
74
- $ client ->request ('GET ' , '/abcdef12 ' );
75
- $ response = $ client ->getResponse ();
76
+ $ this ->client ->request ('GET ' , '/abcdef12 ' );
77
+ $ response = $ this ->client ->getResponse ();
76
78
$ this ->assertTrue ($ response ->isOk ());
77
79
$ this ->assertContains ('foobar ' , $ response ->getContent ());
78
80
}
79
81
80
82
public function testCreatePasteWithParent ()
81
83
{
82
- $ client = $ this ->createClient ();
83
- $ crawler = $ client ->request ('GET ' , '/abcdef12 ' );
84
+ $ crawler = $ this ->client ->request ('GET ' , '/abcdef12 ' );
84
85
85
86
$ link = $ crawler ->selectLink ('copy ' )->link ();
86
- $ crawler = $ client ->click ($ link );
87
+ $ crawler = $ this -> client ->click ($ link );
87
88
88
89
$ form = $ crawler ->filter ('form ' )->form ();
89
90
$ this ->assertSame ('foobar ' , $ form ['content ' ]->getValue ());
@@ -95,17 +96,13 @@ public function testCreatePasteWithParent()
95
96
*/
96
97
public function testViewPasteWithInvalidId ()
97
98
{
98
- $ client = $ this ->createClient ();
99
-
100
- $ client ->request ('GET ' , '/00000000 ' );
99
+ $ this ->client ->request ('GET ' , '/00000000 ' );
101
100
}
102
101
103
102
public function testAbout ()
104
103
{
105
- $ client = $ this ->createClient ();
106
-
107
- $ client ->request ('GET ' , '/about ' );
108
- $ response = $ client ->getResponse ();
104
+ $ this ->client ->request ('GET ' , '/about ' );
105
+ $ response = $ this ->client ->getResponse ();
109
106
$ this ->assertTrue ($ response ->isOk (), '/about should return ok response ' );
110
107
$ this ->assertContains ('trashbin ' , $ response ->getContent ());
111
108
$ this ->assertContains ('github ' , $ response ->getContent ());
@@ -116,10 +113,10 @@ public function testErrorHandler()
116
113
{
117
114
$ this ->app ['debug ' ] = false ;
118
115
119
- $ client = $ this ->createClient ();
116
+ $ this -> client = $ this ->createClient ();
120
117
121
- $ client ->request ('GET ' , '/non-existent ' );
122
- $ response = $ client ->getResponse ();
118
+ $ this -> client ->request ('GET ' , '/non-existent ' );
119
+ $ response = $ this -> client ->getResponse ();
123
120
$ this ->assertSame (404 , $ response ->getStatusCode ());
124
121
}
125
122
}
0 commit comments