Conditions | 1 |
Paths | 1 |
Total Lines | 100 |
Code Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
46 | public function testHandlePreflightRequest() |
||
47 | { |
||
48 | $this->service = new CorsService([ |
||
49 | 'allow_origins' => ['http://foo.com'], |
||
50 | 'allow_methods' => ['post'], |
||
51 | 'allow_headers' => ['accept', 'authorization', 'content-type'], |
||
52 | ]); |
||
53 | |||
54 | $this->request = new Request; |
||
55 | |||
56 | $this->specify('200 response when origin, method and headers are allowed', function () { |
||
57 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
58 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
59 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
60 | |||
61 | $response = $this->service->handlePreflightRequest($this->request); |
||
62 | |||
63 | verify($response->getStatusCode())->equals(200); |
||
64 | }); |
||
65 | |||
66 | $this->service = new CorsService([ |
||
67 | 'allow_origins' => ['http://foo.com'], |
||
68 | 'allow_methods' => ['post'], |
||
69 | 'allow_headers' => ['accept', 'authorization', 'content-type'], |
||
70 | ]); |
||
71 | |||
72 | $this->request = new Request; |
||
73 | |||
74 | $this->specify('response headers are set', function () { |
||
75 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
76 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
77 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
78 | |||
79 | $response = $this->service->handlePreflightRequest($this->request); |
||
80 | |||
81 | verify($response->headers->get('Access-Control-Allow-Origin'))->equals('http://foo.com'); |
||
82 | verify($response->headers->get('Access-Control-Allow-Methods'))->equals('POST'); |
||
83 | verify($response->headers->get('Access-Control-Allow-Headers'))->equals('accept, authorization, content-type'); |
||
84 | verify($response->headers->has('Access-Control-Allow-Credentials'))->false(); |
||
85 | verify($response->headers->has('Access-Control-Max-Age'))->false(); |
||
86 | }); |
||
87 | |||
88 | $this->service = new CorsService([ |
||
89 | 'allow_origins' => ['http://foo.com'], |
||
90 | 'allow_methods' => ['post'], |
||
91 | 'allow_headers' => ['accept', 'authorization', 'content-type'], |
||
92 | ]); |
||
93 | |||
94 | $this->request = new Request; |
||
95 | |||
96 | $this->specify('regression test for issue #31', function () { |
||
97 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
98 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
99 | $this->request->headers->set('Access-Control-Request-Headers', 'accept,authorization, content-type'); |
||
100 | |||
101 | $response = $this->service->handlePreflightRequest($this->request); |
||
102 | |||
103 | verify($response->headers->get('Access-Control-Allow-Origin'))->equals('http://foo.com'); |
||
104 | verify($response->headers->get('Access-Control-Allow-Methods'))->equals('POST'); |
||
105 | verify($response->headers->get('Access-Control-Allow-Headers'))->equals('accept, authorization, content-type'); |
||
106 | verify($response->headers->has('Access-Control-Allow-Credentials'))->false(); |
||
107 | verify($response->headers->has('Access-Control-Max-Age'))->false(); |
||
108 | }); |
||
109 | |||
110 | $this->service = new CorsService([ |
||
111 | 'allow_origins' => ['*'], |
||
112 | 'allow_methods' => ['*'], |
||
113 | 'allow_headers' => ['*'], |
||
114 | 'allow_credentials' => true, |
||
115 | ]); |
||
116 | |||
117 | $this->request = new Request; |
||
118 | |||
119 | $this->specify('response credentials header is set', function () { |
||
120 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
121 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
122 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
123 | |||
124 | $response = $this->service->handlePreflightRequest($this->request); |
||
125 | |||
126 | verify($response->headers->get('Access-Control-Allow-Credentials'))->equals('true'); |
||
127 | }); |
||
128 | |||
129 | $this->service = new CorsService([ |
||
130 | 'allow_origins' => ['*'], |
||
131 | 'allow_methods' => ['*'], |
||
132 | 'allow_headers' => ['*'], |
||
133 | 'max_age' => 3600, |
||
134 | ]); |
||
135 | |||
136 | $this->request = new Request; |
||
137 | |||
138 | $this->specify('response max-age header is set', function () { |
||
139 | $this->request->headers->set('Origin', 'http://foo.com'); |
||
140 | $this->request->headers->set('Access-Control-Request-Method', 'POST'); |
||
141 | $this->request->headers->set('Access-Control-Request-Headers', 'accept, authorization, content-type'); |
||
142 | |||
143 | $response = $this->service->handlePreflightRequest($this->request); |
||
144 | |||
145 | verify($response->headers->get('Access-Control-Max-Age'))->equals(3600); |
||
146 | }); |
||
316 |