From 3a580ca27097172f55ccc15960837781fb700b30 Mon Sep 17 00:00:00 2001 From: pandaLIU <563883861@qq.com> Date: Fri, 14 Oct 2022 23:22:02 +0800 Subject: [PATCH 1/8] Updated Api test case path --- tests/Cases/{ => Api}/GrpcApiStub.php | 2 +- tests/Cases/{ => Api}/GrpcApiTest.php | 3 ++- tests/Cases/{ => Api}/HttpApiTest.php | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) rename tests/Cases/{ => Api}/GrpcApiStub.php (93%) rename tests/Cases/{ => Api}/GrpcApiTest.php (96%) rename tests/Cases/{ => Api}/HttpApiTest.php (96%) diff --git a/tests/Cases/GrpcApiStub.php b/tests/Cases/Api/GrpcApiStub.php similarity index 93% rename from tests/Cases/GrpcApiStub.php rename to tests/Cases/Api/GrpcApiStub.php index 29f0b4e..2a9d17d 100644 --- a/tests/Cases/GrpcApiStub.php +++ b/tests/Cases/Api/GrpcApiStub.php @@ -6,7 +6,7 @@ * * @license https://github.com/dtm-php/dtm-client/blob/master/LICENSE */ -namespace DtmClientTest\Cases; +namespace DtmClientTest\Cases\Api; use DtmClient\Api\GrpcApi; use DtmClient\Grpc\GrpcClient; diff --git a/tests/Cases/GrpcApiTest.php b/tests/Cases/Api/GrpcApiTest.php similarity index 96% rename from tests/Cases/GrpcApiTest.php rename to tests/Cases/Api/GrpcApiTest.php index f9fc702..9d5b587 100644 --- a/tests/Cases/GrpcApiTest.php +++ b/tests/Cases/Api/GrpcApiTest.php @@ -6,10 +6,11 @@ * * @license https://github.com/dtm-php/dtm-client/blob/master/LICENSE */ -namespace DtmClientTest\Cases; +namespace DtmClientTest\Cases\Api; use DtmClient\Api\GrpcApi; use DtmClient\Grpc\GrpcClientManager; +use DtmClientTest\Cases\AbstractTestCase; use Hyperf\Contract\ConfigInterface; use Hyperf\GrpcClient\BaseClient; use Hyperf\Utils\ApplicationContext; diff --git a/tests/Cases/HttpApiTest.php b/tests/Cases/Api/HttpApiTest.php similarity index 96% rename from tests/Cases/HttpApiTest.php rename to tests/Cases/Api/HttpApiTest.php index fdd630e..1f6ca5b 100644 --- a/tests/Cases/HttpApiTest.php +++ b/tests/Cases/Api/HttpApiTest.php @@ -6,9 +6,10 @@ * * @license https://github.com/dtm-php/dtm-client/blob/master/LICENSE */ -namespace DtmClientTest\Cases; +namespace DtmClientTest\Cases\Api; use DtmClient\Api\HttpApi; +use DtmClientTest\Cases\AbstractTestCase; use GuzzleHttp\Client; use Hyperf\Contract\ConfigInterface; use Mockery; From 1bda440fa017568453ed4e400775a25b1d0415bd Mon Sep 17 00:00:00 2001 From: pandaLIU <563883861@qq.com> Date: Fri, 14 Oct 2022 23:22:25 +0800 Subject: [PATCH 2/8] Added Barrire test case --- tests/Cases/BarrierTest.php | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/Cases/BarrierTest.php diff --git a/tests/Cases/BarrierTest.php b/tests/Cases/BarrierTest.php new file mode 100644 index 0000000..26c54d2 --- /dev/null +++ b/tests/Cases/BarrierTest.php @@ -0,0 +1,50 @@ +createMock(ConfigInterface::class); + $configInterface->method('get')->willReturn(DbType::MySQL); + + $mySqlBarrier = $this->createMock(MySqlBarrier::class); + + $mySqlBarrier->method('call')->willReturn(true); + + $barrier = new Barrier($configInterface, $mySqlBarrier); + $this->assertTrue($barrier->call(function () { + return true; + })); + } + + public function testBarrierFrom() + { + $configInterface = $this->createMock(ConfigInterface::class); + $configInterface->method('get')->willReturn(Protocol::GRPC); + + $mySqlBarrier = $this->createMock(MySqlBarrier::class); + + $barrier = new Barrier($configInterface, $mySqlBarrier); + $barrier->barrierFrom(TransType::TCC, 'gid', 'branchId', 'try', 'phase2Url', 'testDtm'); + + $this->assertSame(TransContext::toArray(), [ + 'trans_type' => 'tcc', + 'gid' => 'gid', + 'branch_id' => 'branchId', + 'op' => 'try', + 'phase2_url' => 'phase2Url', + 'dtm' => 'testDtm' + ]); + + } +} \ No newline at end of file From f567c92269e45379e60eef8d22888f3d3f71c019 Mon Sep 17 00:00:00 2001 From: pandaLIU <563883861@qq.com> Date: Fri, 14 Oct 2022 23:32:37 +0800 Subject: [PATCH 3/8] JsonRpc Compatible with hyperf2.2 and hyperf3.0 --- src/Api/JsonRpcHttpApi.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Api/JsonRpcHttpApi.php b/src/Api/JsonRpcHttpApi.php index ca3a97f..a2f4817 100644 --- a/src/Api/JsonRpcHttpApi.php +++ b/src/Api/JsonRpcHttpApi.php @@ -25,10 +25,6 @@ class JsonRpcHttpApi extends AbstractServiceClient implements ApiInterface { - protected string $serviceName = 'dtmserver'; - - protected string $protocol = 'jsonrpc-http'; - protected ConfigInterface $config; protected JsonRpcClientManager $jsonRpcClientManager; @@ -36,7 +32,9 @@ class JsonRpcHttpApi extends AbstractServiceClient implements ApiInterface public function __construct(ContainerInterface $container, DtmPathGenerator $pathGenerator, JsonRpcClientManager $jsonRpcClientManager) { parent::__construct($container); - + // Compatible with hyperf2.2 and hyperf3.0 + $this->serviceName = 'dtmserver'; + $this->protocol = 'jsonrpc-http'; $this->pathGenerator = $pathGenerator; $this->config = $container->get(ConfigInterface::class); $this->jsonRpcClientManager = $jsonRpcClientManager; From c9f27ea7f9f45723cac3d7319f9231fd10fb8a5c Mon Sep 17 00:00:00 2001 From: pandaLIU <563883861@qq.com> Date: Fri, 14 Oct 2022 23:41:46 +0800 Subject: [PATCH 4/8] Added ApiFactory test case --- tests/Cases/ApiFactoryTest.php | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/Cases/ApiFactoryTest.php diff --git a/tests/Cases/ApiFactoryTest.php b/tests/Cases/ApiFactoryTest.php new file mode 100644 index 0000000..3a31c36 --- /dev/null +++ b/tests/Cases/ApiFactoryTest.php @@ -0,0 +1,62 @@ +shouldReceive('get')->andReturn(Protocol::HTTP); + $container = \Mockery::mock(ContainerInterface::class); + + $container->shouldReceive('get')->withArgs([ConfigInterface::class])->andReturn($configInterface); + + $httpApi = \Mockery::mock(HttpApi::class); + $container->shouldReceive('get')->withArgs([HttpApi::class])->andReturn($httpApi); + + + $api = (new ApiFactory())($container); + $this->assertInstanceOf(HttpApi::class, $api); + } + + public function testGetGrpcApi() + { + $configInterface = \Mockery::mock(ConfigInterface::class); + $configInterface->shouldReceive('get')->andReturn(Protocol::GRPC); + $container = \Mockery::mock(ContainerInterface::class); + + $container->shouldReceive('get')->withArgs([ConfigInterface::class])->andReturn($configInterface); + + $httpApi = \Mockery::mock(GrpcApi::class); + $container->shouldReceive('get')->withArgs([GrpcApi::class])->andReturn($httpApi); + + + $api = (new ApiFactory())($container); + $this->assertInstanceOf(GrpcApi::class, $api); + } + + public function testGetJsonRpcHttpApi() + { + $configInterface = \Mockery::mock(ConfigInterface::class); + $configInterface->shouldReceive('get')->andReturn(Protocol::JSONRPC_HTTP); + $container = \Mockery::mock(ContainerInterface::class); + + $container->shouldReceive('get')->withArgs([ConfigInterface::class])->andReturn($configInterface); + + $httpApi = \Mockery::mock(JsonRpcHttpApi::class); + $container->shouldReceive('get')->withArgs([JsonRpcHttpApi::class])->andReturn($httpApi); + + + $api = (new ApiFactory())($container); + $this->assertInstanceOf(JsonRpcHttpApi::class, $api); + } +} \ No newline at end of file From f71d1703f46942077bde0644207bec37d7e0ec52 Mon Sep 17 00:00:00 2001 From: pandaLIU <563883861@qq.com> Date: Fri, 14 Oct 2022 23:59:21 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=9D=9E=E5=8D=8F?= =?UTF-8?q?=E7=A8=8B=E7=8E=AF=E5=A2=83=E7=9A=84=E4=B8=8A=E4=B8=8B=E6=96=87?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Context/Context.php | 45 ++++++++++++++++++++++++++++++++ src/Context/ContextInterface.php | 12 +++++++++ src/TransContext.php | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Context/Context.php create mode 100644 src/Context/ContextInterface.php diff --git a/src/Context/Context.php b/src/Context/Context.php new file mode 100644 index 0000000..0964845 --- /dev/null +++ b/src/Context/Context.php @@ -0,0 +1,45 @@ + Date: Sat, 15 Oct 2022 00:11:00 +0800 Subject: [PATCH 6/8] Updated test.yml --- .github/workflows/test.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 715dffe..8092677 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -60,8 +60,17 @@ jobs: sudo make install sudo sh -c "echo extension=swow > /etc/php/${{ matrix.php-version }}/cli/conf.d/swow.ini" php --ri swow + - name: Setup Packages + if: ${{ matrix.engine != 'swow' }} run: composer update -o --no-scripts + + - name: Setup Swow Packages + if: ${{ matrix.engine == 'swow' }} + run: | + composer update -o --no-scripts + composer require hyperf/engine-swow + - name: Run Test Cases run: | composer require symfony/finder:^5.0 From 3f1dbcd1cd9c195e17dfb3ed5af05739e1fa2815 Mon Sep 17 00:00:00 2001 From: pandaLIU <563883861@qq.com> Date: Sat, 15 Oct 2022 00:12:37 +0800 Subject: [PATCH 7/8] Updated test.yml --- .github/workflows/test.yml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8092677..302a150 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -62,17 +62,8 @@ jobs: php --ri swow - name: Setup Packages - if: ${{ matrix.engine != 'swow' }} - run: composer update -o --no-scripts - - - name: Setup Swow Packages - if: ${{ matrix.engine == 'swow' }} run: | composer update -o --no-scripts - composer require hyperf/engine-swow - - - name: Run Test Cases - run: | composer require symfony/finder:^5.0 composer require hyperf/di composer require hyperf/grpc-client @@ -86,5 +77,13 @@ jobs: composer require hyperf/json-rpc composer require hyperf/rpc-client composer require symfony/serializer:^5.0 + + - name: Setup Swow Packages + if: ${{ matrix.engine == 'swow' }} + run: | + composer require hyperf/engine-swow + + - name: Run Test Cases + run: | composer analyse composer test From eebaec7cebbe87f019a1b56350871c5520204844 Mon Sep 17 00:00:00 2001 From: pandaLIU <563883861@qq.com> Date: Sat, 15 Oct 2022 00:15:19 +0800 Subject: [PATCH 8/8] Updated ci actions/checkout version --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0f7d23f..179c653 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Create Release id: create_release uses: actions/create-release@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 302a150..a5d97bf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: fail-fast: false steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 with: