This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
294 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<div class="json"><?php | ||
|
||
$rawpost = file_get_contents('php://input'); | ||
$rawquery = filter_input(INPUT_SERVER, 'QUERY_STRING'); | ||
$rawcookie = filter_input(INPUT_SERVER, 'HTTP_COOKIE'); | ||
|
||
echo json_encode(compact('_GET', '_POST', '_COOKIE', 'rawpost', 'rawquery', 'rawcookie')); | ||
|
||
?></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<form method="post" action="" enctype="multipart/form-data"> | ||
<input type="file" name="file[x][y]"> | ||
<input type="submit" value="submit"> | ||
</form> | ||
<?php if (isset($_FILES['file']['error']['x']['y']) && is_int($_FILES['file']['error']['x']['y'])): ?> | ||
<?php if ($_FILES['file']['error']['x']['y'] === UPLOAD_ERR_OK): ?> | ||
<div id="success">SUCCESS</div> | ||
<?php else: ?> | ||
<div id="error">ERROR</div> | ||
<?php endif; ?> | ||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<form method="post" action="" enctype="multipart/form-data"> | ||
<input type="file" name="file[tmp_name][y]"> | ||
<input type="submit" value="submit"> | ||
</form> | ||
<?php if (isset($_FILES['file']['error']['tmp_name']['y']) && is_int($_FILES['file']['error']['tmp_name']['y'])): ?> | ||
<?php if ($_FILES['file']['error']['tmp_name']['y'] === UPLOAD_ERR_OK): ?> | ||
<div id="success">SUCCESS</div> | ||
<?php else: ?> | ||
<div id="error">ERROR</div> | ||
<?php endif; ?> | ||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use mpyw\Coutte\Client; | ||
use mpyw\Co\Co; | ||
use mpyw\Co\CoInterface; | ||
use mpyw\Privator\Proxy; | ||
use mpyw\Privator\ProxyException; | ||
|
||
/** | ||
* @requires PHP 7.0 | ||
*/ | ||
class ClientConfigTest extends \Codeception\TestCase\Test { | ||
|
||
use \Codeception\Specify; | ||
|
||
public function testCurlOptionsConfig() | ||
{ | ||
$client = new Client($expected = [ | ||
CURLOPT_SSL_VERIFYPEER => false, | ||
CURLOPT_SSL_VERIFYHOST => false, | ||
]); | ||
$actual = array_intersect_key($client->getCurlOptions(), $expected); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
use mpyw\Coutte\Client; | ||
use mpyw\Co\Co; | ||
use mpyw\Co\CoInterface; | ||
use mpyw\Co\CURLException; | ||
use mpyw\Privator\Proxy; | ||
use mpyw\Privator\ProxyException; | ||
|
||
/** | ||
* @requires PHP 7.0 | ||
*/ | ||
class ClientGetAndPostTest extends \Codeception\TestCase\Test { | ||
|
||
use \Codeception\Specify; | ||
|
||
public function getClient() | ||
{ | ||
return new Client([ | ||
CURLOPT_SSL_VERIFYPEER => false, | ||
CURLOPT_SSL_VERIFYHOST => false, | ||
]); | ||
} | ||
|
||
public function testInvalid() | ||
{ | ||
$this->setExpectedException(CURLException::class); | ||
$client = $this->getClient(); | ||
$client->request('GET', 'invalid'); | ||
} | ||
|
||
public function testNormalPost() | ||
{ | ||
$client = $this->getClient(); | ||
$expected = ['a' => 'b']; | ||
$crawler = $client->request('POST', 'http://localhost:8080/json.php', $expected); | ||
$json = json_decode($crawler->filter('.json')->text(), true); | ||
$this->assertEquals($expected, $json['_POST']); | ||
} | ||
|
||
public function testRawPost() | ||
{ | ||
$client = $this->getClient(); | ||
$expected = 'abcde'; | ||
$crawler = $client->request('POST', 'http://localhost:8080/json.php', [], [], [], $expected); | ||
$json = json_decode($crawler->filter('.json')->text(), true); | ||
$this->assertEquals([], $json['_POST']); | ||
$this->assertEquals($expected, $json['rawpost']); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
use mpyw\Coutte\Client; | ||
use mpyw\Co\Co; | ||
use mpyw\Co\CoInterface; | ||
use mpyw\Privator\Proxy; | ||
use mpyw\Privator\ProxyException; | ||
|
||
/** | ||
* @requires PHP 7.0 | ||
*/ | ||
class ClientPayloadTest extends \Codeception\TestCase\Test { | ||
|
||
use \Codeception\Specify; | ||
|
||
public function getClient() | ||
{ | ||
return new Client([ | ||
CURLOPT_SSL_VERIFYPEER => false, | ||
CURLOPT_SSL_VERIFYHOST => false, | ||
]); | ||
} | ||
|
||
public function testPayloadHttp() | ||
{ | ||
$client = $this->getClient(); | ||
$client->request('GET', 'http://localhost:8080/hello.php'); | ||
$this->assertEquals('Hello', $client->getResponse()->getContent()); | ||
} | ||
|
||
public function testPayloadHttps() | ||
{ | ||
$client = $this->getClient(); | ||
$client->request('GET', 'https://localhost:8081/hello.php'); | ||
$this->assertEquals('Hello', $client->getResponse()->getContent()); | ||
} | ||
|
||
public function testAsyncPayloadHttp() | ||
{ | ||
Co::wait(function () { | ||
$client = $this->getClient(); | ||
yield $client->requestAsync('GET', 'http://localhost:8080/hello.php'); | ||
$this->assertEquals('Hello', $client->getResponse()->getContent()); | ||
}); | ||
} | ||
|
||
public function testAsyncPayloadHttps() | ||
{ | ||
Co::wait(function () { | ||
$client = $this->getClient(); | ||
yield $client->requestAsync('GET', 'https://localhost:8081/hello.php'); | ||
$this->assertEquals('Hello', $client->getResponse()->getContent()); | ||
}); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
use mpyw\Coutte\Client; | ||
use mpyw\Co\Co; | ||
use mpyw\Co\CoInterface; | ||
use mpyw\Privator\Proxy; | ||
use mpyw\Privator\ProxyException; | ||
|
||
/** | ||
* @requires PHP 7.0 | ||
*/ | ||
class ClientUploadTest extends \Codeception\TestCase\Test { | ||
|
||
use \Codeception\Specify; | ||
|
||
public function getClient() | ||
{ | ||
return new Client([ | ||
CURLOPT_SSL_VERIFYPEER => false, | ||
CURLOPT_SSL_VERIFYHOST => false, | ||
]); | ||
} | ||
|
||
public function testUpload01() | ||
{ | ||
$client = $this->getClient(); | ||
$crawler = $client->request('GET', 'http://localhost:8080/upload_form01.php'); | ||
$form = $crawler->filter('form')->form([ | ||
'file[x][y]' => __FILE__, | ||
]); | ||
$crawler = $client->submit($form); | ||
$this->assertEquals('SUCCESS', $crawler->filter('#success')->text()); | ||
} | ||
|
||
public function testUpload02() | ||
{ | ||
$client = $this->getClient(); | ||
$crawler = $client->request('GET', 'http://localhost:8080/upload_form02.php'); | ||
$form = $crawler->filter('form')->form([ | ||
'file[tmp_name][y]' => __FILE__, | ||
]); | ||
$crawler = $client->submit($form); | ||
$this->assertEquals('SUCCESS', $crawler->filter('#success')->text()); | ||
} | ||
|
||
public function testUpload03() | ||
{ | ||
$this->setExpectedException( | ||
PHPUnit_Framework_Exception::class, | ||
'is_readable() expects parameter 1 to be a valid path, object given' | ||
); | ||
$client = $this->getClient(); | ||
$crawler = $client->request('GET', 'http://localhost:8080/upload_form01.php'); | ||
$form = $crawler->filter('form')->form([ | ||
'file[x][y]' => new CURLFile(__FILE__), | ||
]); | ||
} | ||
|
||
public function testUpload04() | ||
{ | ||
$client = $this->getClient(); | ||
$crawler = $client->request( | ||
'POST', | ||
'http://localhost:8080/upload_form01.php', | ||
[], | ||
[ | ||
'file[x]' => [ | ||
'y' => new CURLFile(__FILE__) | ||
] | ||
] | ||
); | ||
$this->assertEquals('SUCCESS', $crawler->filter('#success')->text()); | ||
} | ||
|
||
public function testUpload05() | ||
{ | ||
$client = $this->getClient(); | ||
$crawler = $client->request( | ||
'POST', | ||
'http://localhost:8080/upload_form01.php', | ||
[], | ||
[ | ||
'file[x]' => [ | ||
'y' => __FILE__, | ||
] | ||
] | ||
); | ||
$this->assertEquals('SUCCESS', $crawler->filter('#success')->text()); | ||
} | ||
|
||
public function testUpload06() | ||
{ | ||
$client = $this->getClient(); | ||
$crawler = $client->request( | ||
'POST', | ||
'http://localhost:8080/upload_form01.php', | ||
[ | ||
[], | ||
'file[x]' => [ | ||
'y' => new CURLFile(__FILE__) | ||
] | ||
] | ||
); | ||
$this->assertEquals('SUCCESS', $crawler->filter('#success')->text()); | ||
} | ||
} |