Improve tests and conversion
This commit is contained in:
parent
bc17422418
commit
103c774236
1
.gitignore
vendored
1
.gitignore
vendored
@ -121,3 +121,4 @@ phpunit.xml
|
||||
vendor
|
||||
.php_cs.cache
|
||||
coverage
|
||||
tempConv
|
||||
|
@ -41,7 +41,7 @@
|
||||
"phpunit/phpunit": "^8",
|
||||
"amphp/php-cs-fixer-config": "dev-master",
|
||||
"haydenpierce/class-finder": "^0.4",
|
||||
"ext-ctype":"*",
|
||||
"ext-ctype": "*",
|
||||
"danog/7to70": "^1",
|
||||
"danog/7to5": "^1"
|
||||
},
|
||||
@ -63,12 +63,10 @@
|
||||
"src/polyfill.php"
|
||||
]
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/danog/dns"
|
||||
}
|
||||
],
|
||||
"repositories": [{
|
||||
"type": "git",
|
||||
"url": "https://github.com/danog/dns"
|
||||
}],
|
||||
"scripts": {
|
||||
"build": [
|
||||
"@docs",
|
||||
@ -78,9 +76,12 @@
|
||||
"@cs",
|
||||
"@test"
|
||||
],
|
||||
"prepare-convert": "rm -rf tempConv && mkdir tempConv",
|
||||
"test-php7": "tests/test-conversion.sh 70",
|
||||
"test-php56": "tests/test-conversion.sh 5",
|
||||
"cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff --dry-run",
|
||||
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --diff",
|
||||
"docs": "php tools/build_docs.php",
|
||||
"test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit --coverage-text"
|
||||
}
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
|
||||
namespace phpseclib\Math;
|
||||
|
||||
if (PHP_MAJOR_VERSION < 7 && !(\class_exists(\Phar::class) && \Phar::running())) {
|
||||
if (PHP_MAJOR_VERSION < 7 && !((\class_exists(\Phar::class) && \Phar::running()) || defined('TESTING_VERSIONS'))) {
|
||||
throw new \Exception('MadelineProto requires php 7 to run natively, use phar.madelineproto.xyz to run on PHP 5.6');
|
||||
}
|
||||
if (\defined('HHVM_VERSION')) {
|
||||
|
@ -78,7 +78,11 @@ class Exception extends \Exception
|
||||
public static function exceptionErrorHandler($errno = 0, $errstr = null, $errfile = null, $errline = null)
|
||||
{
|
||||
// If error is suppressed with @, don't throw an exception
|
||||
if (\error_reporting() === 0 || \strpos($errstr, 'headers already sent') || ($errfile && \strpos($errfile, 'vendor/amphp') !== false)) {
|
||||
if (\error_reporting() === 0
|
||||
|| \strpos($errstr, 'headers already sent')
|
||||
|| ($errfile
|
||||
&& (\strpos($errfile, 'vendor/amphp') !== false || \strpos($errfile, 'vendor/league') !== false))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ use danog\MadelineProto\Stream\RawStreamInterface;
|
||||
*
|
||||
* @author Daniil Gentili <daniil@daniil.it>
|
||||
*/
|
||||
class PremadeStream extends Socket implements RawStreamInterface, ProxyStreamInterface
|
||||
class PremadeStream implements RawStreamInterface, ProxyStreamInterface
|
||||
{
|
||||
use RawStream;
|
||||
private $stream;
|
||||
|
@ -38,3 +38,10 @@ if (!\function_exists('error_clear_last')) {
|
||||
if (!\defined('MADELINEPROTO_TEST')) {
|
||||
\define('MADELINEPROTO_TEST', 'NOT PONY');
|
||||
}
|
||||
trait MyCallableMaker
|
||||
{
|
||||
use \Amp\CallableMaker {
|
||||
callableFromInstanceMethod as public;
|
||||
callableFromStaticMethod as public;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ composer config platform.php "7.4"
|
||||
[ $PHP_MAJOR_VERSION -eq 5 ] && composer require dstuecken/php7ify
|
||||
composer clearcache
|
||||
composer update
|
||||
composer dumpautoload --optimize
|
||||
cp -a $madelinePath/src vendor/danog/madelineproto/
|
||||
cd ..
|
||||
|
||||
@ -51,13 +52,17 @@ cd ..
|
||||
sudo apt-get update -q
|
||||
sudo apt-get install php7.3-cli php7.3-json php7.3-mbstring php7.3-curl php7.3-xml php7.3-json -y
|
||||
|
||||
composer global require spatie/7to5 dev-master#0420ad3
|
||||
composer global require danog/7to5
|
||||
[ -f $HOME/.composer/vendor/bin/php7to5 ] && php7to5=$HOME/.composer/vendor/bin/php7to5
|
||||
[ -f $HOME/.config/composer/vendor/bin/php7to5 ] && php7to5=$HOME/.config/composer/vendor/bin/php7to5
|
||||
|
||||
find phar7/vendor/league/uri -type f -name '*.php' -exec sed 's/withScheme[(]\$scheme[)]: UriInterface/withScheme(?string $scheme): UriInterface/g' -i {} +
|
||||
|
||||
|
||||
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i vendor/league/uri-interfaces/src/Contracts/UriInterface.php
|
||||
while IFS= read -r line; do l=$(echo "$line" | sed 's/[(].*//g'); sed -i "s/$l.*/$line/g" vendor/league/uri/src/Uri.php; done <<< $(grep 'public function' vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g')
|
||||
|
||||
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
|
||||
|
||||
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php vendor/amphp/http-client/src/Connection/Http{2,1}Connection.php
|
||||
|
||||
php7.3 $php7to5 convert --copy-all phar7 phar5 >/dev/null
|
||||
|
||||
sed 's/^Loop::set.*;//g' -i phar5/vendor/amphp/amp/lib/Loop.php
|
||||
@ -71,6 +76,16 @@ cd ..
|
||||
|
||||
find phar5/vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i {} +
|
||||
|
||||
sed 's/use Kelunik\\Certificate\\Certificate/use Kelunik\Certificate\Certificate as _Certificate/g;s/new Certificate/new _Certificate/g' -i vendor/amphp/socket/src/TlsInfo.php
|
||||
|
||||
echo "<?php
|
||||
|
||||
namespace League\Uri\Contracts;
|
||||
|
||||
interface UriException
|
||||
{
|
||||
}" > vendor/league/uri-interfaces/src/Contracts/UriException.php
|
||||
|
||||
php -v
|
||||
|
||||
php=5
|
||||
@ -81,7 +96,12 @@ cd ..
|
||||
[ -f $HOME/.composer/vendor/bin/php7to70 ] && php7to70=$HOME/.composer/vendor/bin/php7to70
|
||||
[ -f $HOME/.config/composer/vendor/bin/php7to70 ] && php7to70=$HOME/.config/composer/vendor/bin/php7to70
|
||||
|
||||
find phar7/vendor/league/uri -type f -name '*.php' -exec sed 's/withScheme[(]\$scheme[)]: UriInterface/withScheme(?string $scheme): UriInterface/g' -i {} +
|
||||
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i vendor/league/uri-interfaces/src/Contracts/UriInterface.php
|
||||
while IFS= read -r line; do l=$(echo "$line" | sed 's/[(].*//g'); sed -i "s/$l.*/$line/g" vendor/league/uri/src/Uri.php; done <<< $(grep 'public function' vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g')
|
||||
|
||||
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
|
||||
|
||||
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php vendor/amphp/http-client/src/Connection/Http{2,1}Connection.php
|
||||
|
||||
$php7to70 convert --copy-all phar7 phar5 >/dev/null
|
||||
|
||||
|
@ -1,40 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
composer global require spatie/7to5 dev-master#b20463417bcd2c9d141a5733c6e649b6c468beee
|
||||
|
||||
[ -f $HOME/.composer/vendor/bin/php7to5 ] && php7to5=$HOME/.composer/vendor/bin/php7to5
|
||||
[ -f $HOME/.config/composer/vendor/bin/php7to5 ] && php7to5=$HOME/.config/composer/vendor/bin/php7to5
|
||||
|
||||
rm -rf phar7 phar5 MadelineProtoPhar
|
||||
|
||||
mkdir phar7
|
||||
cd phar7
|
||||
echo '{
|
||||
"name": "danog/madelineprototests",
|
||||
"minimum-stability":"dev",
|
||||
"require": {
|
||||
"danog/madelineproto": "dev-master",
|
||||
"amphp/dns": "dev-master#ecbeca2ae0e93c08e8150a92810a3961fad8ecbe as v1"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniil Gentili",
|
||||
"email": "daniil@daniil.it"
|
||||
}
|
||||
]
|
||||
}' > composer.json
|
||||
composer update
|
||||
cp -a ../src vendor/danog/madelineproto
|
||||
cd ..
|
||||
|
||||
#cp -a phar7 phar5
|
||||
$php7to5 convert --copy-all phar7 phar5 >/dev/null
|
||||
find phar5 -type f -exec sed 's/\w* \.\.\./.../' -i {} +
|
||||
sed 's/^Loop::set.*;//g' -i phar5/vendor/amphp/amp/lib/Loop.php
|
||||
echo 'Loop::set((new DriverFactory())->create());' >> phar5/vendor/amphp/amp/lib/Loop.php
|
||||
cp phar5/vendor/danog/madelineproto/src/danog/MadelineProto/Coroutine.php phar5/vendor/amphp/amp/lib/
|
||||
sed -i 's/namespace danog\\MadelineProto;//g' phar5/vendor/amphp/amp/lib/Coroutine.php
|
||||
|
||||
|
||||
php tools/makephar.php phar5 madeline.phar $(cat .git/refs/heads/master)
|
||||
|
@ -162,18 +162,18 @@ if (!\is_callable('random_bytes')) {
|
||||
return \serialize($arr);
|
||||
}
|
||||
// prevent circular array recursion
|
||||
if (isset($arr['__phpseclib_marker'])) {
|
||||
if (isset($arr['__tgseclib_marker'])) {
|
||||
return '';
|
||||
}
|
||||
$safearr = [];
|
||||
$arr['__phpseclib_marker'] = true;
|
||||
$arr['__tgseclib_marker'] = true;
|
||||
foreach (\array_keys($arr) as $key) {
|
||||
// do not recurse on the '__phpseclib_marker' key itself, for smaller memory usage
|
||||
if ($key !== '__phpseclib_marker') {
|
||||
// do not recurse on the '__tgseclib_marker' key itself, for smaller memory usage
|
||||
if ($key !== '__tgseclib_marker') {
|
||||
$safearr[$key] = safe_serialize($arr[$key]);
|
||||
}
|
||||
}
|
||||
unset($arr['__phpseclib_marker']);
|
||||
unset($arr['__tgseclib_marker']);
|
||||
return \serialize($safearr);
|
||||
}
|
||||
/**
|
||||
@ -236,23 +236,23 @@ if (!\is_callable('random_bytes')) {
|
||||
//
|
||||
// http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Designs_based_on_cryptographic_primitives
|
||||
switch (true) {
|
||||
case \class_exists('\\phpseclib\\Crypt\\AES'):
|
||||
$crypto = new \phpseclib\Crypt\AES('ctr');
|
||||
case \class_exists('\\tgseclib\\Crypt\\AES'):
|
||||
$crypto = new \tgseclib\Crypt\AES('ctr');
|
||||
break;
|
||||
case \class_exists('\\phpseclib\\Crypt\\Twofish'):
|
||||
$crypto = new \phpseclib\Crypt\Twofish('ctr');
|
||||
case \class_exists('\\tgseclib\\Crypt\\Twofish'):
|
||||
$crypto = new \tgseclib\Crypt\Twofish('ctr');
|
||||
break;
|
||||
case \class_exists('\\phpseclib\\Crypt\\Blowfish'):
|
||||
$crypto = new \phpseclib\Crypt\Blowfish('ctr');
|
||||
case \class_exists('\\tgseclib\\Crypt\\Blowfish'):
|
||||
$crypto = new \tgseclib\Crypt\Blowfish('ctr');
|
||||
break;
|
||||
case \class_exists('\\phpseclib\\Crypt\\TripleDES'):
|
||||
$crypto = new \phpseclib\Crypt\TripleDES('ctr');
|
||||
case \class_exists('\\tgseclib\\Crypt\\TripleDES'):
|
||||
$crypto = new \tgseclib\Crypt\TripleDES('ctr');
|
||||
break;
|
||||
case \class_exists('\\phpseclib\\Crypt\\DES'):
|
||||
$crypto = new \phpseclib\Crypt\DES('ctr');
|
||||
case \class_exists('\\tgseclib\\Crypt\\DES'):
|
||||
$crypto = new \tgseclib\Crypt\DES('ctr');
|
||||
break;
|
||||
case \class_exists('\\phpseclib\\Crypt\\RC4'):
|
||||
$crypto = new \phpseclib\Crypt\RC4();
|
||||
case \class_exists('\\tgseclib\\Crypt\\RC4'):
|
||||
$crypto = new \tgseclib\Crypt\RC4();
|
||||
break;
|
||||
default:
|
||||
throw new \RuntimeException(__CLASS__ . ' requires at least one symmetric cipher be loaded');
|
||||
|
81
tests/test-conversion.sh
Executable file
81
tests/test-conversion.sh
Executable file
@ -0,0 +1,81 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
madelinePath=$PWD
|
||||
|
||||
rm -rf /tmp/tempConv
|
||||
mkdir /tmp/tempConv
|
||||
cd /tmp/tempConv
|
||||
|
||||
echo '{
|
||||
"name": "danog/madelineprototests",
|
||||
"minimum-stability":"dev",
|
||||
"require": {
|
||||
"danog/madelineproto": "dev-master",
|
||||
"amphp/dns": "dev-master#ecbeca2ae0e93c08e8150a92810a3961fad8ecbe as v1"
|
||||
},
|
||||
"require-dev": {
|
||||
"vlucas/phpdotenv": "^3"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "'$madelinePath'",
|
||||
"options": {
|
||||
"symlink": false
|
||||
}
|
||||
}
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Daniil Gentili",
|
||||
"email": "daniil@daniil.it"
|
||||
}
|
||||
]
|
||||
}' > composer.json
|
||||
composer update
|
||||
|
||||
|
||||
rm -rf vendor/danog/madelineproto/docs
|
||||
|
||||
sed -re 's/\?(\w*) (\$\w+)/\2 = NULL/g;s/= null = null/=null/ig;s/: self//g' -i vendor/league/uri-interfaces/src/Contracts/UriInterface.php
|
||||
while IFS= read -r line; do l=$(echo "$line" | sed 's/[(].*//g'); sed -i "s/$l.*/$line/g" vendor/league/uri/src/Uri.php; done <<< $(grep 'public function' vendor/league/uri-interfaces/src/Contracts/UriInterface.php | sed 's/;//g;s/: self//g')
|
||||
|
||||
sed -i 's/handleConnectionWindowIncrement[(]\$windowSize[)]/handleConnectionWindowIncrement(int $windowSize)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php
|
||||
|
||||
sed -ri 's/^\{/{ use \\MyCallableMaker;/g;s/\\Closure::fromCallable[(]\[(.+), (.+)\][)]/\1->callableFromInstanceMethod(\2)/g' vendor/amphp/http-client/src/Connection/Internal/Http2ConnectionProcessor.php vendor/amphp/http-client/src/Connection/Http{2,1}Connection.php
|
||||
|
||||
$madelinePath/vendor/bin/php7to$1 convert --copy-all vendor newVendor
|
||||
rm -rf vendor
|
||||
mv newVendor vendor
|
||||
|
||||
[ $1 -eq 5 ] && {
|
||||
sed 's/^Loop::set.*;//g' -i vendor/amphp/amp/lib/Loop.php
|
||||
echo 'Loop::set((new DriverFactory())->create());' >> vendor/amphp/amp/lib/Loop.php
|
||||
cp $madelinePath/tests/random.php vendor/paragonie/random_compat/lib/random.php
|
||||
cp vendor/danog/madelineproto/src/danog/MadelineProto/Coroutine.php vendor/amphp/amp/lib/Coroutine.php
|
||||
sed 's/namespace danog\\MadelineProto;/namespace Amp;/g' -i vendor/amphp/amp/lib/Coroutine.php
|
||||
sed 's/public static function echo/public static function echo_/g' -i vendor/danog/madelineproto/src/danog/MadelineProto/Tools.php
|
||||
|
||||
sed 's/use Kelunik\\Certificate\\Certificate/use Kelunik\Certificate\Certificate as _Certificate/g;s/new Certificate/new _Certificate/g;s/empty[(]\$metadata[)] [?] null : //g' -i vendor/amphp/socket/src/TlsInfo.php
|
||||
|
||||
echo "<?php
|
||||
|
||||
namespace League\Uri\Contracts;
|
||||
|
||||
interface UriException
|
||||
{
|
||||
}" > vendor/league/uri-interfaces/src/Contracts/UriException.php
|
||||
|
||||
}
|
||||
find vendor/amphp -type f -name '*.php' -exec sed "s/extension_loaded[(]'zlib'[)]/false/g;s/new[(]/new_(/g;s/clone[(]/clone_(/g" -i {} +
|
||||
|
||||
find vendor/danog/madelineproto -type f -name '*.php' -exec sed 's/: EncryptableSocket/: \\Amp\\Socket\\Socket/g' -i {} +
|
||||
|
||||
composer dumpautoload --optimize
|
||||
|
||||
cd $madelinePath
|
||||
if [ $1 -eq 5 ];then
|
||||
php5.6 tests/testing.php
|
||||
else
|
||||
php7.0 tests/testing.php
|
||||
fi
|
@ -16,20 +16,34 @@ If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
$loader = false;
|
||||
if (!\file_exists(__DIR__.'/../vendor/autoload.php')) {
|
||||
echo 'You did not run composer update, using madeline.php'.PHP_EOL;
|
||||
if ($phar = \getenv('TRAVIS_PHAR')) {
|
||||
include $phar;
|
||||
$loader = include $phar;
|
||||
} else {
|
||||
if (!\file_exists('madeline.php')) {
|
||||
\copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
|
||||
}
|
||||
include 'madeline.php';
|
||||
}
|
||||
} elseif (\file_exists('/tmp/tempConv/vendor/autoload.php')) {
|
||||
\define('TESTING_VERSIONS', 1);
|
||||
$loader = require_once('/tmp/tempConv/vendor/autoload.php');
|
||||
} else {
|
||||
require_once 'vendor/autoload.php';
|
||||
}
|
||||
|
||||
if ($loader) {
|
||||
foreach ($loader->getClassMap() as $class => $file) {
|
||||
if (\in_array($class, ['Amp\\Sync\\Internal\\MutexStorage', 'Amp\\Sync\\Internal\\SemaphoreStorage', 'Amp\\Parallel\\Sync\\Internal\\ParcelStorage', 'Amp\\Parallel\\Context\\Internal\\Thread'])) {
|
||||
continue;
|
||||
}
|
||||
echo "Requiring $class => $file\n";
|
||||
require_once($file);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Load .env for settings
|
||||
*/
|
||||
|
@ -38,6 +38,6 @@ if ($contents = file_get_contents("https://phar.madelineproto.xyz/phar.php?v=new
|
||||
|
||||
Phar::interceptFileFuncs();
|
||||
Phar::mapPhar("'.$argv[2].'");
|
||||
require_once "phar://'.$argv[2].'/vendor/autoload.php";
|
||||
return require_once "phar://'.$argv[2].'/vendor/autoload.php";
|
||||
|
||||
__HALT_COMPILER(); ?>');
|
||||
|
@ -90,4 +90,4 @@ function ___install_madeline()
|
||||
|
||||
___install_madeline();
|
||||
|
||||
require 'madeline.phar';
|
||||
return require_once 'madeline.phar';
|
||||
|
Loading…
Reference in New Issue
Block a user