Conditions | 1 |
Paths | 1 |
Total Lines | 100 |
Code Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | public function testHandlePreflightRequest() |
||
49 | { |
||
50 | $this->service = new CorsService([ |
||
51 | 'allow_origins' => ['http://foo.com'], |
||
52 | 'allow_methods' => ['post'], |
||
53 | 'allow_headers' => ['accept', 'authorization', 'content-type'], |
||
54 | ]); |
||
55 | |||
56 | $this->request = new Request; |
||
57 | |||
58 | $this->specify('200 response when origin, method and headers are allowed', function () { |
||
59 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
60 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
61 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
62 | |||
63 | $response = $this->service->handlePreflightRequest($this->request); |
||
64 | |||
65 | verify($response->getStatusCode())->equals(200); |
||
66 | }); |
||
67 | |||
68 | $this->service = new CorsService([ |
||
69 | 'allow_origins' => ['http://foo.com'], |
||
70 | 'allow_methods' => ['post'], |
||
71 | 'allow_headers' => ['accept', 'authorization', 'content-type'], |
||
72 | ]); |
||
73 | |||
74 | $this->request = new Request; |
||
75 | |||
76 | $this->specify('response headers are set', function () { |
||
77 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
78 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
79 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
80 | |||
81 | $response = $this->service->handlePreflightRequest($this->request); |
||
82 | |||
83 | verify($response->headers->get('Access-Control-Allow-Origin'))->equals('http://foo.com'); |
||
84 | verify($response->headers->get('Access-Control-Allow-Methods'))->equals('POST'); |
||
85 | verify($response->headers->get('Access-Control-Allow-Headers'))->equals('accept, authorization, content-type'); |
||
86 | verify($response->headers->has('Access-Control-Allow-Credentials'))->false(); |
||
87 | verify($response->headers->has('Access-Control-Max-Age'))->false(); |
||
88 | }); |
||
89 | |||
90 | $this->service = new CorsService([ |
||
91 | 'allow_origins' => ['http://foo.com'], |
||
92 | 'allow_methods' => ['post'], |
||
93 | 'allow_headers' => ['accept', 'authorization', 'content-type'], |
||
94 | ]); |
||
95 | |||
96 | $this->request = new Request; |
||
97 | |||
98 | $this->specify('regression test for issue #31', function () { |
||
99 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
100 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
101 | $this->request->headers->set('Access-Control-Request-Headers', 'accept,authorization, content-type'); |
||
102 | |||
103 | $response = $this->service->handlePreflightRequest($this->request); |
||
104 | |||
105 | verify($response->headers->get('Access-Control-Allow-Origin'))->equals('http://foo.com'); |
||
106 | verify($response->headers->get('Access-Control-Allow-Methods'))->equals('POST'); |
||
107 | verify($response->headers->get('Access-Control-Allow-Headers'))->equals('accept, authorization, content-type'); |
||
108 | verify($response->headers->has('Access-Control-Allow-Credentials'))->false(); |
||
109 | verify($response->headers->has('Access-Control-Max-Age'))->false(); |
||
110 | }); |
||
111 | |||
112 | $this->service = new CorsService([ |
||
113 | 'allow_origins' => ['*'], |
||
114 | 'allow_methods' => ['*'], |
||
115 | 'allow_headers' => ['*'], |
||
116 | 'allow_credentials' => true, |
||
117 | ]); |
||
118 | |||
119 | $this->request = new Request; |
||
120 | |||
121 | $this->specify('response credentials header is set', function () { |
||
122 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
123 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
124 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
125 | |||
126 | $response = $this->service->handlePreflightRequest($this->request); |
||
127 | |||
128 | verify($response->headers->get('Access-Control-Allow-Credentials'))->equals('true'); |
||
129 | }); |
||
130 | |||
131 | $this->service = new CorsService([ |
||
132 | 'allow_origins' => ['*'], |
||
133 | 'allow_methods' => ['*'], |
||
134 | 'allow_headers' => ['*'], |
||
135 | 'max_age' => 3600, |
||
136 | ]); |
||
137 | |||
138 | $this->request = new Request; |
||
139 | |||
140 | $this->specify('response max-age header is set', function () { |
||
141 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
142 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
143 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
144 | |||
145 | $response = $this->service->handlePreflightRequest($this->request); |
||
146 | |||
147 | verify($response->headers->get('Access-Control-Max-Age'))->equals(3600); |
||
148 | }); |
||
318 |