Skip to content

Commit

Permalink
Merge pull request #257 from cryptounifier/php-80-test-passing
Browse files Browse the repository at this point in the history
Support PHP 8.0
  • Loading branch information
sc0Vu authored Mar 7, 2022
2 parents bd40f19 + cc7d01e commit 2eafffb
Show file tree
Hide file tree
Showing 57 changed files with 87 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: PHP

on: ["push", "pull_request"]
on: ["push", "pull_request", "workflow_dispatch"]

jobs:
build_and_test:
name: Build and test web3.php with ${{ matrix.php-version }}
strategy:
matrix:
php-version: ["7.3", "7.4"]
php-version: ["7.3", "7.4", "8.0"]

runs-on: ubuntu-latest

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
],
"require": {
"guzzlehttp/guzzle": "^6.3|^7.0",
"PHP": "^7.1",
"PHP": "^7.2|^8.0",
"kornrunner/keccak": "~1.0",
"phpseclib/phpseclib": "~2.0.11",
"phpseclib/phpseclib": "~2.0.30",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "~6.0"
"phpunit/phpunit": "~8.0|~9.0"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 23 additions & 0 deletions docker/php/Dockerfile-80
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM php:8.0-alpine

MAINTAINER Peter Lai <[email protected]>

COPY composer-setup.php composer-setup.php
# COPY php.ini-production $PHP_INI_DIR/php.ini

RUN apk update && \
apk add git

# Install gmp
Run apk add gmp-dev && \
docker-php-ext-install gmp

# Install nodejs
# Run apk add --update nodejs nodejs-npm

# Install composer
RUN php composer-setup.php && \
php composer-setup.php --install-dir=/usr/bin --filename=composer && \
php -r "unlink('composer-setup.php');"

WORKDIR /app
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">

<testsuite name="Web3.php unit test">
<directory suffix="Test.php">./test/unit</directory>
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public static function toBn($number)
$number = str_replace('-', '', $number, $count);
$negative1 = new BigNumber(-1);
}
if (self::isZeroPrefixed($number) || preg_match('/[a-f]+/', $number) === 1) {
if (self::isZeroPrefixed($number) || preg_match('/^[0-9a-f]+$/i', $number) === 1) {
$number = self::stripZero($number);
$bn = new BigNumber($number, 16);
} elseif (empty($number)) {
Expand Down
10 changes: 3 additions & 7 deletions test/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ class TestCase extends BaseTestCase

/**
* setUp
*
* @return void
*/
public function setUp()
public function setUp(): void
{
$web3 = new Web3($this->testHost);
$this->web3 = $web3;
Expand All @@ -55,8 +53,6 @@ public function setUp()

/**
* tearDown
*
* @return void
*/
public function tearDown() {}
}
public function tearDown(): void {}
}
2 changes: 1 addition & 1 deletion test/unit/AddressFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AddressFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new AddressFormatter;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/AddressTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AddressTypeTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->solidityType = new Address;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/AddressValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AddressValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new AddressValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BigNumberFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BigNumberFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new BigNumberFormatter;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BlockHashValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BlockHashValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new BlockHashValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BooleanFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BooleanFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new BooleanFormatter;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BooleanTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BooleanTypeTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->solidityType = new Boolean;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BooleanValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BooleanValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new BooleanValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BytesTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BytesTypeTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->solidityType = new Bytes;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/CallValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CallValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new CallValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ContractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class ContractTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/DynamicBytesTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DynamicBytesTypeTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->solidityType = new DynamicBytes;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/EthApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EthApiTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/EthBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EthBatchTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/EthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EthTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/EthabiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class EthabiTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
// Error: Using $this when not in object context
Expand Down
2 changes: 1 addition & 1 deletion test/unit/FilterValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FilterValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new FilterValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/HexFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HexFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new HexFormatter;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/HexValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class HexValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new HexValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/IdentityValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IdentityValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new IdentityValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/IntegerFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class IntegerFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new IntegerFormatter;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/IntegerTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class IntegerTypeTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->solidityType = new Integer;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/NetApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NetApiTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/NetBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class NetBatchTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/NetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NetTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/NonceValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NonceValidatorTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->validator = new NonceValidator;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/NumberFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NumberFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new NumberFormatter;
Expand Down
6 changes: 4 additions & 2 deletions test/unit/OptionalQuantityFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class OptionalQuantityFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new OptionalQuantityFormatter;
Expand Down Expand Up @@ -55,6 +55,8 @@ public function testFormat()
$this->assertEquals('latest', $formatter->format('latest'));
$this->assertEquals('earliest', $formatter->format('earliest'));
$this->assertEquals('pending', $formatter->format('pending'));
$this->assertEquals('0x0', $formatter->format('hello'));

$this->expectExceptionMessage('toBn number must be valid hex string.');
$formatter->format('hello');
}
}
2 changes: 1 addition & 1 deletion test/unit/PersonalApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PersonalApiTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/PersonalBatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PersonalBatchTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/PersonalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PersonalTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion test/unit/PostFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class PostFormatterTest extends TestCase
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
$this->formatter = new PostFormatter;
Expand Down
Loading

0 comments on commit 2eafffb

Please sign in to comment.