Commit 385d80db authored by shajiaiming's avatar shajiaiming

引用curl

parent dc60edee
......@@ -8,7 +8,7 @@
namespace common\service\exchange;
use common\helpers\Curl;
use linslin\yii2\curl\Curl;
use Yii;
class Bitfinex extends Exchange implements ExchangeInterface
......@@ -32,7 +32,8 @@ class Bitfinex extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$result = $this->ch->get('https://api.bitfinex.com/v1/symbols', false);
$curl = new Curl();
$result = $curl->get('https://api.bitfinex.com/v1/symbols');
if ($result) {
foreach ($result as $item) {
$this->redis->sadd($this->supported_symbol, 't' . strtoupper($item));
......@@ -44,7 +45,8 @@ class Bitfinex extends Exchange implements ExchangeInterface
{
$symbols = $this->redis->smembers($this->supported_symbol);
$query = '?symbols=' . implode(',', $symbols);
$res = $this->ch->get('https://api.bitfinex.com/v2/tickers' . $query, false);
$curl = new Curl();
$res = $curl->get('https://api.bitfinex.com/v2/tickers' . $query);
if(false == $res){
return;
}
......
......@@ -9,7 +9,7 @@
namespace common\service\exchange;
use Yii;
use linslin\yii2\curl\Curl;
class Bittrex extends Exchange implements ExchangeInterface
{
......@@ -24,7 +24,8 @@ class Bittrex extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$api = 'https://bittrex.com/api/v1.1/public/getmarkets';
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api);
if ($rev && $rev['success']) {
$lists = $rev['result'];
foreach ($lists as $item) {
......@@ -36,7 +37,8 @@ class Bittrex extends Exchange implements ExchangeInterface
public function setQuotation()
{
$api = 'https://bittrex.com/api/v1.1/public/getmarketsummaries';
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api, false);
if ($rev && $rev['success']) {
$lists = $rev['result'];
foreach ($lists as $item) {
......
......@@ -8,6 +8,8 @@
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Bty extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_bty';
......@@ -44,8 +46,9 @@ class Bty extends Exchange implements ExchangeInterface
public function setQuotation()
{
$platforms = ['HKJB', 'BB360'];
$curl = new Curl();
foreach($platforms as $platform) {
$content = $this->ch->get($this->base_url . $platform, false);
$content = $curl->get($this->base_url . $platform);
if (is_array($content) && isset($content['code']) && $content['code'] == 200) {
$data = $content['data']['USDT'];
foreach ($data as $item) {
......
......@@ -8,7 +8,7 @@
namespace common\service\exchange;
use common\helpers\Curl;
use linslin\yii2\curl\Curl;
use Yii;
class Hadax extends HuoBi
......@@ -19,8 +19,9 @@ class Hadax extends HuoBi
public function setSupportedSymbol()
{
$curl = new Curl();
$api = $this->base_url . '/v1/hadax/common/symbols';
$res = $this->ch->get($api, false);//json
$res = $curl->get($api);//json
if ($res && $res['status'] == 'ok') {
$data = $res['data'];
foreach ($data as $item) {
......
......@@ -9,7 +9,7 @@
namespace common\service\exchange;
use Yii;
use common\helpers\Curl;
use linslin\yii2\curl\Curl;
class HuoBi extends Exchange implements ExchangeInterface
{
......@@ -25,7 +25,8 @@ class HuoBi extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$api = $this->base_url . '/v1/common/symbols';
$res = $this->ch->get($api, false);//json
$curl = new Curl();
$res = $curl->get($api);//json
if ($res && $res['status'] == 'ok') {
$data = $res['data'];
foreach ($data as $item) {
......@@ -38,7 +39,8 @@ class HuoBi extends Exchange implements ExchangeInterface
public function setQuotation()
{
$api = $this->base_url . '/market/tickers';
$res = $this->ch->get($api, false);
$curl = new Curl();
$res = $curl->get($api, false);
if ($res && $res['status'] == 'ok') {
$datas = $res['data'];
foreach ($datas as $item) {
......
......@@ -8,6 +8,8 @@
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Token7 extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_token7';
......@@ -52,36 +54,8 @@ class Token7 extends Exchange implements ExchangeInterface
*/
public function setQuotation()
{
$content = $this->ch->get($this->base_url, false);
$content = [
"date" => "2019-03-27 14:28:08",
"ticker" => [
[
"symbol"=>"GM_HA",
"vol"=>"759301.65",
"high"=>"2.608",
"last"=>"2.607",
"low"=>"2.607",
"sell"=>"2.615",
"buy"=>"2.613",
"yesterdayPrice"=>"2.609",
"change"=>"-0.077",
"lastExchangPrice"=>"2.608"
],
[
"symbol"=>"BSTC_HA",
"vol"=>"321550.59",
"high"=>"0.029",
"last"=>"0.029",
"low"=>"0.029",
"sell"=>"0.029",
"buy"=>"0.028",
"yesterdayPrice"=>"0.027",
"change"=>"7.407",
"lastExchangPrice"=>"0.029"]
]
];
$curl = new Curl();
$content = $curl->get($this->base_url);
if (is_array($content) && isset($content['date']) && isset($content['ticker'])) {
$data = $content['ticker'];
foreach ($data as $item) {
......
......@@ -8,6 +8,8 @@
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
/**
* Class Zb
* api document:https://www.zb.com/i/developer/restApi#market
......@@ -26,7 +28,8 @@ class Zb extends Exchange implements ExchangeInterface
public function setSupportedSymbol()
{
$api = "http://api.zb.com/data/v1/markets";
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api);
if ($rev) {
$keys = array_keys($rev);
foreach ($keys as $key) {
......@@ -38,7 +41,8 @@ class Zb extends Exchange implements ExchangeInterface
public function setQuotation()
{
$api = 'http://api.zb.com/data/v1/allTicker';
$rev = $this->ch->get($api, false);
$curl = new Curl();
$rev = $curl->get($api);
if ($rev) {
foreach ($rev as $key => $item) {
$this->redis->hmset($this->quotation_prefix . $key, 'low', $item['low'], 'high', $item['high'], 'last',
......
......@@ -20,7 +20,8 @@
"kartik-v/yii2-date-range": "*",
"kartik-v/yii2-widget-fileinput": "*",
"yiisoft/yii2-redis": "~2.0.0",
"yiisoft/yii2-queue": "~2.0"
"yiisoft/yii2-queue": "~2.0",
"linslin/yii2-curl": "*"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
......
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "51ae166c71c3be07b2d84ab426a18ebe",
"content-hash": "4c1d96df90fb4ff9a976d6268b520242",
"packages": [
{
"name": "bower-asset/bootstrap",
......@@ -17,8 +17,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twbs/bootstrap/zipball/0b9c4a4007c44201dce9a6cc1a38407005c26c86",
"reference": "0b9c4a4007c44201dce9a6cc1a38407005c26c86",
"shasum": null
"reference": "0b9c4a4007c44201dce9a6cc1a38407005c26c86"
},
"require": {
"bower-asset/jquery": ">=1.9.1,<4.0"
......@@ -39,8 +38,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/14873e5775964275d13621cbe2b52e4448af3707",
"reference": "14873e5775964275d13621cbe2b52e4448af3707",
"shasum": null
"reference": "14873e5775964275d13621cbe2b52e4448af3707"
},
"require": {
"bower-asset/jquery": ">=1.7"
......@@ -61,8 +59,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jquery/jquery-dist/zipball/77d2a51d0520d2ee44173afdf4e40a9201f5964e",
"reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e",
"shasum": null
"reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e"
},
"type": "bower-asset",
"license": [
......@@ -80,8 +77,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3",
"reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3",
"shasum": null
"reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3"
},
"type": "bower-asset"
},
......@@ -96,8 +92,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/aef7b953107264f00234902a3880eb50dafc48be",
"reference": "aef7b953107264f00234902a3880eb50dafc48be",
"shasum": null
"reference": "aef7b953107264f00234902a3880eb50dafc48be"
},
"require": {
"bower-asset/jquery": ">=1.8"
......@@ -1707,6 +1702,58 @@
"time": "2014-11-09T19:54:17+00:00"
},
{
"name": "linslin/yii2-curl",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/linslin/Yii2-Curl.git",
"reference": "734c40b520729c79af2937283864f8c999e86879"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/linslin/Yii2-Curl/zipball/734c40b520729c79af2937283864f8c999e86879",
"reference": "734c40b520729c79af2937283864f8c999e86879",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"yiisoft/yii2": "*"
},
"require-dev": {
"codeception/base": "^2.2.3",
"codeception/specify": "~0.4.3",
"codeception/verify": "~0.3.1",
"codeclimate/php-test-reporter": "dev-master",
"guzzlehttp/guzzle": ">=4.1.4 <7.0",
"mcustiel/phiremock-codeception-extension": "1.2.4"
},
"type": "yii2-extension",
"autoload": {
"psr-4": {
"linslin\\yii2\\curl\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nils Gajsek",
"email": "info@linslin.org"
}
],
"description": "Easy and nice cURL extension with RESTful support for Yii2",
"keywords": [
" curl",
"extension",
"restful",
"yii2"
],
"time": "2019-02-25T10:56:34+00:00"
},
{
"name": "swiftmailer/swiftmailer",
"version": "v6.1.2",
"source": {
......@@ -2225,7 +2272,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/Behat/Gherkin/74ac03d52c5e23ad8abd5c5cce4ab0e8dc1b530a.zip",
"url": "https://api.github.com/repos/Behat/Gherkin/zipball/74ac03d52c5e23ad8abd5c5cce4ab0e8dc1b530a",
"reference": "74ac03d52c5e23ad8abd5c5cce4ab0e8dc1b530a",
"shasum": ""
},
......@@ -2285,8 +2332,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twitter/typeahead.js/zipball/588440f66559714280628a4f9799f0c4eb880a4a",
"reference": "588440f66559714280628a4f9799f0c4eb880a4a",
"shasum": null
"reference": "588440f66559714280628a4f9799f0c4eb880a4a"
},
"require": {
"bower-asset/jquery": ">=1.7"
......@@ -2392,7 +2438,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/Codeception/phpunit-wrapper/f18ed631f1eddbb603d72219f577d223b23a1f89.zip",
"url": "https://api.github.com/repos/Codeception/phpunit-wrapper/zipball/f18ed631f1eddbb603d72219f577d223b23a1f89",
"reference": "f18ed631f1eddbb603d72219f577d223b23a1f89",
"shasum": ""
},
......@@ -2435,7 +2481,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/Codeception/Stub/b2eff325d8ff0b824ff659048be7be4e5767d7d0.zip",
"url": "https://api.github.com/repos/Codeception/Stub/zipball/b2eff325d8ff0b824ff659048be7be4e5767d7d0",
"reference": "b2eff325d8ff0b824ff659048be7be4e5767d7d0",
"shasum": ""
},
......@@ -2673,7 +2719,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/myclabs/DeepCopy/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8.zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8",
"reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8",
"shasum": ""
},
......@@ -2877,7 +2923,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/phpDocumentor/ReflectionDocBlock/94fd0001232e47129dd3504189fa1c7225010d08.zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08",
"reference": "94fd0001232e47129dd3504189fa1c7225010d08",
"shasum": ""
},
......@@ -3013,7 +3059,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/phpspec/prophecy/33a7e3c4fda54e912ff6338c48823bd5c0f0b712.zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
"reference": "33a7e3c4fda54e912ff6338c48823bd5c0f0b712",
"shasum": ""
},
......@@ -3076,7 +3122,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/sebastianbergmann/php-code-coverage/4cab20a326d14de7575a8e235c70d879b569a57a.zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4cab20a326d14de7575a8e235c70d879b569a57a",
"reference": "4cab20a326d14de7575a8e235c70d879b569a57a",
"shasum": ""
},
......@@ -3139,7 +3185,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/sebastianbergmann/php-file-iterator/730b01bc3e867237eaac355e06a36b85dd93a8b4.zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4",
"reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4",
"shasum": ""
},
......@@ -3227,7 +3273,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/sebastianbergmann/php-timer/8b8454ea6958c3dee38453d3bd571e023108c91f.zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b8454ea6958c3dee38453d3bd571e023108c91f",
"reference": "8b8454ea6958c3dee38453d3bd571e023108c91f",
"shasum": ""
},
......@@ -3276,7 +3322,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/sebastianbergmann/php-token-stream/21ad88bbba7c3d93530d93994e0a33cd45f02ace.zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/21ad88bbba7c3d93530d93994e0a33cd45f02ace",
"reference": "21ad88bbba7c3d93530d93994e0a33cd45f02ace",
"shasum": ""
},
......@@ -3325,7 +3371,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/sebastianbergmann/phpunit/ca64dba53b88aba6af32aebc6b388068db95c435.zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ca64dba53b88aba6af32aebc6b388068db95c435",
"reference": "ca64dba53b88aba6af32aebc6b388068db95c435",
"shasum": ""
},
......@@ -3405,7 +3451,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/sebastianbergmann/phpunit-mock-objects/f9756fd4f43f014cb2dca98deeaaa8ce5500a36e.zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/f9756fd4f43f014cb2dca98deeaaa8ce5500a36e",
"reference": "f9756fd4f43f014cb2dca98deeaaa8ce5500a36e",
"shasum": ""
},
......@@ -3620,7 +3666,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/sebastianbergmann/diff/366541b989927187c4ca70490a35615d3fef2dce.zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/366541b989927187c4ca70490a35615d3fef2dce",
"reference": "366541b989927187c4ca70490a35615d3fef2dce",
"shasum": ""
},
......@@ -4074,7 +4120,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/browser-kit/ff9ac5d5808a530b2e7f6abcf3a2412d4f9bcd62.zip",
"url": "https://api.github.com/repos/symfony/browser-kit/zipball/ff9ac5d5808a530b2e7f6abcf3a2412d4f9bcd62",
"reference": "ff9ac5d5808a530b2e7f6abcf3a2412d4f9bcd62",
"shasum": ""
},
......@@ -4131,7 +4177,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/console/70591cda56b4b47c55776ac78e157c4bb6c8b43f.zip",
"url": "https://api.github.com/repos/symfony/console/zipball/70591cda56b4b47c55776ac78e157c4bb6c8b43f",
"reference": "70591cda56b4b47c55776ac78e157c4bb6c8b43f",
"shasum": ""
},
......@@ -4199,7 +4245,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/css-selector/03ac71606ecb0b0ce792faa17d74cc32c2949ef4.zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/03ac71606ecb0b0ce792faa17d74cc32c2949ef4",
"reference": "03ac71606ecb0b0ce792faa17d74cc32c2949ef4",
"shasum": ""
},
......@@ -4252,7 +4298,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/dom-crawler/3350cacf151b48d903114ab8f7a4ccb23e07e10a.zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/3350cacf151b48d903114ab8f7a4ccb23e07e10a",
"reference": "3350cacf151b48d903114ab8f7a4ccb23e07e10a",
"shasum": ""
},
......@@ -4309,7 +4355,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/event-dispatcher/2391ed210a239868e7256eb6921b1bd83f3087b5.zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/2391ed210a239868e7256eb6921b1bd83f3087b5",
"reference": "2391ed210a239868e7256eb6921b1bd83f3087b5",
"shasum": ""
},
......@@ -4372,7 +4418,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/finder/84714b8417d19e4ba02ea78a41a975b3efaafddb.zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/84714b8417d19e4ba02ea78a41a975b3efaafddb",
"reference": "84714b8417d19e4ba02ea78a41a975b3efaafddb",
"shasum": ""
},
......@@ -4421,7 +4467,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/polyfill-ctype/7cc359f1b7b80fc25ed7796be7d96adc9b354bae.zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae",
"reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae",
"shasum": ""
},
......@@ -4476,7 +4522,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/polyfill-mbstring/3296adf6a6454a050679cde90f95350ad604b171.zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171",
"reference": "3296adf6a6454a050679cde90f95350ad604b171",
"shasum": ""
},
......@@ -4535,7 +4581,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/symfony/yaml/80e4bfa9685fc4a09acc4a857ec16974a9cd944e.zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/80e4bfa9685fc4a09acc4a857ec16974a9cd944e",
"reference": "80e4bfa9685fc4a09acc4a857ec16974a9cd944e",
"shasum": ""
},
......@@ -4634,7 +4680,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/webmozart/assert/0df1908962e7a3071564e857d86874dad1ef204a.zip",
"url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a",
"reference": "0df1908962e7a3071564e857d86874dad1ef204a",
"shasum": ""
},
......@@ -4684,7 +4730,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/yiisoft/yii2-debug/b37f414959c2fafefb332020b42037cd17c1cb7f.zip",
"url": "https://api.github.com/repos/yiisoft/yii2-debug/zipball/b37f414959c2fafefb332020b42037cd17c1cb7f",
"reference": "b37f414959c2fafefb332020b42037cd17c1cb7f",
"shasum": ""
},
......@@ -4731,7 +4777,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/yiisoft/yii2-faker/3df62b1dcb272a8413f9c6e532c9d73f325ccde1.zip",
"url": "https://api.github.com/repos/yiisoft/yii2-faker/zipball/3df62b1dcb272a8413f9c6e532c9d73f325ccde1",
"reference": "3df62b1dcb272a8413f9c6e532c9d73f325ccde1",
"shasum": ""
},
......@@ -4778,7 +4824,7 @@
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/yiisoft/yii2-gii/9ec1374d0844f448d2af29c707f77c9f8d1375c8.zip",
"url": "https://api.github.com/repos/yiisoft/yii2-gii/zipball/9ec1374d0844f448d2af29c707f77c9f8d1375c8",
"reference": "9ec1374d0844f448d2af29c707f77c9f8d1375c8",
"shasum": ""
},
......
......@@ -279,7 +279,7 @@ class ClassLoader
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
......@@ -377,7 +377,7 @@ class ClassLoader
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath.'\\';
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
......
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: Composer
Upstream-Contact: Jordi Boggiano <j.boggiano@seld.be>
Source: https://github.com/composer/composer
Files: *
Copyright: 2016, Nils Adermann <naderman@naderman.de>
2016, Jordi Boggiano <j.boggiano@seld.be>
License: Expat
Copyright (c) Nils Adermann, Jordi Boggiano
Files: src/Composer/Util/TlsHelper.php
Copyright: 2016, Nils Adermann <naderman@naderman.de>
2016, Jordi Boggiano <j.boggiano@seld.be>
2013, Evan Coury <me@evancoury.com>
License: Expat and BSD-2-Clause
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
License: BSD-2-Clause
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
.
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
License: Expat
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
......@@ -10,7 +10,7 @@ return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'180092cfc969a12e06f2132a203a3184' => $vendorDir . '/codeception/verify/src/Codeception/function.php',
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'180092cfc969a12e06f2132a203a3184' => $vendorDir . '/codeception/verify/src/Codeception/function.php',
);
......@@ -25,6 +25,7 @@ return array(
'yii\\bootstrap\\' => array($vendorDir . '/yiisoft/yii2-bootstrap/src'),
'yii\\' => array($vendorDir . '/yiisoft/yii2'),
'phpDocumentor\\Reflection\\' => array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/reflection-docblock/src', $vendorDir . '/phpdocumentor/type-resolver/src'),
'linslin\\yii2\\curl\\' => array($vendorDir . '/linslin/yii2-curl'),
'kartik\\widgets\\' => array($vendorDir . '/kartik-v/yii2-widgets'),
'kartik\\typeahead\\' => array($vendorDir . '/kartik-v/yii2-widget-typeahead'),
'kartik\\touchspin\\' => array($vendorDir . '/kartik-v/yii2-widget-touchspin'),
......
......@@ -11,9 +11,9 @@ class ComposerStaticInit33057934f3e7eaaa1ce2d53797277936
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php',
'180092cfc969a12e06f2132a203a3184' => __DIR__ . '/..' . '/codeception/verify/src/Codeception/function.php',
'6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php',
'180092cfc969a12e06f2132a203a3184' => __DIR__ . '/..' . '/codeception/verify/src/Codeception/function.php',
);
public static $prefixLengthsPsr4 = array (
......@@ -42,6 +42,10 @@ class ComposerStaticInit33057934f3e7eaaa1ce2d53797277936
array (
'phpDocumentor\\Reflection\\' => 25,
),
'l' =>
array (
'linslin\\yii2\\curl\\' => 18,
),
'k' =>
array (
'kartik\\widgets\\' => 15,
......@@ -203,6 +207,10 @@ class ComposerStaticInit33057934f3e7eaaa1ce2d53797277936
1 => __DIR__ . '/..' . '/phpdocumentor/reflection-docblock/src',
2 => __DIR__ . '/..' . '/phpdocumentor/type-resolver/src',
),
'linslin\\yii2\\curl\\' =>
array (
0 => __DIR__ . '/..' . '/linslin/yii2-curl',
),
'kartik\\widgets\\' =>
array (
0 => __DIR__ . '/..' . '/kartik-v/yii2-widgets',
......
......@@ -72,8 +72,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twbs/bootstrap/zipball/0b9c4a4007c44201dce9a6cc1a38407005c26c86",
"reference": "0b9c4a4007c44201dce9a6cc1a38407005c26c86",
"shasum": null
"reference": "0b9c4a4007c44201dce9a6cc1a38407005c26c86"
},
"require": {
"bower-asset/jquery": ">=1.9.1,<4.0"
......@@ -96,8 +95,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/RobinHerbots/Inputmask/zipball/14873e5775964275d13621cbe2b52e4448af3707",
"reference": "14873e5775964275d13621cbe2b52e4448af3707",
"shasum": null
"reference": "14873e5775964275d13621cbe2b52e4448af3707"
},
"require": {
"bower-asset/jquery": ">=1.7"
......@@ -120,8 +118,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jquery/jquery-dist/zipball/77d2a51d0520d2ee44173afdf4e40a9201f5964e",
"reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e",
"shasum": null
"reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e"
},
"type": "bower-asset",
"installation-source": "dist",
......@@ -141,8 +138,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bestiejs/punycode.js/zipball/38c8d3131a82567bfef18da09f7f4db68c84f8a3",
"reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3",
"shasum": null
"reference": "38c8d3131a82567bfef18da09f7f4db68c84f8a3"
},
"type": "bower-asset",
"installation-source": "dist"
......@@ -159,8 +155,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twitter/typeahead.js/zipball/588440f66559714280628a4f9799f0c4eb880a4a",
"reference": "588440f66559714280628a4f9799f0c4eb880a4a",
"shasum": null
"reference": "588440f66559714280628a4f9799f0c4eb880a4a"
},
"require": {
"bower-asset/jquery": ">=1.7"
......@@ -180,8 +175,7 @@
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/yiisoft/jquery-pjax/zipball/aef7b953107264f00234902a3880eb50dafc48be",
"reference": "aef7b953107264f00234902a3880eb50dafc48be",
"shasum": null
"reference": "aef7b953107264f00234902a3880eb50dafc48be"
},
"require": {
"bower-asset/jquery": ">=1.8"
......@@ -2238,6 +2232,60 @@
]
},
{
"name": "linslin/yii2-curl",
"version": "1.3.0",
"version_normalized": "1.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/linslin/Yii2-Curl.git",
"reference": "734c40b520729c79af2937283864f8c999e86879"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/linslin/Yii2-Curl/zipball/734c40b520729c79af2937283864f8c999e86879",
"reference": "734c40b520729c79af2937283864f8c999e86879",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"yiisoft/yii2": "*"
},
"require-dev": {
"codeception/base": "^2.2.3",
"codeception/specify": "~0.4.3",
"codeception/verify": "~0.3.1",
"codeclimate/php-test-reporter": "dev-master",
"guzzlehttp/guzzle": ">=4.1.4 <7.0",
"mcustiel/phiremock-codeception-extension": "1.2.4"
},
"time": "2019-02-25T10:56:34+00:00",
"type": "yii2-extension",
"installation-source": "dist",
"autoload": {
"psr-4": {
"linslin\\yii2\\curl\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nils Gajsek",
"email": "info@linslin.org"
}
],
"description": "Easy and nice cURL extension with RESTful support for Yii2",
"keywords": [
" curl",
"extension",
"restful",
"yii2"
]
},
{
"name": "myclabs/deep-copy",
"version": "1.8.1",
"version_normalized": "1.8.1.0",
......@@ -3053,7 +3101,8 @@
"keywords": [
"mock",
"xunit"
]
],
"abandoned": true
},
{
"name": "psr/http-message",
......
vendor/
\ No newline at end of file
language: php
php:
- '7.1.3'
branches:
only:
- master
- develop
install:
- composer install
script:
- vendor/bin/codecept run --coverage-xml ./../../build/logs/clover.xml
addons:
code_climate:
repo_token: 24b886eb6df6abd48cb812de2c20b9311d0444f30043bdf4d254116e5225ed84
after_success:
- vendor/bin/test-reporter
\ No newline at end of file
<?php
/**
* Yii2 cURL wrapper
* With RESTful support.
*
* @category Web-yii2
* @package yii2-curl
* @author Nils Gajsek <info@linslin.org>
* @copyright 2013-2017 Nils Gajsek <info@linslin.org>
* @license http://opensource.org/licenses/MIT MIT Public
* @version 1.3.0
* @link http://www.linslin.org
*
*/
namespace linslin\yii2\curl;
use Yii;
/**
* Class Curl
* @package linslin\yii2\curl
*/
class Curl
{
// ################################################ class vars // ################################################
/**
* @var string|boolean
* Holds response data right after sending a request.
*/
public $response = null;
/**
* @var null|integer
* Error code holder: https://curl.haxx.se/libcurl/c/libcurl-errors.html
*/
public $errorCode = null;
/**
* @var null|string
* Error text holder: http://php.net/manual/en/function.curl-strerror.php
*/
public $errorText = null;
/**
* @var integer HTTP-Status Code
* This value will hold HTTP-Status Code. False if request was not successful.
*/
public $responseCode = null;
/**
* @var string|null HTTP Response Charset
* (taken from Content-type header)
*/
public $responseCharset = null;
/**
* @var int HTTP Response Length
* (taken from Content-length header, or strlen() of downloaded content)
*/
public $responseLength = -1;
/**
* @var string|null HTTP Response Content Type
* (taken from Content-type header)
*/
public $responseType = null;
/**
* @var array|null HTTP Response headers
* Lists response header in an array if CURLOPT_HEADER is set to true.
*/
public $responseHeaders = null;
/**
* @var array HTTP-Status Code
* Custom options holder
*/
protected $_options = [];
/**
* @var array
* Hold array of get params to send with the request
*/
protected $_getParams = [];
/**
* @var array
* Hold array of post params to send with the request
*/
protected $_postParams = [];
/**
* @var resource|null
* Holds cURL-Handler
*/
public $curl = null;
/**
* @var string
* hold base URL
*/
protected $_baseUrl = '';
/**
* @var array default curl options
* Default curl options
*/
protected $_defaultOptions = [
CURLOPT_USERAGENT => 'Yii2-Curl-Agent',
CURLOPT_TIMEOUT => 30,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
];
// ############################################### class methods // ##############################################
/**
* Start performing GET-HTTP-Request
*
* @param string $url
* @param boolean $raw if response body contains JSON and should be decoded
*
* @return mixed
* @throws \Exception
*/
public function get($url, $raw = true)
{
$this->_baseUrl = $url;
return $this->_httpRequest('GET', $raw);
}
/**
* Start performing HEAD-HTTP-Request
*
* @param string $url
*
* @return mixed
* @throws \Exception
*/
public function head($url)
{
$this->_baseUrl = $url;
return $this->_httpRequest('HEAD');
}
/**
* Start performing POST-HTTP-Request
*
* @param string $url
* @param boolean $raw if response body contains JSON and should be decoded
*
* @return mixed
* @throws \Exception
*/
public function post($url, $raw = true)
{
$this->_baseUrl = $url;
return $this->_httpRequest('POST', $raw);
}
/**
* Start performing PUT-HTTP-Request
*
* @param string $url
* @param boolean $raw if response body contains JSON and should be decoded
*
* @return mixed
* @throws \Exception
*/
public function put($url, $raw = true)
{
$this->_baseUrl = $url;
return $this->_httpRequest('PUT', $raw);
}
/**
* Start performing PATCH-HTTP-Request
*
* @param string $url
* @param bool $raw if response body contains JSON and should be decoded
*
* @return mixed
* @throws \Exception
*/
public function patch($url, $raw = true)
{
$this->_baseUrl = $url;
$this->setHeaders([
'X-HTTP-Method-Override' => 'PATCH'
]);
return $this->_httpRequest('PATCH',$raw);
}
/**
* Start performing DELETE-HTTP-Request
*
* @param string $url
* @param boolean $raw if response body contains JSON and should be decoded
*
* @return mixed
* @throws \Exception
*/
public function delete($url, $raw = true)
{
$this->_baseUrl = $url;
return $this->_httpRequest('DELETE', $raw);
}
/**
* Set curl option
*
* @param string $key
* @param mixed $value
*
* @return $this
*/
public function setOption($key, $value)
{
//set value
if (array_key_exists($key, $this->_defaultOptions) && $key !== CURLOPT_WRITEFUNCTION) {
$this->_defaultOptions[$key] = $value;
} else {
$this->_options[$key] = $value;
}
//return self
return $this;
}
/**
* Set get params
*
* @param array $params
* @return $this
*/
public function setGetParams($params)
{
if (is_array($params)) {
foreach ($params as $key => $value) {
$this->_getParams[$key] = $value;
}
}
//return self
return $this;
}
/**
* Set get params
*
* @param array $params
* @return $this
*/
public function setPostParams($params)
{
if (is_array($params)) {
$this->setOption(
CURLOPT_POSTFIELDS,
http_build_query($params)
);
}
//return self
return $this;
}
/**
* Set raw post data allows you to post any data format.
*
* @param mixed $data
* @return $this
*/
public function setRawPostData($data)
{
$this->setOption(
CURLOPT_POSTFIELDS,
$data
);
//return self
return $this;
}
/**
* Set get params
*
* @param string $data
* @return $this
*/
public function setRequestBody($data)
{
if (is_string($data)) {
$this->setOption(
CURLOPT_POSTFIELDS,
$data
);
}
//return self
return $this;
}
/**
* Get URL - return URL parsed with given params
*
* @return string The full URL with parsed get params
*/
public function getUrl()
{
if (Count($this->_getParams) > 0) {
return $this->_baseUrl.'?'.http_build_query($this->_getParams);
} else {
return $this->_baseUrl;
}
}
/**
* Set curl options
*
* @param array $options
*
* @return $this
*/
public function setOptions($options)
{
$this->_options = $options + $this->_options;
return $this;
}
/**
* Set multiple headers for request.
*
* @param array $headers
*
* @return $this
*/
public function setHeaders($headers)
{
if (is_array($headers)) {
//init
$parsedHeader = [];
//collect currently set headers
foreach ($this->getRequestHeaders() as $header => $value) {
array_push($parsedHeader, $header.':'.$value);
}
//parse header into right format key:value
foreach ($headers as $header => $value) {
array_push($parsedHeader, $header.':'.$value);
}
//set headers
$this->setOption(
CURLOPT_HTTPHEADER,
$parsedHeader
);
}
return $this;
}
/**
* Set a single header for request.
*
* @param string $header
* @param string $value
*
* @return $this
*/
public function setHeader($header, $value)
{
//init
$parsedHeader = [];
//collect currently set headers
foreach ($this->getRequestHeaders() as $headerToSet => $valueToSet) {
array_push($parsedHeader, $headerToSet.':'.$valueToSet);
}
//add override new header
if (strlen($header) > 0) {
array_push($parsedHeader, $header.':'.$value);
}
//set headers
$this->setOption(
CURLOPT_HTTPHEADER,
$parsedHeader
);
return $this;
}
/**
* Unset a single header.
*
* @param string $header
*
* @return $this
*/
public function unsetHeader($header)
{
//init
$parsedHeader = [];
//collect currently set headers and filter "unset" header param.
foreach ($this->getRequestHeaders() as $headerToSet => $valueToSet) {
if ($header !== $headerToSet) {
array_push($parsedHeader, $headerToSet.':'.$valueToSet);
}
}
//set headers
$this->setOption(
CURLOPT_HTTPHEADER,
$parsedHeader
);
return $this;
}
/**
* Get all request headers as key:value array
*
* @return array
*/
public function getRequestHeaders()
{
//Init
$requestHeaders = $this->getOption(CURLOPT_HTTPHEADER);
$parsedRequestHeaders = [];
if (is_array($requestHeaders)) {
foreach ($requestHeaders as $headerValue) {
list ($key, $value) = explode(':', $headerValue, 2);
$parsedRequestHeaders[$key] = $value;
}
}
return $parsedRequestHeaders;
}
/**
* Get specific request header as key:value array
*
* @param string $headerKey
*
* @return string|null
*/
public function getRequestHeader($headerKey)
{
//Init
$parsedRequestHeaders = $this->getRequestHeaders();
return isset($parsedRequestHeaders[$headerKey]) ? $parsedRequestHeaders[$headerKey] : null;
}
/**
* Unset a single curl option
*
* @param string $key
*
* @return $this
*/
public function unsetOption($key)
{
//reset a single option if its set already
if (isset($this->_options[$key])) {
unset($this->_options[$key]);
}
return $this;
}
/**
* Unset all curl option, excluding default options.
*
* @return $this
*/
public function unsetOptions()
{
//reset all options
if (isset($this->_options)) {
$this->_options = [];
}
return $this;
}
/**
* Total reset of options, responses, etc.
*
* @return $this
*/
public function reset()
{
if ($this->curl !== null) {
curl_close($this->curl); //stop curl
}
//reset all options
if (isset($this->_options)) {
$this->_options = [];
}
//reset response & status params
$this->curl = null;
$this->errorCode = null;
$this->response = null;
$this->responseCode = null;
$this->responseCharset = null;
$this->responseLength = -1;
$this->responseType = null;
$this->errorText = null;
$this->_postParams = [];
$this->_getParams = [];
return $this;
}
/**
* Return a single option
*
* @param string|integer $key
* @return mixed|boolean
*/
public function getOption($key)
{
//get merged options depends on default and user options
$mergesOptions = $this->getOptions();
//return value or false if key is not set.
return isset($mergesOptions[$key]) ? $mergesOptions[$key] : false;
}
/**
* Return merged curl options and keep keys!
*
* @return array
*/
public function getOptions()
{
return $this->_options + $this->_defaultOptions;
}
/**
* Get curl info according to http://php.net/manual/de/function.curl-getinfo.php
*
* @param null $opt
* @return array|mixed
*/
public function getInfo($opt = null)
{
if ($this->curl !== null && $opt === null) {
return curl_getinfo($this->curl);
} elseif ($this->curl !== null && $opt !== null) {
return curl_getinfo($this->curl, $opt);
} else {
return [];
}
}
/**
* Performs HTTP request
*
* @param string $method
* @param boolean $raw if response body contains JSON and should be decoded -> helper.
*
* @throws \Exception if request failed
*
* @return mixed
*/
protected function _httpRequest($method, $raw = false)
{
//set request type and writer function
$this->setOption(CURLOPT_CUSTOMREQUEST, strtoupper($method));
//check if method is head and set no body
if ($method === 'HEAD') {
$this->setOption(CURLOPT_NOBODY, true);
$this->unsetOption(CURLOPT_WRITEFUNCTION);
}
//setup error reporting and profiling
if (YII_DEBUG) {
Yii::trace('Start sending cURL-Request: '.$this->getUrl().'\n', __METHOD__);
Yii::beginProfile($method.' '.$this->_baseUrl.'#'.md5(serialize($this->getOption(CURLOPT_POSTFIELDS))), __METHOD__);
}
/**
* proceed curl
*/
$curlOptions = $this->getOptions();
$this->curl = curl_init($this->getUrl());
curl_setopt_array($this->curl, $curlOptions);
$response = curl_exec($this->curl);
//check if curl was successful
if ($response === false) {
//set error code
$this->errorCode = curl_errno($this->curl);
$this->errorText = curl_strerror($this->errorCode);
switch ($this->errorCode) {
// 7, 28 = timeout
case 7:
case 28:
$this->responseCode = 'timeout';
return false;
break;
default:
return false;
break;
}
}
//extract header / body data if CURLOPT_HEADER are set to true
if (isset($curlOptions[CURLOPT_HEADER]) && $curlOptions[CURLOPT_HEADER]) {
$this->response = $this->_extractCurlBody($response);
$this->responseHeaders = $this->_extractCurlHeaders($response);
} else {
$this->response = $response;
}
// Extract additional curl params
$this->_extractAdditionalCurlParameter();
//end yii debug profile
if (YII_DEBUG) {
Yii::endProfile($method.' '.$this->getUrl().'#'.md5(serialize($this->getOption(CURLOPT_POSTFIELDS))), __METHOD__);
}
//check responseCode and return data/status
if ($this->getOption(CURLOPT_CUSTOMREQUEST) === 'HEAD') {
return true;
} else {
$this->response = $raw ? $this->response : json_decode($this->response, true);
return $this->response;
}
}
/**
* Extract additional curl params protected class helper
*/
protected function _extractAdditionalCurlParameter ()
{
/**
* retrieve response code
*/
$this->responseCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
/**
* try extract response type & charset.
*/
$this->responseType = curl_getinfo($this->curl, CURLINFO_CONTENT_TYPE);
if (!is_null($this->responseType) && count(explode(';', $this->responseType)) > 1) {
list($this->responseType, $possibleCharset) = explode(';', $this->responseType);
//extract charset
if (preg_match('~^charset=(.+?)$~', trim($possibleCharset), $matches) && isset($matches[1])) {
$this->responseCharset = strtolower($matches[1]);
}
}
/**
* try extract response length
*/
$this->responseLength = curl_getinfo($this->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
if((int)$this->responseLength === -1) {
$this->responseLength = strlen($this->response);
}
}
/**
* Extract body curl data from response
*
* @param string $response
* @return string
*/
protected function _extractCurlBody ($response)
{
return substr($response, $this->getInfo(CURLINFO_HEADER_SIZE));
}
/**
* Extract header curl data from response
*
* @param string $response
* @return array
*/
protected function _extractCurlHeaders ($response)
{
//Init
$headers = [];
$headerText = substr($response, 0, strpos($response, "\r\n\r\n"));
foreach (explode("\r\n", $headerText) as $i => $line) {
if ($i === 0) {
$headers['http_code'] = $line;
} else {
list ($key, $value) = explode(':', $line, 2);
$headers[$key] = ltrim($value);
}
}
return $headers;
}
}
\ No newline at end of file
yii2-curl extension
===================
[![Latest Stable Version](https://poser.pugx.org/linslin/yii2-curl/v/stable)](https://packagist.org/packages/linslin/yii2-curl)
[![Latest Master Build](https://api.travis-ci.org/linslin/Yii2-Curl.svg?branch=master)](https://travis-ci.org/linslin/Yii2-Curl/builds)
[![Test Coverage](https://codeclimate.com/github/linslin/Yii2-Curl/badges/coverage.svg)](https://codeclimate.com/github/linslin/Yii2-Curl/coverage)
[![Total Downloads](https://poser.pugx.org/linslin/yii2-curl/downloads)](https://packagist.org/packages/linslin/yii2-curl)
[![License](https://poser.pugx.org/linslin/yii2-curl/license)](https://packagist.org/packages/linslin/yii2-curl)
Easy working cURL extension for Yii2, including RESTful support:
- POST
- GET
- HEAD
- PUT
- PATCH
- DELETE
Requirements
------------
- Yii2
- PHP >=7.1.3
- ext-curl, ext-json, and php-curl installed
Installation
------------
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
```bash
php composer.phar require --prefer-dist linslin/yii2-curl "*"
```
Usage
-----
Once the extension is installed, simply use it in your code. The following example shows you how to handling a simple GET Request.
```php
use linslin\yii2\curl;
$curl = new curl\Curl();
//get http://example.com/
$response = $curl->get('http://example.com/');
if ($curl->errorCode === null) {
echo $response;
} else {
// List of curl error codes here https://curl.haxx.se/libcurl/c/libcurl-errors.html
switch ($curl->errorCode) {
case 6:
//host unknown example
break;
}
}
```
```php
// GET request with GET params
// http://example.com/?key=value&scondKey=secondValue
$curl = new curl\Curl();
$response = $curl->setGetParams([
'key' => 'value',
'secondKey' => 'secondValue'
])
->get('http://example.com/');
```
```php
// POST URL form-urlencoded
$curl = new curl\Curl();
$response = $curl->setPostParams([
'key' => 'value',
'secondKey' => 'secondValue'
])
->post('http://example.com/');
```
```php
// POST RAW JSON
$curl = new curl\Curl();
$response = $curl->setRawPostData(
json_encode[
'key' => 'value',
'secondKey' => 'secondValue'
])
->post('http://example.com/');
```
```php
// POST RAW JSON and auto decode JSON respawn by setting raw = true.
// This is usefull if you expect an JSON response and want to autoparse it.
$curl = new curl\Curl();
$response = $curl->setRawPostData(
json_encode[
'key' => 'value',
'secondKey' => 'secondValue'
])
->post('http://example.com/', true);
// JSON decoded response by parsing raw = true in to ->post().
var_dump($response);
```
```php
// POST RAW XML
$curl = new curl\Curl();
$response = $curl->setRawPostData('<?xml version="1.0" encoding="UTF-8"?><someNode>Test</someNode>')
->post('http://example.com/');
```
```php
// POST with special headers
$curl = new curl\Curl();
$response = $curl->setPostParams([
'key' => 'value',
'secondKey' => 'secondValue'
])
->setHeaders([
'Custom-Header' => 'user-b'
])
->post('http://example.com/');
```
```php
// POST JSON with body string & special headers
$curl = new curl\Curl();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$response = $curl->setRequestBody(json_encode($params))
->setHeaders([
'Content-Type' => 'application/json',
'Content-Length' => strlen(json_encode($params))
])
->post('http://example.com/');
```
```php
// Avanced POST request with curl options & error handling
$curl = new curl\Curl();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$response = $curl->setRequestBody(json_encode($params))
->setOption(CURLOPT_ENCODING, 'gzip')
->post('http://example.com/');
// List of status codes here http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
switch ($curl->responseCode) {
case 'timeout':
//timeout error logic here
break;
case 200:
//success logic here
break;
case 404:
//404 Error logic here
break;
}
//list response headers
var_dump($curl->responseHeaders);
```
Testing
------------
- Run codeception tests with `vendor/bin/codecept run` in repository root dir.
On windows run `vendor\bin\codecept.bat run`.
Changelog
------------
##### Release 1.3.0 - Changelog
- Fixed HTTP-Method parsing on PATCH request.
- Updated DocBlocks + code refactoring.
- Removed deprecated PHP Version support. Minimum PHP Version is now 7.1.3.
Please use version "linslin/yii2-curl 1.2.1" - https://github.com/linslin/Yii2-Curl/releases/tag/1.2.1 if you need PHP 5.4+ support.
##### Release 1.2.2 - Changelog
- Added some new cURL examples into readme.md.
##### Release 1.2.1 - Changelog
- Added `setRawPostData([mixed]) [this]` which allows you to post any data format.
##### Release 1.2.0 - Changelog
- Added `unsetHeader([string header]) [this]` helper which allows you to unset one specific header.
- Added `setHeader([string header, string value]) [this]` helper which allows you to set one specific header.
- Added `getRequestHeaders() [array]` helper which returns all request headers as an array.
- Added `getRequestHeader([string headerKey]) [string|null]` helper which returns a specific request header as an string.
- Added new test cases for `getRequestHeaders()` and `getRequestHeader()`.
- Readme adjustments.
##### Release 1.1.3 - Changelog
- Fixed issue with patch request.
- Fully added functionalTests for 100% coverage.
##### Release 1.1.2 - Changelog
- Fixed https://github.com/linslin/Yii2-Curl/issues/59
- Fixed https://github.com/linslin/Yii2-Curl/issues/57
##### Release 1.1.1 - Changelog
- Fixed wrong parameter parsing into `_httpRequest()` (thanks to yemexx1)
- Added JSON decode functions tests (thanks to yemexx1)
##### Release 1.1.0 - Changelog
- Added `setHeaders() [array]` helper.
- Added `setPostParams() [array]` helper.
- Added `setGetParams() [array]` helper.
- Added `setRequestBody() [string]` helper.
- Added `getUrl()` helper.
- Added API attribute `errorText [string|null]` - holds a string describing the given error code - https://github.com/linslin/Yii2-Curl/issues/49.
- Added functionTests to ensure stability.
- Allow PHP class goodness - https://github.com/linslin/Yii2-Curl/issues/52.
- Fixed header explode - https://github.com/linslin/Yii2-Curl/pull/51.
##### Release 1.0.11 - Changelog
- Added API attribute `responseHeaders [array|null]` which returns an array of all response headers.
- Changed `_defaultOptions[CURLOPT_HEADER]` to `true`.
- Profile debugging is only active if constant `YII_DEBUG` is `true`.
##### Release 1.0.10 - Changelog
- Fixed PHP notice https://github.com/linslin/Yii2-Curl/issues/39.
##### Release 1.0.9 - Changelog
- Added API attribute `responseCode [string|null]` which holds the HTTP response code.
- Added API attribute `responseCharset [string|null]` which holds the response charset.
- Added API attribute `responseLength [integer|null]` which holds the response length.
- Added API attribute `errorCode` which holds the a integer code error like described here: https://curl.haxx.se/libcurl/c/libcurl-errors.html.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues//36.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues//37 and removed exception throwing on curl fail. This allow the user to handle the error while using attribute `errorCode`.
##### Release 1.0.8 - Changelog
- Added API method `setOptions([array])` which allows to setup multiple options at once.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues/30.
##### Release 1.0.7 - Changelog
- Fixed `getInfo([, int $opt = 0 ])` exception were cURL wasn't initialized before calling `getInfo($opt)`.
##### Release 1.0.6 - Changelog
- Added `getInfo([, int $opt = 0 ])` method to retrieve http://php.net/manual/de/function.curl-getinfo.php data.
##### Release 1.0.5 - Changelog
- Made `body` callback not depending on HTTP-Status codes anymore. You can retrieve `body` data on any HTTP-Status now.
- Fixed Issue https://github.com/linslin/Yii2-Curl/issues/19 where override default settings break options.
- Added timeout response handling. `$curl->responseCode = 'timeout'`
##### Release 1.0.4 - Changelog
- `CURLOPT_RETURNTRANSFER` is now set to true on default - https://github.com/linslin/Yii2-Curl/issues/18
- Readme.md adjustments.
##### Release 1.0.3 - Changelog
- Fixed override of user options. https://github.com/linslin/Yii2-Curl/pull/7
- Nice formatted PHP-examples.
- Moved `parent::init();` behavior into unitTest Controller.
##### Release 1.0.2 - Changelog
- Added custom params support
- Added custom status code support
- Added POST-Param support and a readme example
- Removed "body" support at request functions. Please use "CURLOPT_POSTFIELDS" to setup a body now.
- Readme modifications
##### Release 1.0.1 - Changelog
- Removed widget support
- Edited some spellings + added more examples into readme.md
##### Release 1.0 - Changelog
- Official stable release
\ No newline at end of file
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
coverage:
enabled: true
include:
- Curl.php
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
- Codeception\Extension\Phiremock
config:
Codeception\Extension\Phiremock:
listen: 127.0.0.1:18080 # defaults to 0.0.0.0:8086
bin_path: vendor/bin # defaults to codeception_dir/../vendor/bin
debug: true # defaults to false
startDelay: 1 # default to 0
modules:
config:
Db:
dsn: ''
user: ''
password: ''
dump: tests/_data/dump.sql
{
"name": "linslin/yii2-curl",
"description": "Easy and nice cURL extension with RESTful support for Yii2",
"type": "yii2-extension",
"keywords": ["yii2","extension"," curl", "RESTful"],
"license": "MIT",
"authors": [
{
"name": "Nils Gajsek",
"email": "info@linslin.org"
}
],
"require": {
"ext-json": "*",
"ext-curl": "*",
"yiisoft/yii2": "*"
},
"require-dev": {
"codeception/base": "^2.2.3",
"codeception/verify": "~0.3.1",
"codeception/specify": "~0.4.3",
"guzzlehttp/guzzle": ">=4.1.4 <7.0",
"mcustiel/phiremock-codeception-extension": "1.2.4",
"codeclimate/php-test-reporter": "dev-master"
},
"autoload": {
"psr-4": {
"linslin\\yii2\\curl\\": ""
}
}
}
<?php
/**
* Minimal Yii2 setup for test environment
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
\ No newline at end of file
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;
/**
* Define custom actions here
*/
}
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Acceptance extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
{
}
<?php
namespace Helper;
// here you can define custom actions
// all public methods declared in helper class will be available in $I
class Unit extends \Codeception\Module
{
}
<?php
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
<?php //[STAMP] c3f973d7d565ef23c473f5d8c511c70d
namespace _generated;
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile
trait AcceptanceTesterActions
{
/**
* @return \Codeception\Scenario
*/
abstract protected function getScenario();
}
<?php //[STAMP] 4eebdc02c639acc0dbe1ec2e5b0bbe3c
namespace _generated;
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile
trait FunctionalTesterActions
{
/**
* @return \Codeception\Scenario
*/
abstract protected function getScenario();
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values equal.
*
* Regular example:
* ```php
* <?php
* $I->assertEquals(5, $element->getChildrenCount());
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertEquals(0.3, $calculator->add(0.1, 0.2), 'Calculator should add the two numbers correctly.', 0.01);
* ```
*
* @param $expected
* @param $actual
* @param string $message
* @param float $delta
* @see \Codeception\Module\Asserts::assertEquals()
*/
public function assertEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are not equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values not equal.
*
* Regular example:
* ```php
* <?php
* $I->assertNotEquals(0, $element->getChildrenCount());
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertNotEquals(0.4, $calculator->add(0.1, 0.2), 'Calculator should add the two numbers correctly.', 0.01);
* ```
*
* @param $expected
* @param $actual
* @param string $message
* @param float $delta
* @see \Codeception\Module\Asserts::assertNotEquals()
*/
public function assertNotEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are same
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertSame()
*/
public function assertSame($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are not same
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotSame()
*/
public function assertNotSame($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is greater than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertGreaterThan()
*/
public function assertGreaterThan($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is greater or equal than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertGreaterThanOrEqual()
*/
public function assertGreaterThanOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is less than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertLessThan()
*/
public function assertLessThan($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is less or equal than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertLessThanOrEqual()
*/
public function assertLessThanOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that haystack contains needle
*
* @param $needle
* @param $haystack
* @param string $message
* @see \Codeception\Module\Asserts::assertContains()
*/
public function assertContains($needle, $haystack, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that haystack doesn't contain needle.
*
* @param $needle
* @param $haystack
* @param string $message
* @see \Codeception\Module\Asserts::assertNotContains()
*/
public function assertNotContains($needle, $haystack, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that string match with pattern
*
* @param string $pattern
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertRegExp()
*/
public function assertRegExp($pattern, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that string not match with pattern
*
* @param string $pattern
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertNotRegExp()
*/
public function assertNotRegExp($pattern, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string starts with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsWith()
*/
public function assertStringStartsWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string doesn't start with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsNotWith()
*/
public function assertStringStartsNotWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is empty.
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertEmpty()
*/
public function assertEmpty($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is not empty.
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotEmpty()
*/
public function assertNotEmpty($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is NULL
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNull()
*/
public function assertNull($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is not NULL
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotNull()
*/
public function assertNotNull($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that condition is positive.
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertTrue()
*/
public function assertTrue($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that the condition is NOT true (everything but true)
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertNotTrue()
*/
public function assertNotTrue($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotTrue', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that condition is negative.
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertFalse()
*/
public function assertFalse($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that the condition is NOT false (everything but false)
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertNotFalse()
*/
public function assertNotFalse($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotFalse', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks if file exists
*
* @param string $filename
* @param string $message
* @see \Codeception\Module\Asserts::assertFileExists()
*/
public function assertFileExists($filename, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks if file doesn't exist
*
* @param string $filename
* @param string $message
* @see \Codeception\Module\Asserts::assertFileNotExists()
*/
public function assertFileNotExists($filename, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expected
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertGreaterOrEquals()
*/
public function assertGreaterOrEquals($expected, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expected
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertLessOrEquals()
*/
public function assertLessOrEquals($expected, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertIsEmpty()
*/
public function assertIsEmpty($actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $key
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertArrayHasKey()
*/
public function assertArrayHasKey($key, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $key
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertArrayNotHasKey()
*/
public function assertArrayNotHasKey($key, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module\Asserts::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expectedCount
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertCount()
*/
public function assertCount($expectedCount, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCount', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $class
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertInstanceOf()
*/
public function assertInstanceOf($class, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $class
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertNotInstanceOf()
*/
public function assertNotInstanceOf($class, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $type
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertInternalType()
*/
public function assertInternalType($type, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Fails the test with message.
*
* @param $message
* @see \Codeception\Module\Asserts::fail()
*/
public function fail($message) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Handles and checks exception called inside callback function.
* Either exception class name or exception instance should be provided.
*
* ```php
* <?php
* $I->expectException(MyException::class, function() {
* $this->doSomethingBad();
* });
*
* $I->expectException(new MyException(), function() {
* $this->doSomethingBad();
* });
* ```
* If you want to check message or exception code, you can pass them with exception instance:
* ```php
* <?php
* // will check that exception MyException is thrown with "Don't do bad things" message
* $I->expectException(new MyException("Don't do bad things"), function() {
* $this->doSomethingBad();
* });
* ```
*
* @param $exception string or \Exception
* @param $callback
*
* @deprecated Use expectThrowable instead
* @see \Codeception\Module\Asserts::expectException()
*/
public function expectException($exception, $callback) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Handles and checks throwables (Exceptions/Errors) called inside the callback function.
* Either throwable class name or throwable instance should be provided.
*
* ```php
* <?php
* $I->expectThrowable(MyThrowable::class, function() {
* $this->doSomethingBad();
* });
*
* $I->expectThrowable(new MyException(), function() {
* $this->doSomethingBad();
* });
* ```
* If you want to check message or throwable code, you can pass them with throwable instance:
* ```php
* <?php
* // will check that throwable MyError is thrown with "Don't do bad things" message
* $I->expectThrowable(new MyError("Don't do bad things"), function() {
* $this->doSomethingBad();
* });
* ```
*
* @param $throwable string or \Throwable
* @param $callback
* @see \Codeception\Module\Asserts::expectThrowable()
*/
public function expectThrowable($throwable, $callback) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('expectThrowable', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @see \Codeception\Module\Phiremock::expectARequestToRemoteServiceWithAResponse()
*/
public function expectARequestToRemoteServiceWithAResponse($expectation) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('expectARequestToRemoteServiceWithAResponse', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @see \Codeception\Module\Phiremock::haveACleanSetupInRemoteService()
*/
public function haveACleanSetupInRemoteService() {
return $this->getScenario()->runStep(new \Codeception\Step\Action('haveACleanSetupInRemoteService', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @see \Codeception\Module\Phiremock::dontExpectRequestsInRemoteService()
*/
public function dontExpectRequestsInRemoteService() {
return $this->getScenario()->runStep(new \Codeception\Step\Action('dontExpectRequestsInRemoteService', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @see \Codeception\Module\Phiremock::haveCleanScenariosInRemoteService()
*/
public function haveCleanScenariosInRemoteService() {
return $this->getScenario()->runStep(new \Codeception\Step\Action('haveCleanScenariosInRemoteService', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* Conditional Assertion: Test won't be stopped on fail
* @see \Codeception\Module\Phiremock::seeRemoteServiceReceived()
*/
public function canSeeRemoteServiceReceived($times, $builder) {
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeRemoteServiceReceived', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
*
* @see \Codeception\Module\Phiremock::seeRemoteServiceReceived()
*/
public function seeRemoteServiceReceived($times, $builder) {
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeRemoteServiceReceived', func_get_args()));
}
}
<?php //[STAMP] 7bead099398d3adac547a525fb171305
namespace _generated;
// This class was automatically generated by build task
// You should not change it manually as it will be overwritten on next build
// @codingStandardsIgnoreFile
trait UnitTesterActions
{
/**
* @return \Codeception\Scenario
*/
abstract protected function getScenario();
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values equal.
*
* Regular example:
* ```php
* <?php
* $I->assertEquals(5, $element->getChildrenCount());
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertEquals(0.3, $calculator->add(0.1, 0.2), 'Calculator should add the two numbers correctly.', 0.01);
* ```
*
* @param $expected
* @param $actual
* @param string $message
* @param float $delta
* @see \Codeception\Module\Asserts::assertEquals()
*/
public function assertEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are not equal. If you're comparing floating-point values,
* you can specify the optional "delta" parameter which dictates how great of a precision
* error are you willing to tolerate in order to consider the two values not equal.
*
* Regular example:
* ```php
* <?php
* $I->assertNotEquals(0, $element->getChildrenCount());
* ```
*
* Floating-point example:
* ```php
* <?php
* $I->assertNotEquals(0.4, $calculator->add(0.1, 0.2), 'Calculator should add the two numbers correctly.', 0.01);
* ```
*
* @param $expected
* @param $actual
* @param string $message
* @param float $delta
* @see \Codeception\Module\Asserts::assertNotEquals()
*/
public function assertNotEquals($expected, $actual, $message = null, $delta = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are same
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertSame()
*/
public function assertSame($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that two variables are not same
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotSame()
*/
public function assertNotSame($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is greater than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertGreaterThan()
*/
public function assertGreaterThan($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is greater or equal than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertGreaterThanOrEqual()
*/
public function assertGreaterThanOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is less than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertLessThan()
*/
public function assertLessThan($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that actual is less or equal than expected
*
* @param $expected
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertLessThanOrEqual()
*/
public function assertLessThanOrEqual($expected, $actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that haystack contains needle
*
* @param $needle
* @param $haystack
* @param string $message
* @see \Codeception\Module\Asserts::assertContains()
*/
public function assertContains($needle, $haystack, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that haystack doesn't contain needle.
*
* @param $needle
* @param $haystack
* @param string $message
* @see \Codeception\Module\Asserts::assertNotContains()
*/
public function assertNotContains($needle, $haystack, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that string match with pattern
*
* @param string $pattern
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertRegExp()
*/
public function assertRegExp($pattern, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that string not match with pattern
*
* @param string $pattern
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertNotRegExp()
*/
public function assertNotRegExp($pattern, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string starts with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsWith()
*/
public function assertStringStartsWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that a string doesn't start with the given prefix.
*
* @param string $prefix
* @param string $string
* @param string $message
* @see \Codeception\Module\Asserts::assertStringStartsNotWith()
*/
public function assertStringStartsNotWith($prefix, $string, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertStringStartsNotWith', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is empty.
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertEmpty()
*/
public function assertEmpty($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is not empty.
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotEmpty()
*/
public function assertNotEmpty($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is NULL
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNull()
*/
public function assertNull($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that variable is not NULL
*
* @param $actual
* @param string $message
* @see \Codeception\Module\Asserts::assertNotNull()
*/
public function assertNotNull($actual, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that condition is positive.
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertTrue()
*/
public function assertTrue($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that the condition is NOT true (everything but true)
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertNotTrue()
*/
public function assertNotTrue($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotTrue', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that condition is negative.
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertFalse()
*/
public function assertFalse($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that the condition is NOT false (everything but false)
*
* @param $condition
* @param string $message
* @see \Codeception\Module\Asserts::assertNotFalse()
*/
public function assertNotFalse($condition, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotFalse', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks if file exists
*
* @param string $filename
* @param string $message
* @see \Codeception\Module\Asserts::assertFileExists()
*/
public function assertFileExists($filename, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks if file doesn't exist
*
* @param string $filename
* @param string $message
* @see \Codeception\Module\Asserts::assertFileNotExists()
*/
public function assertFileNotExists($filename, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expected
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertGreaterOrEquals()
*/
public function assertGreaterOrEquals($expected, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterOrEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expected
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertLessOrEquals()
*/
public function assertLessOrEquals($expected, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessOrEquals', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertIsEmpty()
*/
public function assertIsEmpty($actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertIsEmpty', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $key
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertArrayHasKey()
*/
public function assertArrayHasKey($key, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayHasKey', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $key
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertArrayNotHasKey()
*/
public function assertArrayNotHasKey($key, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArrayNotHasKey', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Checks that array contains subset.
*
* @param array $subset
* @param array $array
* @param bool $strict
* @param string $message
* @see \Codeception\Module\Asserts::assertArraySubset()
*/
public function assertArraySubset($subset, $array, $strict = null, $message = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertArraySubset', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $expectedCount
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertCount()
*/
public function assertCount($expectedCount, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertCount', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $class
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertInstanceOf()
*/
public function assertInstanceOf($class, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInstanceOf', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $class
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertNotInstanceOf()
*/
public function assertNotInstanceOf($class, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotInstanceOf', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* @param $type
* @param $actual
* @param $description
* @see \Codeception\Module\Asserts::assertInternalType()
*/
public function assertInternalType($type, $actual, $description = null) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('assertInternalType', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Fails the test with message.
*
* @param $message
* @see \Codeception\Module\Asserts::fail()
*/
public function fail($message) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Handles and checks exception called inside callback function.
* Either exception class name or exception instance should be provided.
*
* ```php
* <?php
* $I->expectException(MyException::class, function() {
* $this->doSomethingBad();
* });
*
* $I->expectException(new MyException(), function() {
* $this->doSomethingBad();
* });
* ```
* If you want to check message or exception code, you can pass them with exception instance:
* ```php
* <?php
* // will check that exception MyException is thrown with "Don't do bad things" message
* $I->expectException(new MyException("Don't do bad things"), function() {
* $this->doSomethingBad();
* });
* ```
*
* @param $exception string or \Exception
* @param $callback
*
* @deprecated Use expectThrowable instead
* @see \Codeception\Module\Asserts::expectException()
*/
public function expectException($exception, $callback) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('expectException', func_get_args()));
}
/**
* [!] Method is generated. Documentation taken from corresponding module.
*
* Handles and checks throwables (Exceptions/Errors) called inside the callback function.
* Either throwable class name or throwable instance should be provided.
*
* ```php
* <?php
* $I->expectThrowable(MyThrowable::class, function() {
* $this->doSomethingBad();
* });
*
* $I->expectThrowable(new MyException(), function() {
* $this->doSomethingBad();
* });
* ```
* If you want to check message or throwable code, you can pass them with throwable instance:
* ```php
* <?php
* // will check that throwable MyError is thrown with "Don't do bad things" message
* $I->expectThrowable(new MyError("Don't do bad things"), function() {
* $this->doSomethingBad();
* });
* ```
*
* @param $throwable string or \Throwable
* @param $callback
* @see \Codeception\Module\Asserts::expectThrowable()
*/
public function expectThrowable($throwable, $callback) {
return $this->getScenario()->runStep(new \Codeception\Step\Action('expectThrowable', func_get_args()));
}
}
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
<?php
// Here you can initialize variables that will be available to your tests
# Codeception Test Suite Configuration
#
# Suite for functional (integration) tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- \Helper\Functional
- Asserts
- Phiremock:
host: 127.0.0.1
port: 18080
<?php
// Here you can initialize variables that will be available to your tests
<?php
//use namespaces
use Mcustiel\Phiremock\Client\Phiremock;
use Mcustiel\Phiremock\Client\Utils\A;
use Mcustiel\Phiremock\Client\Utils\Respond;
use Mcustiel\Phiremock\Client\Utils\Is;
/**
* Class httpMockCest
*/
class httpMockCest
{
// ############################################### private class vars // ###########################################
/**
* Holds instance of yii2-curl
* @type linslin\yii2\curl\Curl
*/
private $_curl = null;
/**
* Default test server endpoint URL
* @type string
*/
private $_endPoint = 'http://127.0.0.1:18080';
// ################################################## class methods // #############################################
/**
* Cleanup
* @param \FunctionalTester $I
*/
public function _before(\FunctionalTester $I)
{
$I->haveACleanSetupInRemoteService();
//Init curl
$this->_curl = new linslin\yii2\curl\Curl();
}
/**
* Simple HTTP ok
* @param FunctionalTester $I
* @throws Exception
*/
public function simpleHttpOkTest(\FunctionalTester $I)
{
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/httpStatus/200'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->get($this->_endPoint . '/test/httpStatus/200');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Try set params to send with get request
* @param FunctionalTester $I
* @throws Exception
*/
public function setGetParamsTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/params/get?' . http_build_query($params)))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setGetParams($params)
->get($this->_endPoint . '/test/params/get');
$I->assertEquals($this->_curl->responseCode, 200);
$I->assertEquals($this->_curl->getUrl(), $this->_endPoint . '/test/params/get?' . http_build_query($params));
}
/**
* Try set post to send with post request
* @param FunctionalTester $I
* @throws Exception
*/
public function setPostParamsTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/x-www-form-urlencoded'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Try set post to send with post request
* @param FunctionalTester $I
* @throws Exception
*/
public function setPostParamsOptionTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/x-www-form-urlencoded'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setOption(
CURLOPT_POSTFIELDS,
http_build_query($params))
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Try set post param with header modification
* @param FunctionalTester $I
* @throws Exception
*/
public function setPostParamsWithHeaderTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->setHeaders([
'Content-Type' => 'application/json'
])
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Post JSON data test
* @param FunctionalTester $I
* @throws Exception
*/
public function postJsonTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(json_encode($params)))
->andHeader('content-type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
->andBody('{"id": 1, "description": "I am a resource"}')
)
);
$this->_curl->setRequestBody(json_encode($params))
->setHeaders([
'content-type' => 'application/json',
'content-length' => strlen(json_encode($params))
])
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Get JSON response test
* @param FunctionalTester $I
* @throws Exception
*/
public function getWithDecodedJsonResponseTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/params/get/json'))
)->then(
Respond::withStatusCode(200)
->andBody('{"id": 1, "description": "I am a resource"}')
)
);
$jsonResponse = $this->_curl->get($this->_endPoint . '/test/params/get/json', false);
$I->assertEquals($this->_curl->responseCode, 200);
$I->assertArrayHasKey('id', $jsonResponse);
$I->assertArrayHasKey('description', $jsonResponse);
$I->assertEquals($jsonResponse['id'], 1);
$I->assertEquals($jsonResponse['description'], 'I am a resource');
}
/**
* Get JSON response test
* @param FunctionalTester $I
* @throws Exception
*/
public function getWithRawJsonResponseTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/params/get/json'))
)->then(
Respond::withStatusCode(200)
->andBody('{"id": 1, "description": "I am a resource"}')
)
);
$rawResponse = $this->_curl->get($this->_endPoint . '/test/params/get/json', true);
$I->assertEquals($this->_curl->responseCode, 200);
$I->assertEquals($rawResponse, '{"id": 1, "description": "I am a resource"}');
}
/**
* Get header params with special header separators in values
* @issue https://github.com/linslin/Yii2-Curl/issues/59
*
* @param FunctionalTester $I
* @throws Exception
*/
public function getHeaderParamWithSpecialHeaderSeparatorInValue(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/header'))
)->then(
Respond::withStatusCode(200)
->andHeader('param', 'value')
->andHeader('location', 'http://somelocation/')
)
);
$this->_curl->get($this->_endPoint . '/test/header');
$I->assertEquals($this->_curl->responseCode, 200);
$I->assertEquals($this->_curl->responseHeaders['location'], 'http://somelocation/');
$I->assertEquals($this->_curl->responseHeaders['param'], 'value');
}
/**
* Default head method test
* @param FunctionalTester $I
* @throws Exception
*/
public function defaultHeadMethodTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::headRequest()->andUrl(Is::equalTo('/test/head'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->head($this->_endPoint . '/test/head');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Default delete method test
* @param FunctionalTester $I
* @throws Exception
*/
public function defaultDeleteMethodTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::deleteRequest()->andUrl(Is::equalTo('/test/head'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->delete($this->_endPoint . '/test/head');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Default patch method test
* @param FunctionalTester $I
* @throws Exception
*/
public function defaultPatchMethodTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::patchRequest()->andUrl(Is::equalTo('/test/head'))
->andHeader('X-HTTP-Method-Override', Is::equalTo('PATCH'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->patch($this->_endPoint . '/test/head');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Default put method test
* @param FunctionalTester $I
* @throws Exception
*/
public function defaultPutMethodTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::putRequest()->andUrl(Is::equalTo('/test/head'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->put($this->_endPoint . '/test/head');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Set single option test
* @param FunctionalTester $I
* @throws Exception
*/
public function setSingleDefaultOptionTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/x-www-form-urlencoded'))
->andHeader('user-agent', Is::equalTo('my-agent'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setOption(CURLOPT_USERAGENT, 'my-agent')
->setPostParams($params)
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Set multiple option test
* @param FunctionalTester $I
* @throws Exception
*/
public function setMultipleOptionsTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/x-www-form-urlencoded'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setOptions([
CURLOPT_USERAGENT => 'my-agent',
CURLOPT_POSTFIELDS => http_build_query($params)
])
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Set and unset option test
* @param FunctionalTester $I
* @throws Exception
*/
public function setUnsetSingleOptionTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(''))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setOption(CURLOPT_POSTFIELDS, http_build_query($params))
->unsetOption(CURLOPT_POSTFIELDS)
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Set and unset all options test
* @param FunctionalTester $I
* @throws Exception
*/
public function setAllAndUnsertOptionsTest(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(''))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setOption(CURLOPT_POSTFIELDS, http_build_query($params))
->unsetOptions()
->post($this->_endPoint . '/test/params/post');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Simple reset after request test
* @param FunctionalTester $I
* @throws Exception
*/
public function resetAfterGet(\FunctionalTester $I)
{
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/httpStatus/200'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->get($this->_endPoint . '/test/httpStatus/200');
$I->assertEquals($this->_curl->responseCode, 200);
$this->_curl->reset();
$I->assertEquals($this->_curl->curl, null);
}
/**
* Simple get info test
* @param FunctionalTester $I
* @throws Exception
*/
public function getInfo(\FunctionalTester $I)
{
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/httpStatus/200'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->get($this->_endPoint . '/test/httpStatus/200');
$I->assertEquals($this->_curl->responseCode, 200);
$this->_curl->getInfo();
}
/**
* Simple get info without curl test
* @param \FunctionalTester $I
*/
public function getInfoWithoutCurl(\FunctionalTester $I)
{
$I->assertEquals($this->_curl->getInfo(CURLINFO_HEADER_SIZE ), []);
}
/**
* Simple curl timeout test
* @param FunctionalTester $I
* @throws Exception
*/
public function defaultCurlTimeoutError(\FunctionalTester $I)
{
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/httpStatus/timeout'))
)->then(
Respond::withStatusCode(404)
->andDelayInMillis(2000)
)
);
$this->_curl->setOption(CURLOPT_TIMEOUT, 1)
->get($this->_endPoint . '/test/httpStatus/timeout');
$I->assertEquals($this->_curl->responseCode, 'timeout');
}
/**
* Simple get without head request
* @param FunctionalTester $I
* @throws Exception
*/
public function simpleGetWithoutHead(\FunctionalTester $I)
{
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/httpStatus/200'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl
->setOption(CURLOPT_HEADER, false)
->get($this->_endPoint . '/test/httpStatus/200');
$I->assertEquals($this->_curl->responseCode, 200);
}
/**
* Simple curl error test CURL_UNSUPPORTED_PROTOCOL
* @param FunctionalTester $I
* @throws Exception
*/
public function defaultCurlError(\FunctionalTester $I)
{
$this->_curl->get( 'messy:/test/httpStatus/timeout');
$I->assertEquals($this->_curl->responseCode, null);
$I->assertLessOrEquals($this->_curl->errorCode, 1);
}
/**
* Default charset extract test
* @param FunctionalTester $I
* @throws Exception
*/
public function defaultCharsetExtractTest(\FunctionalTester $I)
{
$I->expectARequestToRemoteServiceWithAResponse(
Phiremock::on(
A::getRequest()->andUrl(Is::equalTo('/test/httpStatus/header'))
)->then(
Respond::withStatusCode(200)
->andHeader('Content-Type', Is::equalTo('application/x-javascript;charset=UTF-8'))
)
);
$this->_curl
->get($this->_endPoint . '/test/httpStatus/header');
$I->assertEquals($this->_curl->responseCharset, 'utf-8');
}
/**
* Try set a header param and check if getHeaders() does return it
* @param FunctionalTester $I
* @throws Exception
*/
public function setHeaderParamAndTestGetHeaders(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->setHeaders([
'Content-Type' => 'application/json'
])
->post($this->_endPoint . '/test/params/post');
//check for count
$I->assertEquals(count($this->_curl->getRequestHeaders()), 1);
//check for value
$requestHeaders = $this->_curl->getRequestHeaders();
$I->assertEquals($requestHeaders['Content-Type'], 'application/json');
}
/**
* Try set a header param and check if getHeader() does return it
* @param FunctionalTester $I
* @throws Exception
*/
public function setHeaderParamAndTestGetHeader(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->setHeaders([
'Content-Type' => 'application/json'
])
->post($this->_endPoint . '/test/params/post');
//check for value
$I->assertEquals($this->_curl->getRequestHeader('Content-Type'), 'application/json');
}
/**
* Try set a single header param and check if getRequestHeader() does return it
* @param FunctionalTester $I
* @throws Exception
*/
public function setSingleHeaderParamAndTestGetHeader(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->setHeader('Content-Type', 'application/json')
->post($this->_endPoint . '/test/params/post');
//check for value
$I->assertEquals($this->_curl->getRequestHeader('Content-Type'), 'application/json');
}
/**
* Try set a single header and multiple headers at once and check if getRequestHeader() does return it
* @param FunctionalTester $I
* @throws Exception
*/
public function setSingleHeaderAndMultipleHeadersAndTestGetHeader(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
->andHeader('custom-type', Is::equalTo('><)#7?aJEvgavJk(*4'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->setHeader('Content-Type', 'application/json')
->setHeaders([
'custom-type' => '><)#7?aJEvgavJk(*4'
])
->post($this->_endPoint . '/test/params/post');
//check for value
$I->assertEquals($this->_curl->getRequestHeader('Content-Type'), 'application/json');
$I->assertEquals($this->_curl->getRequestHeader('custom-type'), '><)#7?aJEvgavJk(*4');
}
/**
* Try set a single header, multiple header and unset one header param and check if getRequestHeader() does return it
* @param FunctionalTester $I
* @throws Exception
*/
public function setSingleHeaderAndMultipleHeadersAndUnsetOneTillTestGetHeader(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->setHeader('Content-Type', 'application/json')
->setHeaders([
'custom-type' => '><)#7?aJEvgavJk(*4'
])
->unsetHeader('custom-type')
->post($this->_endPoint . '/test/params/post');
//check for value
$I->assertEquals($this->_curl->getRequestHeader('Content-Type'), 'application/json');
$I->assertEquals($this->_curl->getRequestHeader('custom-type'), null);
}
/**
* Try set a single header, multiple header and unset one header param and check if getRequestHeader() does return it
* @param FunctionalTester $I
* @throws Exception
*/
public function setMultipleHeadersAndSingleHeaderAndUnsetOneTillTestGetHeader(\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(http_build_query($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setPostParams($params)
->setHeaders([
'custom-type' => '><)#7?aJEvgavJk(*4'
])
->setHeader('Content-Type', 'application/json')
->unsetHeader('custom-type')
->post($this->_endPoint . '/test/params/post');
//check for value
$I->assertEquals($this->_curl->getRequestHeader('Content-Type'), 'application/json');
$I->assertEquals($this->_curl->getRequestHeader('custom-type'), null);
}
/**
* Try to post raw json string
* @param FunctionalTester $I
* @throws Exception
*/
public function setRawPostDataTest (\FunctionalTester $I)
{
//Init
$this->_curl->reset();
$params = [
'key' => 'value',
'secondKey' => 'secondValue'
];
$I->expectARequestToRemoteServiceWithAResponse(
$expectation = Phiremock::on(
A::postRequest()->andUrl(Is::equalTo('/test/params/post'))
->andBody(Is::equalTo(json_encode($params)))
->andHeader('Content-Type', Is::equalTo('application/json'))
)->then(
Respond::withStatusCode(200)
)
);
$this->_curl->setRawPostData(json_encode($params))
->setHeader('Content-Type', 'application/json')
->post($this->_endPoint . '/test/params/post');
//check for value
$I->assertEquals($this->_curl->getRequestHeader('Content-Type'), 'application/json');
}
}
# Codeception Test Suite Configuration
#
# Suite for unit (internal) tests.
class_name: UnitTester
modules:
enabled:
- Asserts
- \Helper\Unit
\ No newline at end of file
<?php
/**
* Class CurlTest
*/
class CurlTest extends \Codeception\Test\Unit
{
// ################################################### Class methods ###############################################
/**
* No sense test
*/
public function testInit()
{
$curl = new linslin\yii2\curl\Curl();
expect($curl instanceof linslin\yii2\curl\Curl)->equals(true);
}
}
<?php
// Here you can initialize variables that will be available to your tests
......@@ -291,4 +291,13 @@ return array (
'@yii/queue/sqs' => $vendorDir . '/yiisoft/yii2-queue/src/drivers/sqs',
),
),
'linslin/yii2-curl' =>
array (
'name' => 'linslin/yii2-curl',
'version' => '1.3.0.0',
'alias' =>
array (
'@linslin/yii2/curl' => $vendorDir . '/linslin/yii2-curl',
),
),
);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment