Skip to content

Commit 39b2e5b

Browse files
PHP Proto3: update tests and README
1 parent 857a130 commit 39b2e5b

File tree

18 files changed

+106
-420
lines changed

18 files changed

+106
-420
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"license": "BSD-3-Clause",
88
"require": {
99
"php": ">=5.5.0",
10-
"stanley-cheung/protobuf-php": "v0.6"
10+
"google/protobuf": "v3.1.0-alpha-1"
1111
},
1212
"require-dev": {
1313
"google/auth": "v0.9"

src/php/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ mkinstalldirs
2020
ext/grpc/ltmain.sh
2121
composer.lock
2222
vendor/
23+
24+
*.pb.php
25+
*_grpc_pb.php

src/php/README.md

+59-27
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11

22
#Overview
33

4-
This directory contains source code for PHP implementation of gRPC layered on shared C library.
4+
This directory contains source code for PHP implementation of gRPC layered on
5+
shared C library.
56

67
#Status
78

89
GA
910

1011
## Environment
1112

12-
Prerequisite:
13+
**Prerequisite:**
1314
* `php` 5.5 or above, 7.0 or above
14-
* `pear` and `pecl`
15-
* `phpunit`
15+
* `pecl`
16+
* `composer`
17+
* `phpunit` (optional)
1618

17-
**PEAR:**
19+
**Ubuntu/Debian:**
20+
```sh
21+
$ sudo apt-get install php5 php5-dev
22+
```
23+
24+
**PEAR/PECL:**
1825
```sh
1926
$ curl -O http://pear.php.net/go-pear.phar
2027
$ sudo php -d detect_unicode=0 go-pear.phar
2128
```
2229

30+
**Composer:**
31+
```sh
32+
$ curl -sS https://getcomposer.org/installer | php
33+
$ sudo mv composer.phar /usr/local/bin/composer
34+
```
35+
2336
**PHPUnit:**
2437
```sh
2538
$ wget https://phar.phpunit.de/phpunit-old.phar
@@ -29,15 +42,32 @@ $ sudo mv phpunit-old.phar /usr/bin/phpunit
2942

3043
## Quick Install
3144

32-
Install the gRPC PHP extension
45+
**Install the gRPC PHP extension**
3346

3447
```sh
3548
sudo pecl install grpc
3649
```
3750

38-
This will compile and install the gRPC PHP extension into the standard PHP extension directory. You should be able to run the [unit tests](#unit-tests), with the PHP extension installed.
51+
This will compile and install the gRPC PHP extension into the standard PHP
52+
extension directory. You should be able to run the [unit tests](#unit-tests),
53+
with the PHP extension installed.
54+
55+
56+
**Add the gRPC PHP library as a Composer dependency**
57+
58+
You need to add this to your project's `composer.json` file.
59+
60+
```
61+
"require": {
62+
"grpc/grpc": "v1.0.0"
63+
}
64+
```
65+
66+
To run tests with generated stub code from `.proto` files, you will also need
67+
the `composer` and `protoc` binaries. You can find out how to get these
68+
[below](#generated-code-tests).
69+
3970

40-
To run tests with generated stub code from `.proto` files, you will also need the `composer`, `protoc` and `protoc-gen-php` binaries. You can find out how to get these [below](#generated-code-tests).
4171

4272
## Build from Source
4373

@@ -98,45 +128,46 @@ $ ./bin/run_tests.sh
98128

99129
## Generated Code Tests
100130

101-
This section specifies the prerequisites for running the generated code tests, as well as how to run the tests themselves.
131+
This section specifies the prerequisites for running the generated code tests,
132+
as well as how to run the tests themselves.
102133

103134
### Composer
104135

105-
If you don't have it already, install `composer` to pull in some runtime dependencies based on the `composer.json` file.
136+
Install the runtime dependencies via `composer install`.
106137

107138
```sh
108-
$ curl -sS https://getcomposer.org/installer | php
109-
$ sudo mv composer.phar /usr/local/bin/composer
110-
111139
$ cd grpc/src/php
112140
$ composer install
113141
```
114142

115143
### Protobuf compiler
116144

117-
Again if you don't have it already, you need to install the protobuf compiler `protoc`, version 3.0.0+.
145+
Again if you don't have it already, you need to install the protobuf compiler
146+
`protoc`, version 3.1.0+.
147+
148+
If `protoc` hasn't been installed, you can download the `protoc` binaries from
149+
[the protocol buffers Github repository](https://github.com/google/protobuf/releases).
118150

119-
If you compiled the gRPC C core library from source above, the `protoc` binary should have been installed as well. If it hasn't been installed, you can run the following commands to install it.
151+
If you really must compile `protoc` from source, you can run the following
152+
commands, but this is risky because there is no easy way to uninstall /
153+
upgrade to a newer release.
120154

121155
```sh
122156
$ cd grpc/third_party/protobuf
123-
$ sudo make install # 'make' should have been run by core grpc
157+
$ ./autogen.sh && ./configure && make
158+
$ sudo make install
124159
```
125160

126-
Alternatively, you can download `protoc` binaries from [the protocol buffers Github repository](https://github.com/google/protobuf/releases).
127161

162+
### PHP Protoc Plugin
128163

129-
### PHP protobuf compiler
164+
You need the gRPC PHP protoc plugin to generate the client stub classes.
130165

131-
You need to install `protoc-gen-php` to generate stub class `.php` files from service definition `.proto` files.
166+
It should already been compiled when you run `make` from the root directory
167+
of this repo. The plugin can be found in the `bins/opt` directory. We are
168+
planning to provide a better way to download and install the plugin
169+
in the future.
132170

133-
```sh
134-
$ git clone https://github.com/stanley-cheung/Protobuf-PHP
135-
$ cd Protobuf-PHP
136-
$ gem install rake ronn
137-
$ rake pear:package version=1.0
138-
$ sudo pear install Protobuf-1.0.tgz
139-
```
140171

141172
### Client Stub
142173

@@ -149,7 +180,8 @@ $ ./bin/generate_proto_php.sh
149180

150181
### Run test server
151182

152-
Run a local server serving the math services. Please see [Node][] for how to run an example server.
183+
Run a local server serving the math services. Please see [Node][] for how to
184+
run an example server.
153185

154186
```sh
155187
$ cd grpc

src/php/bin/determine_extension_dir.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ default_extension_dir=$(php-config --extension-dir)
3232
if [ ! -e $default_extension_dir/grpc.so ]; then
3333
# the grpc extension is not found in the default PHP extension dir
3434
# try the source modules directory
35-
module_dir=../ext/grpc/modules
35+
module_dir=$(pwd)/../ext/grpc/modules
3636
if [ ! -e $module_dir/grpc.so ]; then
3737
echo "Please run 'phpize && ./configure && make' from ext/grpc first"
3838
exit 1

src/php/bin/generate_proto_php.sh

+25-6
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,32 @@
2828
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

31-
3231
set +e
33-
cd $(dirname $0)
32+
cd $(dirname $0)/../../..
33+
34+
protoc --proto_path=src/proto/math \
35+
--php_out=src/php/tests/generated_code \
36+
--grpc_out=src/php/tests/generated_code \
37+
--plugin=protoc-gen-grpc=bins/opt/grpc_php_plugin \
38+
src/proto/math/math.proto
3439

35-
gen_code='../tests/generated_code'
36-
interop='../tests/interop'
40+
# replace the Empty message with EmptyMessage
41+
# because Empty is a PHP reserved word
42+
sed -i 's/message Empty/message EmptyMessage/g' \
43+
src/proto/grpc/testing/empty.proto
44+
sed -i 's/grpc\.testing\.Empty/grpc\.testing\.EmptyMessage/g' \
45+
src/proto/grpc/testing/test.proto
3746

38-
protoc-gen-php -i $gen_code -o $gen_code $gen_code/math.proto
47+
protoc --proto_path=. \
48+
--php_out=src/php/tests/interop \
49+
--grpc_out=src/php/tests/interop \
50+
--plugin=protoc-gen-grpc=bins/opt/grpc_php_plugin \
51+
src/proto/grpc/testing/messages.proto \
52+
src/proto/grpc/testing/empty.proto \
53+
src/proto/grpc/testing/test.proto
3954

40-
protoc-gen-php -i $interop -o $interop $interop/test.proto
55+
# change it back
56+
sed -i 's/message EmptyMessage/message Empty/g' \
57+
src/proto/grpc/testing/empty.proto
58+
sed -i 's/grpc\.testing\.EmptyMessage/grpc\.testing\.Empty/g' \
59+
src/proto/grpc/testing/test.proto

src/php/bin/interop_client.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
set -e
3232
cd $(dirname $0)
3333
source ./determine_extension_dir.sh
34+
cd ../tests/interop
3435
php $extension_dir -d max_execution_time=300 \
35-
../tests/interop/interop_client.php $@ 1>&2
36+
interop_client.php $@ 1>&2

src/php/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"version": "1.1.0",
99
"require": {
1010
"php": ">=5.5.0",
11-
"stanley-cheung/protobuf-php": "v0.6"
11+
"google/protobuf": "v3.1.0-alpha-1"
1212
},
1313
"require-dev": {
1414
"google/auth": "v0.9"

src/php/tests/generated_code/AbstractGeneratedCodeTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
*
3333
*/
3434
require_once realpath(dirname(__FILE__).'/../../vendor/autoload.php');
35-
require_once dirname(__FILE__).'/math.php';
35+
require_once dirname(__FILE__).'/math.pb.php';
36+
require_once dirname(__FILE__).'/math_grpc_pb.php';
3637

3738
abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase
3839
{
@@ -92,7 +93,7 @@ public function testGetCallMetadata()
9293
public function testTimeout()
9394
{
9495
$div_arg = new math\DivArgs();
95-
$call = self::$client->Div($div_arg, [], ['timeout' => 100]);
96+
$call = self::$client->Div($div_arg, [], ['timeout' => 1]);
9697
list($response, $status) = $call->wait();
9798
$this->assertSame(\Grpc\STATUS_DEADLINE_EXCEEDED, $status->code);
9899
}

src/php/tests/generated_code/math.proto

-83
This file was deleted.

src/php/tests/interop/empty.proto

-43
This file was deleted.

0 commit comments

Comments
 (0)