Skip to content

Commit

Permalink
Merge branch 'apache:master' into akuhn/python_3_type_hints
Browse files Browse the repository at this point in the history
  • Loading branch information
arkuhn committed Feb 24, 2024
2 parents 93d250d + 3b1c30c commit 9e01199
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 117 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -76,6 +76,62 @@ jobs:
path: compiler/cpp/thrift
retention-days: 3

lib-php:
needs: compiler
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, xml

- name: Install Dependencies
run: composer install

- name: Backward compatibility for unit test in php greater then 7.1
if: matrix.php-version > 7.0
run: |
sed -i 's/setUp()/setUp():void/' lib/php/test/Unit/*Test.php
sed -i 's/setUpBeforeClass()/setUpBeforeClass():void/' lib/php/test/Unit/*Test.php
- name: Run bootstrap
run: ./bootstrap.sh

- name: Run configure
run: |
./configure $(echo $CONFIG_ARGS_FOR_LIBS | sed 's/without-php/with-php/' | sed 's/without-php_extension/with-php_extension/' )
- uses: actions/download-artifact@v3
with:
name: thrift-compiler
path: compiler/cpp

- name: Run thrift-compiler
run: |
chmod a+x compiler/cpp/thrift
compiler/cpp/thrift -version
- name: Build Thrift Classes
run: |
mkdir -p ./lib/php/test/Resources/packages/php
mkdir -p ./lib/php/test/Resources/packages/phpv
mkdir -p ./lib/php/test/Resources/packages/phpvo
mkdir -p ./lib/php/test/Resources/packages/phpjs
compiler/cpp/thrift --gen php -r --out ./lib/php/test/Resources/packages/php lib/php/test/Resources/ThriftTest.thrift
compiler/cpp/thrift --gen php:validate -r --out ./lib/php/test/Resources/packages/phpv lib/php/test/Resources/ThriftTest.thrift
compiler/cpp/thrift --gen php:validate,oop -r --out ./lib/php/test/Resources/packages/phpvo lib/php/test/Resources/ThriftTest.thrift
compiler/cpp/thrift --gen php:json -r --out ./lib/php/test/Resources/packages/phpjs lib/php/test/Resources/ThriftTest.thrift
- name: Run Tests
run: vendor/bin/phpunit -c lib/php/phpunit.xml

lib-go:
needs: compiler
runs-on: ubuntu-20.04
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/pypi.yml
@@ -0,0 +1,51 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

name: "PyPI publishing"

on:
release:
types: [published]

jobs:
pypi-publish:
name: Publish release to PyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Build
run: |
cd lib/py
python setup.py sdist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: lib/py/dist/
5 changes: 2 additions & 3 deletions .gitignore
Expand Up @@ -279,9 +279,8 @@ project.lock.json
/lib/php/src/ext/thrift_protocol/run-tests.php
/lib/php/src/ext/thrift_protocol/thrift_protocol.la
/lib/php/src/ext/thrift_protocol/tmp-php.ini
/lib/php/src/packages/
/lib/php/test/TEST-*.xml
/lib/php/test/packages/
/lib/php/tests/Resources/packages/
/lib/php/test/test-log-junit.xml
/lib/py/dist/
/lib/erl/logs/
/lib/go/pkg
Expand Down
5 changes: 5 additions & 0 deletions build/docker/ubuntu-bionic/Dockerfile
Expand Up @@ -216,9 +216,14 @@ RUN apt-get install -y --no-install-recommends \
php-dev \
php-json \
php-pear \
php-mbstring \
php-xml \
re2c \
composer

RUN pecl install xdebug-3.1.1 && \
echo "zend_extension=xdebug.so" > /etc/php/7.2/cli/conf.d/20-xdebug.ini

RUN apt-get install -y --no-install-recommends \
`# Python dependencies` \
python-all \
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -21,8 +21,10 @@
"php": "^5.5 || ^7.0 || ^8.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8.36",
"squizlabs/php_codesniffer": "3.*"
"phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.5 || ^9.3",
"squizlabs/php_codesniffer": "3.*",
"ext-json": "*",
"ext-xml": "*"
},
"autoload": {
"psr-4": {"Thrift\\": "lib/php/lib/"}
Expand Down
3 changes: 2 additions & 1 deletion lib/php/README.apache.md
Expand Up @@ -29,7 +29,7 @@ you must use a THttpClient transport.

Sample Code
===========

```php
<?php

namespace MyNamespace;
Expand Down Expand Up @@ -72,3 +72,4 @@ $protocol = new TBinaryProtocol($transport);
$transport->open();
$processor->process($protocol, $protocol);
$transport->close();
```
42 changes: 42 additions & 0 deletions lib/php/phpunit.xml
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="../../vendor/autoload.php"
cacheResult="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnWarning="true"
stopOnFailure="true"
processIsolation="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
<directory suffix=".php">./lib</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Thrift PHP Test Suite">
<directory>./test/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
Expand Up @@ -21,7 +21,7 @@
* @package thrift.test
*/

namespace Test\Thrift;
namespace Test\Thrift\Fixtures;

use ThriftTest\Xtruct;
use ThriftTest\Xtruct2;
Expand Down
Expand Up @@ -21,7 +21,7 @@
* @package thrift.test
*/

namespace Test\Thrift\Protocol;
namespace Test\Thrift\Fixtures;

class TJSONProtocolFixtures
{
Expand Down
Expand Up @@ -21,7 +21,7 @@
* @package thrift.test
*/

namespace test\Thrift\Protocol;
namespace Test\Thrift\Fixtures;

class TSimpleJSONProtocolFixtures
{
Expand Down
37 changes: 13 additions & 24 deletions lib/php/test/Makefile.am
Expand Up @@ -19,37 +19,26 @@

PHPUNIT=php $(top_srcdir)/vendor/bin/phpunit

stubs: ../../../test/v0.16/ThriftTest.thrift TestValidators.thrift
mkdir -p ./packages/php
$(THRIFT) --gen php -r --out ./packages/php ../../../test/v0.16/ThriftTest.thrift
mkdir -p ./packages/phpv
mkdir -p ./packages/phpvo
mkdir -p ./packages/phpjs
$(THRIFT) --gen php:validate -r --out ./packages/phpv TestValidators.thrift
$(THRIFT) --gen php:validate,oop -r --out ./packages/phpvo TestValidators.thrift
$(THRIFT) --gen php:json -r --out ./packages/phpjs TestValidators.thrift
stubs: Resources/ThriftTest.thrift
mkdir -p ./Resources/packages/php
mkdir -p ./Resources/packages/phpv
mkdir -p ./Resources/packages/phpvo
mkdir -p ./Resources/packages/phpjs
$(THRIFT) --gen php -r --out ./Resources/packages/php Resources/ThriftTest.thrift
$(THRIFT) --gen php:validate -r --out ./Resources/packages/phpv Resources/ThriftTest.thrift
$(THRIFT) --gen php:validate,oop -r --out ./Resources/packages/phpvo Resources/ThriftTest.thrift
$(THRIFT) --gen php:json -r --out ./Resources/packages/phpjs Resources/ThriftTest.thrift

deps: $(top_srcdir)/composer.json
composer install --working-dir=$(top_srcdir)

all-local: deps

check-json-serializer: deps stubs
$(PHPUNIT) --log-junit=TEST-log-json-serializer.xml JsonSerialize/

check-validator: deps stubs
$(PHPUNIT) --log-junit=TEST-log-validator.xml Validator/

check-protocol: deps stubs
$(PHPUNIT) --log-junit=TEST-log-protocol.xml Protocol/

check: deps stubs \
check-protocol \
check-validator \
check-json-serializer
check: deps stubs
$(PHPUNIT) --log-junit=test-log-junit.xml -c phpunit.xml /

distclean-local:

clean-local:
$(RM) -r ./packages
$(RM) TEST-*.xml
$(RM) -r ./Resources/packages
$(RM) test-log-junit.xml
Expand Up @@ -19,7 +19,7 @@

namespace php TestValidators

include "../../../test/v0.16/ThriftTest.thrift"
include "../../../../test/v0.16/ThriftTest.thrift"

union UnionOfStrings {
1: string aa;
Expand Down
@@ -1,4 +1,5 @@
<?php

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand All @@ -18,7 +19,7 @@
* under the License.
*/

namespace Test\Thrift;
namespace Test\Thrift\Unit;

use PHPUnit\Framework\TestCase;
use Thrift\Exception\TProtocolException;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function testReadEmpty()
$transport = new TMemoryBuffer("\000");
$protocol = new TBinaryProtocol($transport);
$bonk->read($protocol);
$this->assertTrue(true);
}

public function testWriteEmpty()
Expand All @@ -73,6 +75,8 @@ public function testWriteEmpty()
$bonk->write($protocol);
$this->fail('Bonk was able to write an empty object');
} catch (TProtocolException $e) {
$this->expectExceptionMessage('Required field Bonk.message is unset!');
throw $e;
}
}

Expand All @@ -87,6 +91,8 @@ public function testWriteWithMissingRequired()
$structa->write($protocol);
$this->fail('StructA was able to write an empty object');
} catch (TProtocolException $e) {
$this->expectExceptionMessage('Required field StructA.s is unset!');
throw $e;
}
}

Expand Down Expand Up @@ -114,27 +120,35 @@ protected static function assertHasReadValidator($class)
{
if (!static::hasReadValidator($class)) {
static::fail($class . ' class should have a read validator');
} else {
static::assertTrue(true);
}
}

protected static function assertNoReadValidator($class)
{
if (static::hasReadValidator($class)) {
static::fail($class . ' class should not have a write validator');
} else {
static::assertTrue(true);
}
}

protected static function assertHasWriteValidator($class)
{
if (!static::hasWriteValidator($class)) {
static::fail($class . ' class should have a write validator');
} else {
static::assertTrue(true);
}
}

protected static function assertNoWriteValidator($class)
{
if (static::hasWriteValidator($class)) {
static::fail($class . ' class should not have a write validator');
} else {
static::assertTrue(true);
}
}

Expand Down

0 comments on commit 9e01199

Please sign in to comment.