From 824b62cd10f1d9cbe4c35fa0c10ad25bf5d45229 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 2 Sep 2019 17:21:20 +0200 Subject: [PATCH] Fix tests --- src/danog/MadelineProto/API.php | 4 ++-- src/danog/MadelineProto/APIFactory.php | 16 ++++++++-------- src/danog/MadelineProto/Async/AsyncConstruct.php | 5 ++--- src/danog/MadelineProto/MTProtoTools/Files.php | 2 +- tests/testing.php | 9 +-------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 161d771e..dc9b7285 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -197,7 +197,7 @@ class API extends APIFactory Logger::log('Shutting down MadelineProto (normally or due to an exception, idk)'); } $this->destructing = true; - $this->wait($this->serialize()); + Tools::wait($this->serialize()); } //restore_error_handler(); } @@ -285,7 +285,7 @@ class API extends APIFactory public function serialize($filename = null) { - return $this->callFork((function () use ($filename) { + return Tools::callFork((function () use ($filename) { if ($filename === null) { $filename = $this->session; } diff --git a/src/danog/MadelineProto/APIFactory.php b/src/danog/MadelineProto/APIFactory.php index 14f36429..891c5463 100644 --- a/src/danog/MadelineProto/APIFactory.php +++ b/src/danog/MadelineProto/APIFactory.php @@ -120,7 +120,6 @@ class APIFactory extends AsyncConstruct */ public $auth; - use Tools; public $namespace = ''; public $API; public $lua = false; @@ -138,17 +137,18 @@ class APIFactory extends AsyncConstruct public function __call($name, $arguments) { - $yielded = $this->call($this->__call_async($name, $arguments)); + $yielded = Tools::call($this->__call_async($name, $arguments)); $async = $this->lua === false && (\is_array(\end($arguments)) && isset(\end($arguments)['async']) ? \end($arguments)['async'] : ($this->async && $name !== 'loop')); + if ($async) { return $yielded; } if (!$this->lua) { - return $this->wait($yielded); + return Tools::wait($yielded); } try { - $yielded = $this->wait($yielded); + $yielded = Tools::wait($yielded); Lua::convert_objects($yielded); return $yielded; @@ -203,7 +203,7 @@ class APIFactory extends AsyncConstruct public function &__get($name) { if ($this->asyncAPIPromise) { - $this->wait($this->asyncAPIPromise); + Tools::wait($this->asyncAPIPromise); } if ($name === 'settings') { $this->API->flushSettings = true; @@ -220,7 +220,7 @@ class APIFactory extends AsyncConstruct public function __set($name, $value) { if ($this->asyncAPIPromise) { - $this->wait($this->asyncAPIPromise); + Tools::wait($this->asyncAPIPromise); } if ($name === 'settings') { if ($this->API->asyncInitPromise) { @@ -236,7 +236,7 @@ class APIFactory extends AsyncConstruct public function __isset($name) { if ($this->asyncAPIPromise) { - $this->wait($this->asyncAPIPromise); + Tools::wait($this->asyncAPIPromise); } return isset($this->API->storage[$name]); @@ -245,7 +245,7 @@ class APIFactory extends AsyncConstruct public function __unset($name) { if ($this->asyncAPIPromise) { - $this->wait($this->asyncAPIPromise); + Tools::wait($this->asyncAPIPromise); } unset($this->API->storage[$name]); } diff --git a/src/danog/MadelineProto/Async/AsyncConstruct.php b/src/danog/MadelineProto/Async/AsyncConstruct.php index bea986d7..7d08c7ed 100644 --- a/src/danog/MadelineProto/Async/AsyncConstruct.php +++ b/src/danog/MadelineProto/Async/AsyncConstruct.php @@ -29,13 +29,12 @@ use danog\MadelineProto\Tools; */ class AsyncConstruct { - use Tools; public $asyncInitPromise; public function init() { if ($this->asyncInitPromise) { - $this->wait($this->asyncInitPromise); + Tools::wait($this->asyncInitPromise); } } @@ -48,7 +47,7 @@ class AsyncConstruct public function setInitPromise($promise) { - $this->asyncInitPromise = $this->callFork($promise); + $this->asyncInitPromise = Tools::callFork($promise); $this->asyncInitPromise->onResolve(function ($error, $result) { if ($error) { throw $error; diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 96aca496..00a1cd1e 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -80,7 +80,7 @@ trait Files $mime = $this->get_mime_from_file($file); try { - return yield $this->upload_from_stream_async($stream, $size, $stream, $mime, $cb, $encrypted); + return yield $this->upload_from_stream_async($stream, $size, $mime, $file_name, $cb, $encrypted); } finally { yield $stream->close(); } diff --git a/tests/testing.php b/tests/testing.php index 388d0d7f..3c3da0d3 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -50,6 +50,7 @@ echo 'Loading MadelineProto...'.PHP_EOL; $MadelineProto = new \danog\MadelineProto\API(\getcwd().'/testing.madeline', $settings); $MadelineProto->fileGetContents('https://google.com'); $MadelineProto->start(); +$MadelineProto->async(false); try { $MadelineProto->get_self(); @@ -59,14 +60,6 @@ try { } } - $inputMediaUploadedPhoto1 = ['_' => 'inputMediaUploadedPhoto','file' => '1.jpg']; - $inputMediaUploadedPhoto2 = ['_' => 'inputMediaUploadedPhoto','file' => '2.jpg']; - $inputMediaUploadedPhoto3 = ['_' => 'inputMediaUploadedPhoto','file' => '3.jpg']; - $inputSingleMedia1 = ['_' => 'inputSingleMedia', 'media' => $inputMediaUploadedPhoto1, 'message' => 'str']; - $inputSingleMedia2 = ['_' => 'inputSingleMedia', 'media' => $inputMediaUploadedPhoto2, 'message' => 'str']; - $inputSingleMedia3 = ['_' => 'inputSingleMedia', 'media' => $inputMediaUploadedPhoto3, 'message' => 'str']; - $Updates = $this->messages->sendMultiMedia(['peer' => 'danogentili','multi_media' => [$inputSingleMedia3, $inputSingleMedia2,$inputSingleMedia1]]); - //var_dump(count($MadelineProto->get_pwr_chat('@madelineproto')['participants'])); /*