Skip to content

Commit d08b3e5

Browse files
committed
Merge pull request #19 from adbre/replace-__call-with-explicit-method-declarations
Replace __call with explicit method declarations
2 parents 16ed260 + e2674fc commit d08b3e5

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

src/There4/Slim/Test/WebTestClient.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,46 @@ class WebTestClient
1010
public $request;
1111
public $response;
1212

13-
// We support these methods for testing. These are available via
14-
// `this->get()` and `$this->post()`. This is accomplished with the
15-
// `__call()` magic method below.
16-
public $testingMethods = array('get', 'post', 'patch', 'put', 'delete', 'head');
17-
1813
public function __construct(Slim\Slim $slim)
1914
{
2015
$this->app = $slim;
2116
}
2217

23-
// Implement our `get`, `post`, and other http operations
2418
public function __call($method, $arguments)
2519
{
26-
if (in_array($method, $this->testingMethods)) {
27-
list($path, $data, $headers) = array_pad($arguments, 3, array());
28-
return $this->request($method, $path, $data, $headers);
29-
}
3020
throw new \BadMethodCallException(strtoupper($method) . ' is not supported');
3121
}
3222

23+
public function get($path, $data = array(), $optionalHeaders = array())
24+
{
25+
$this->request('get', $path, $data, $optionalHeaders);
26+
}
27+
28+
public function post($path, $data = array(), $optionalHeaders = array())
29+
{
30+
$this->request('post', $path, $data, $optionalHeaders);
31+
}
32+
33+
public function patch($path, $data = array(), $optionalHeaders = array())
34+
{
35+
$this->request('patch', $path, $data, $optionalHeaders);
36+
}
37+
38+
public function put($path, $data = array(), $optionalHeaders = array())
39+
{
40+
$this->request('put', $path, $data, $optionalHeaders);
41+
}
42+
43+
public function delete($path, $data = array(), $optionalHeaders = array())
44+
{
45+
$this->request('delete', $path, $data, $optionalHeaders);
46+
}
47+
48+
public function head($path, $data = array(), $optionalHeaders = array())
49+
{
50+
$this->request('head', $path, $data, $optionalHeaders);
51+
}
52+
3353
// Abstract way to make a request to SlimPHP, this allows us to mock the
3454
// slim environment
3555
private function request($method, $path, $data = array(), $optionalHeaders = array())

0 commit comments

Comments
 (0)