diff --git a/composer.json b/composer.json index 3ab3740..78467cd 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ ], "require": { "php": ">=7.0.0", - "psr/log": "^1.0", + "roave/security-advisories": "dev-master", + "unreal4u/dummy-logger": "^1.0", "react/http-client": "^0.5", "react/promise": "^2.5", "clue/block-react": "^1.1", diff --git a/composer.lock b/composer.lock index b9f08be..1bce26b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "2d420370b964627532842a0a94ebfa16", + "content-hash": "5f3eb18571d385a0e5375aade84ed767", "packages": [ { "name": "amphp/amp", @@ -390,16 +390,16 @@ }, { "name": "amphp/parallel", - "version": "v0.2.0", + "version": "v0.2.1", "source": { "type": "git", "url": "https://github.com/amphp/parallel.git", - "reference": "c545be1dc5be296eb57f9cc2f540d53abc04da31" + "reference": "0d40e6da980d56de8bbd292668becef6ed45a2a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/parallel/zipball/c545be1dc5be296eb57f9cc2f540d53abc04da31", - "reference": "c545be1dc5be296eb57f9cc2f540d53abc04da31", + "url": "https://api.github.com/repos/amphp/parallel/zipball/0d40e6da980d56de8bbd292668becef6ed45a2a7", + "reference": "0d40e6da980d56de8bbd292668becef6ed45a2a7", "shasum": "" }, "require": { @@ -449,7 +449,7 @@ "multi-processing", "multi-threading" ], - "time": "2017-12-14T05:06:38+00:00" + "time": "2017-12-27T18:36:28+00:00" }, { "name": "amphp/parser", @@ -1464,6 +1464,189 @@ ], "time": "2017-12-21T14:12:01+00:00" }, + { + "name": "roave/security-advisories", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/Roave/SecurityAdvisories.git", + "reference": "0703d860f83775029738dc4a519301e8e3d81853" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/0703d860f83775029738dc4a519301e8e3d81853", + "reference": "0703d860f83775029738dc4a519301e8e3d81853", + "shasum": "" + }, + "conflict": { + "adodb/adodb-php": "<5.20.6", + "amphp/artax": "<1.0.6|>=2,<2.0.6", + "aws/aws-sdk-php": ">=3,<3.2.1", + "bugsnag/bugsnag-laravel": ">=2,<2.0.2", + "cakephp/cakephp": ">=1.3,<1.3.18|>=2,<2.4.99|>=2.5,<2.5.99|>=2.6,<2.6.12|>=2.7,<2.7.6|>=3,<3.0.15|>=3.1,<3.1.4", + "cart2quote/module-quotation": ">=4.1.6,<=4.4.5|>=5,<5.4.4", + "cartalyst/sentry": "<=2.1.6", + "codeigniter/framework": "<=3.0.6", + "composer/composer": "<=1.0.0-alpha11", + "contao-components/mediaelement": ">=2.14.2,<2.21.1", + "contao/core": ">=2,<3.5.31", + "contao/core-bundle": ">=4,<4.4.8", + "contao/listing-bundle": ">=4,<4.4.8", + "doctrine/annotations": ">=1,<1.2.7", + "doctrine/cache": ">=1,<1.3.2|>=1.4,<1.4.2", + "doctrine/common": ">=2,<2.4.3|>=2.5,<2.5.1", + "doctrine/dbal": ">=2,<2.0.8|>=2.1,<2.1.2", + "doctrine/doctrine-bundle": "<1.5.2", + "doctrine/doctrine-module": "<=0.7.1", + "doctrine/mongodb-odm": ">=1,<1.0.2", + "doctrine/mongodb-odm-bundle": ">=2,<3.0.1", + "doctrine/orm": ">=2,<2.4.8|>=2.5,<2.5.1", + "dompdf/dompdf": ">=0.6,<0.6.2", + "drupal/core": ">=8,<8.3.7", + "drupal/drupal": ">=8,<8.3.7", + "ezsystems/ezpublish-legacy": ">=5.3,<5.3.12.2|>=5.4,<5.4.10.1|>=2017.8,<2017.8.1.1", + "firebase/php-jwt": "<2", + "friendsofsymfony/rest-bundle": ">=1.2,<1.2.2", + "friendsofsymfony/user-bundle": ">=1.2,<1.3.5", + "gree/jose": "<=2.2", + "gregwar/rst": "<1.0.3", + "guzzlehttp/guzzle": ">=6,<6.2.1|>=4.0.0-rc2,<4.2.4|>=5,<5.3.1", + "illuminate/auth": ">=4,<4.0.99|>=4.1,<4.1.26", + "illuminate/database": ">=4,<4.0.99|>=4.1,<4.1.29", + "joomla/session": "<1.3.1", + "laravel/framework": ">=4,<4.0.99|>=4.1,<4.1.29", + "laravel/socialite": ">=1,<1.0.99|>=2,<2.0.10", + "magento/magento1ce": ">=1.5.0.1,<1.9.3.2", + "magento/magento1ee": ">=1.9,<1.14.3.2", + "magento/magento2ce": ">=2,<2.2", + "monolog/monolog": ">=1.8,<1.12", + "namshi/jose": "<2.2", + "onelogin/php-saml": "<2.10.4", + "oro/crm": ">=1.7,<1.7.4", + "oro/platform": ">=1.7,<1.7.4", + "phpmailer/phpmailer": ">=5,<5.2.24", + "phpunit/phpunit": ">=4.8.19,<4.8.28|>=5.0.10,<5.6.3", + "phpxmlrpc/extras": "<6.0.1", + "pusher/pusher-php-server": "<2.2.1", + "sabre/dav": ">=1.6,<1.6.99|>=1.7,<1.7.11|>=1.8,<1.8.9", + "shopware/shopware": "<5.2.25", + "silverstripe/cms": ">=3,<=3.0.11|>=3.1,<3.1.11", + "silverstripe/forum": "<=0.6.1|>=0.7,<=0.7.3", + "silverstripe/framework": ">=3,<3.3", + "silverstripe/userforms": "<3", + "simplesamlphp/saml2": "<1.8.1|>=1.9,<1.9.1|>=1.10,<1.10.3|>=2,<2.3.3", + "simplesamlphp/simplesamlphp": "<1.14.16", + "simplesamlphp/simplesamlphp-module-infocard": "<1.0.1", + "socalnick/scn-social-auth": "<1.15.2", + "squizlabs/php_codesniffer": ">=1,<2.8.1", + "swiftmailer/swiftmailer": ">=4,<5.4.5", + "symfony/dependency-injection": ">=2,<2.0.17", + "symfony/form": ">=2.3,<2.3.35|>=2.4,<2.6.12|>=2.7,<2.7.38|>=2.8,<2.8.31|>=3,<3.2.14|>=3.3,<3.3.13", + "symfony/framework-bundle": ">=2,<2.3.18|>=2.4,<2.4.8|>=2.5,<2.5.2", + "symfony/http-foundation": ">=2,<2.3.27|>=2.4,<2.5.11|>=2.6,<2.6.6", + "symfony/http-kernel": ">=2,<2.3.29|>=2.4,<2.5.12|>=2.6,<2.6.8", + "symfony/intl": ">=2.7,<2.7.38|>=2.8,<2.8.31|>=3,<3.2.14|>=3.3,<3.3.13", + "symfony/routing": ">=2,<2.0.19", + "symfony/security": ">=2,<2.0.25|>=2.1,<2.1.13|>=2.2,<2.2.9|>=2.3,<2.3.37|>=2.4,<2.6.13|>=2.7,<2.7.9|>=2.7.30,<2.7.32|>=2.8.23,<2.8.25|>=3.2.10,<3.2.12|>=3.3.3,<3.3.5", + "symfony/security-core": ">=2.4,<2.6.13|>=2.7,<2.7.9|>=2.7.30,<2.7.32|>=2.8,<2.8.6|>=2.8.23,<2.8.25|>=3,<3.0.6|>=3.2.10,<3.2.12|>=3.3.3,<3.3.5", + "symfony/security-csrf": ">=2.7,<2.7.38|>=2.8,<2.8.31|>=3,<3.2.14|>=3.3,<3.3.13", + "symfony/security-http": ">=2.3,<2.3.41|>=2.4,<2.7.38|>=2.8,<2.8.31|>=3,<3.2.14|>=3.3,<3.3.13", + "symfony/serializer": ">=2,<2.0.11", + "symfony/symfony": ">=2,<2.3.41|>=2.4,<2.7.38|>=2.8,<2.8.31|>=3,<3.2.14|>=3.3,<3.3.13", + "symfony/translation": ">=2,<2.0.17", + "symfony/validator": ">=2,<2.0.24|>=2.1,<2.1.12|>=2.2,<2.2.5|>=2.3,<2.3.3", + "symfony/web-profiler-bundle": ">=2,<2.3.19|>=2.4,<2.4.9|>=2.5,<2.5.4", + "symfony/yaml": ">=2,<2.0.22|>=2.1,<2.1.7", + "thelia/backoffice-default-template": ">=2.1,<2.1.2", + "thelia/thelia": ">=2.1.0-beta1,<2.1.3|>=2.1,<2.1.2", + "twig/twig": "<1.20", + "typo3/cms": ">=6.2,<6.2.30|>=7,<7.6.22|>=8,<8.7.5", + "typo3/flow": ">=1,<1.0.4|>=1.1,<1.1.1|>=2,<2.0.1|>=2.3,<2.3.16|>=3,<3.0.10|>=3.1,<3.1.7|>=3.2,<3.2.7|>=3.3,<3.3.5", + "typo3/neos": ">=1.1,<1.1.3|>=1.2,<1.2.13|>=2,<2.0.4", + "willdurand/js-translation-bundle": "<2.1.1", + "yiisoft/yii": ">=1.1.14,<1.1.15", + "yiisoft/yii2": "<2.0.5", + "yiisoft/yii2-bootstrap": "<2.0.4", + "yiisoft/yii2-dev": "<2.0.4", + "yiisoft/yii2-gii": "<2.0.4", + "yiisoft/yii2-jui": "<2.0.4", + "zendframework/zend-cache": ">=2.4,<2.4.8|>=2.5,<2.5.3", + "zendframework/zend-captcha": ">=2,<2.4.9|>=2.5,<2.5.2", + "zendframework/zend-crypt": ">=2,<2.4.9|>=2.5,<2.5.2", + "zendframework/zend-db": ">=2,<2.0.99|>=2.1,<2.1.99|>=2.2,<2.2.10|>=2.3,<2.3.5", + "zendframework/zend-diactoros": ">=1,<1.0.4", + "zendframework/zend-form": ">=2,<2.2.7|>=2.3,<2.3.1", + "zendframework/zend-http": ">=2,<2.0.99|>=2.1,<2.1.99|>=2.3,<2.3.8|>=2.4,<2.4.1", + "zendframework/zend-json": ">=2.1,<2.1.6|>=2.2,<2.2.6", + "zendframework/zend-ldap": ">=2,<2.0.99|>=2.1,<2.1.99|>=2.2,<2.2.8|>=2.3,<2.3.3", + "zendframework/zend-mail": ">=2,<2.4.11|>=2.5,<2.7.2", + "zendframework/zend-navigation": ">=2,<2.2.7|>=2.3,<2.3.1", + "zendframework/zend-session": ">=2,<2.0.99|>=2.1,<2.1.99|>=2.2,<2.2.9|>=2.3,<2.3.4", + "zendframework/zend-validator": ">=2.3,<2.3.6", + "zendframework/zend-view": ">=2,<2.2.7|>=2.3,<2.3.1", + "zendframework/zend-xmlrpc": ">=2.1,<2.1.6|>=2.2,<2.2.6", + "zendframework/zendframework": ">=2,<2.4.11|>=2.5,<2.5.1", + "zendframework/zendframework1": "<1.12.20", + "zendframework/zendopenid": ">=2,<2.0.2", + "zendframework/zendxml": ">=1,<1.0.1", + "zetacomponents/mail": "<1.8.2", + "zf-commons/zfc-user": "<1.2.2", + "zfcampus/zf-apigility-doctrine": ">=1,<1.0.3", + "zfr/zfr-oauth2-server-module": "<0.1.2" + }, + "type": "metapackage", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "role": "maintainer" + } + ], + "description": "Prevents installation of composer packages with known security vulnerabilities: no API, simply require it", + "time": "2017-12-24T19:52:27+00:00" + }, + { + "name": "unreal4u/dummy-logger", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/unreal4u/dummyLogger.git", + "reference": "48e049c6e1519a67eee1173e88e8c4c5e969c267" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/unreal4u/dummyLogger/zipball/48e049c6e1519a67eee1173e88e8c4c5e969c267", + "reference": "48e049c6e1519a67eee1173e88e8c4c5e969c267", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/log": "~1.0", + "roave/security-advisories": "dev-master" + }, + "type": "library", + "autoload": { + "psr-4": { + "unreal4u\\Dummy\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Camilo Sperberg", + "email": "me+ghdummylogger@unreal4u.com" + } + ], + "description": "Dummy logger that implements PSR-3 so that my own classes can work with a common base", + "time": "2018-01-02T21:34:48+00:00" + }, { "name": "yoshi2889/collections", "version": "v0.1.6", @@ -3142,7 +3325,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "roave/security-advisories": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Abstracts/TelegramTypes.php b/src/Abstracts/TelegramTypes.php index ce4c982..5ca1206 100644 --- a/src/Abstracts/TelegramTypes.php +++ b/src/Abstracts/TelegramTypes.php @@ -5,7 +5,7 @@ namespace unreal4u\TelegramAPI\Abstracts; use Psr\Log\LoggerInterface; -use unreal4u\TelegramAPI\InternalFunctionality\DummyLogger; +use unreal4u\Dummy\Logger; use unreal4u\TelegramAPI\Telegram\Types\Custom\ResultArray; abstract class TelegramTypes @@ -18,7 +18,7 @@ abstract class TelegramTypes public function __construct(array $data = null, LoggerInterface $logger = null) { if ($logger === null) { - $logger = new DummyLogger(); + $logger = new Logger(); } $this->logger = $logger; diff --git a/src/InternalFunctionality/DummyLogger.php b/src/InternalFunctionality/DummyLogger.php deleted file mode 100644 index 77293d9..0000000 --- a/src/InternalFunctionality/DummyLogger.php +++ /dev/null @@ -1,68 +0,0 @@ -log(LogLevel::EMERGENCY, $message, $context); - } - - public function alert($message, array $context = array()): bool - { - return $this->log(LogLevel::ALERT, $message, $context); - } - - public function critical($message, array $context = array()): bool - { - return $this->log(LogLevel::CRITICAL, $message, $context); - } - - public function error($message, array $context = array()): bool - { - return $this->log(LogLevel::ERROR, $message, $context); - } - - public function warning($message, array $context = array()): bool - { - return $this->log(LogLevel::WARNING, $message, $context); - } - - public function notice($message, array $context = array()): bool - { - return $this->log(LogLevel::NOTICE, $message, $context); - } - - public function info($message, array $context = array()): bool - { - return $this->log(LogLevel::INFO, $message, $context); - } - - public function debug($message, array $context = array()): bool - { - return $this->log(LogLevel::DEBUG, $message, $context); - } - - /** - * @SuppressWarnings("unused") - * @param mixed $level - * @param string $message - * @param array $context - * @return bool - */ - public function log($level, $message, array $context = array()): bool - { - return false; - } -} diff --git a/src/InternalFunctionality/PostOptionsConstructor.php b/src/InternalFunctionality/PostOptionsConstructor.php index 4749190..b3c702e 100644 --- a/src/InternalFunctionality/PostOptionsConstructor.php +++ b/src/InternalFunctionality/PostOptionsConstructor.php @@ -7,6 +7,7 @@ use MultipartBuilder\Builder; use MultipartBuilder\MultipartData; use Psr\Log\LoggerInterface; +use unreal4u\Dummy\Logger; use unreal4u\TelegramAPI\Abstracts\TelegramMethods; use unreal4u\TelegramAPI\Telegram\Types\Custom\InputFile; @@ -30,7 +31,7 @@ class PostOptionsConstructor public function __construct(LoggerInterface $logger = null) { if ($logger === null) { - $logger = new DummyLogger(); + $logger = new Logger(); } $this->logger = $logger; } diff --git a/src/TgLog.php b/src/TgLog.php index 9de73a5..1965932 100644 --- a/src/TgLog.php +++ b/src/TgLog.php @@ -6,8 +6,8 @@ use Psr\Log\LoggerInterface; use React\Promise\PromiseInterface; +use unreal4u\Dummy\Logger; use unreal4u\TelegramAPI\Abstracts\TelegramMethods; -use unreal4u\TelegramAPI\InternalFunctionality\DummyLogger; use unreal4u\TelegramAPI\InternalFunctionality\PostOptionsConstructor; use unreal4u\TelegramAPI\InternalFunctionality\TelegramDocument; use unreal4u\TelegramAPI\InternalFunctionality\TelegramResponse; @@ -64,7 +64,7 @@ public function __construct(string $botToken, RequestHandlerInterface $handler, // Initialize new dummy logger (PSR-3 compatible) if not injected if ($logger === null) { - $logger = new DummyLogger(); + $logger = new Logger(); } $this->logger = $logger; @@ -113,6 +113,8 @@ function (TelegramResponse $rawData) { } /** + * This is the method that actually makes the call, which can be easily overwritten so that our unit tests can work + * * @param TelegramMethods $method * @param array $formData * @@ -148,7 +150,7 @@ final protected function resetObjectValues(): TgLog */ protected function composeApiMethodUrl(TelegramMethods $call): string { - $completeClassName = get_class($call); + $completeClassName = \get_class($call); $this->methodName = substr($completeClassName, strrpos($completeClassName, '\\') + 1); $this->logger->info('About to perform API request', ['method' => $this->methodName]); diff --git a/tests/InternalFunctionality/DummyLoggerTest.php b/tests/InternalFunctionality/DummyLoggerTest.php deleted file mode 100644 index 314fb41..0000000 --- a/tests/InternalFunctionality/DummyLoggerTest.php +++ /dev/null @@ -1,86 +0,0 @@ -dummyLogger = new DummyLogger(); - } - - /** - * Cleans up the environment after running a test. - */ - protected function tearDown() - { - $this->dummyLogger = null; - parent::tearDown(); - } - - public function testEmergency() - { - $result = $this->dummyLogger->emergency('Hello'); - $this->assertFalse($result); - } - - public function testAlert() - { - $result = $this->dummyLogger->alert('Hello'); - $this->assertFalse($result); - } - - public function testCritical() - { - $result = $this->dummyLogger->critical('Hello'); - $this->assertFalse($result); - } - - public function testError() - { - $result = $this->dummyLogger->error('Hello'); - $this->assertFalse($result); - } - - public function testWarning() - { - $result = $this->dummyLogger->warning('Hello'); - $this->assertFalse($result); - } - - public function testNotice() - { - $result = $this->dummyLogger->notice('Hello'); - $this->assertFalse($result); - } - - public function testInfo() - { - $result = $this->dummyLogger->info('Hello'); - $this->assertFalse($result); - } - - public function testDebug() - { - $result = $this->dummyLogger->debug('Hello'); - $this->assertFalse($result); - } - - public function testLog() - { - $result = $this->dummyLogger->log(100, 'Hello'); - $this->assertFalse($result); - } -}