Comments (26)
ようやく動いた!
$ make test
node tests/server.js &> /dev/null &
./vendor/bin/http_test_server &> /dev/null &
vendor/bin/phpunit
PHPUnit 9.6.13 by Sebastian Bergmann and contributors.
Random Seed: 1696822998
Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!
............................................................... 63 / 560 ( 11%)
............................................................... 126 / 560 ( 22%)
...............S....................S.....................SS... 189 / 560 ( 33%)
............................................................... 252 / 560 ( 45%)
..................................................S............ 315 / 560 ( 56%)
.............................................................SS 378 / 560 ( 67%)
S.............................................................. 441 / 560 ( 78%)
............................................................... 504 / 560 ( 90%)
........................................................ 560 / 560 (100%)
Time: 00:03.462, Memory: 16.00 MB
OK, but incomplete, skipped, or risky tests!
Tests: 560, Assertions: 2309, Skipped: 8.
make stop-server
make[1]: Entering directory '/home/runner/OSS-GATE-2/guzzle'
make[1]: Leaving directory '/home/runner/OSS-GATE-2/guzzle'
from workshop.
これをやってみようかな!
https://github.com/guzzle/guzzle/#guzzle-php-http-client
from workshop.
ReplitのPHPCLIで、ドキュメントに沿ってまずはうごかしてみる
https://docs.guzzlephp.org/en/stable/overview.html#contributing
$ git clone https://github.com/guzzle/guzzle.git
$ cd guzzle/
$ composer install
composer: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
Adding php80Packages.composer to replit.nix
success
/nix/store/4vjlcim1643j5s2kn2k66rjq03d50sxk-php-composer-2.1.5
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 42 installs, 0 updates, 0 removals
- Locking bamarni/composer-bin-plugin (1.8.2)
- Locking clue/stream-filter (v1.6.0)
- Locking doctrine/instantiator (1.5.0)
- Locking guzzlehttp/promises (2.0.1)
- Locking guzzlehttp/psr7 (2.6.1)
- Locking myclabs/deep-copy (1.11.1)
- Locking nikic/php-parser (v4.17.1)
- Locking phar-io/manifest (2.0.3)
- Locking phar-io/version (3.2.1)
- Locking php-http/client-integration-tests (dev-master 2c02584)
- Locking php-http/message (1.16.0)
- Locking php-http/message-factory (1.1.0)
- Locking phpunit/php-code-coverage (9.2.29)
- Locking phpunit/php-file-iterator (3.0.6)
- Locking phpunit/php-invoker (3.1.1)
- Locking phpunit/php-text-template (2.0.4)
- Locking phpunit/php-timer (5.0.3)
- Locking phpunit/phpunit (9.6.13)
- Locking psr/http-client (1.0.3)
- Locking psr/http-factory (1.0.2)
- Locking psr/http-message (2.0)
- Locking psr/log (3.0.0)
- Locking ralouphie/getallheaders (3.0.3)
- Locking sebastian/cli-parser (1.0.1)
- Locking sebastian/code-unit (1.0.8)
- Locking sebastian/code-unit-reverse-lookup (2.0.3)
- Locking sebastian/comparator (4.0.8)
- Locking sebastian/complexity (2.0.2)
- Locking sebastian/diff (4.0.5)
- Locking sebastian/environment (5.1.5)
- Locking sebastian/exporter (4.0.5)
- Locking sebastian/global-state (5.0.6)
- Locking sebastian/lines-of-code (1.0.3)
- Locking sebastian/object-enumerator (4.0.4)
- Locking sebastian/object-reflector (2.0.4)
- Locking sebastian/recursion-context (4.0.5)
- Locking sebastian/resource-operations (3.0.3)
- Locking sebastian/type (3.2.1)
- Locking sebastian/version (3.0.2)
- Locking symfony/deprecation-contracts (v3.0.2)
- Locking th3n3rd/cartesian-product (v0.3.0)
- Locking theseer/tokenizer (1.2.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 42 installs, 0 updates, 0 removals
- Downloading bamarni/composer-bin-plugin (1.8.2)
- Downloading guzzlehttp/promises (2.0.1)
- Downloading th3n3rd/cartesian-product (v0.3.0)
- Downloading sebastian/version (3.0.2)
- Downloading sebastian/type (3.2.1)
- Downloading sebastian/resource-operations (3.0.3)
- Downloading sebastian/recursion-context (4.0.5)
- Downloading sebastian/object-reflector (2.0.4)
- Downloading sebastian/object-enumerator (4.0.4)
- Downloading sebastian/global-state (5.0.6)
- Downloading sebastian/exporter (4.0.5)
- Downloading sebastian/environment (5.1.5)
- Downloading sebastian/diff (4.0.5)
- Downloading sebastian/comparator (4.0.8)
- Downloading sebastian/code-unit (1.0.8)
- Downloading sebastian/cli-parser (1.0.1)
- Downloading phpunit/php-timer (5.0.3)
- Downloading phpunit/php-text-template (2.0.4)
- Downloading phpunit/php-invoker (3.1.1)
- Downloading phpunit/php-file-iterator (3.0.6)
- Downloading theseer/tokenizer (1.2.1)
- Downloading nikic/php-parser (v4.17.1)
- Downloading sebastian/lines-of-code (1.0.3)
- Downloading sebastian/complexity (2.0.2)
- Downloading sebastian/code-unit-reverse-lookup (2.0.3)
- Downloading phpunit/php-code-coverage (9.2.29)
- Downloading phar-io/version (3.2.1)
- Downloading phar-io/manifest (2.0.3)
- Downloading myclabs/deep-copy (1.11.1)
- Downloading doctrine/instantiator (1.5.0)
- Downloading phpunit/phpunit (9.6.13)
- Downloading psr/http-message (2.0)
- Downloading clue/stream-filter (v1.6.0)
- Downloading php-http/message (1.16.0)
- Downloading ralouphie/getallheaders (3.0.3)
- Downloading psr/http-factory (1.0.2)
- Downloading guzzlehttp/psr7 (2.6.1)
- Downloading php-http/client-integration-tests (dev-master 2c02584)
- Downloading php-http/message-factory (1.1.0)
- Downloading psr/http-client (1.0.3)
- Downloading psr/log (3.0.0)
- Downloading symfony/deprecation-contracts (v3.0.2)
- Installing bamarni/composer-bin-plugin (1.8.2): Extracting archive
- Installing guzzlehttp/promises (2.0.1): Extracting archive
- Installing th3n3rd/cartesian-product (v0.3.0): Extracting archive
- Installing sebastian/version (3.0.2): Extracting archive
- Installing sebastian/type (3.2.1): Extracting archive
- Installing sebastian/resource-operations (3.0.3): Extracting archive
- Installing sebastian/recursion-context (4.0.5): Extracting archive
- Installing sebastian/object-reflector (2.0.4): Extracting archive
- Installing sebastian/object-enumerator (4.0.4): Extracting archive
- Installing sebastian/global-state (5.0.6): Extracting archive
- Installing sebastian/exporter (4.0.5): Extracting archive
- Installing sebastian/environment (5.1.5): Extracting archive
- Installing sebastian/diff (4.0.5): Extracting archive
- Installing sebastian/comparator (4.0.8): Extracting archive
- Installing sebastian/code-unit (1.0.8): Extracting archive
- Installing sebastian/cli-parser (1.0.1): Extracting archive
- Installing phpunit/php-timer (5.0.3): Extracting archive
- Installing phpunit/php-text-template (2.0.4): Extracting archive
- Installing phpunit/php-invoker (3.1.1): Extracting archive
- Installing phpunit/php-file-iterator (3.0.6): Extracting archive
- Installing theseer/tokenizer (1.2.1): Extracting archive
- Installing nikic/php-parser (v4.17.1): Extracting archive
- Installing sebastian/lines-of-code (1.0.3): Extracting archive
- Installing sebastian/complexity (2.0.2): Extracting archive
- Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
- Installing phpunit/php-code-coverage (9.2.29): Extracting archive
- Installing phar-io/version (3.2.1): Extracting archive
- Installing phar-io/manifest (2.0.3): Extracting archive
- Installing myclabs/deep-copy (1.11.1): Extracting archive
- Installing doctrine/instantiator (1.5.0): Extracting archive
- Installing phpunit/phpunit (9.6.13): Extracting archive
- Installing psr/http-message (2.0): Extracting archive
- Installing clue/stream-filter (v1.6.0): Extracting archive
- Installing php-http/message (1.16.0): Extracting archive
- Installing ralouphie/getallheaders (3.0.3): Extracting archive
- Installing psr/http-factory (1.0.2): Extracting archive
- Installing guzzlehttp/psr7 (2.6.1): Extracting archive
- Installing php-http/client-integration-tests (dev-master 2c02584): Extracting archive
- Installing php-http/message-factory (1.1.0): Extracting archive
- Installing psr/http-client (1.0.3): Extracting archive
- Installing psr/log (3.0.0): Extracting archive
- Installing symfony/deprecation-contracts (v3.0.2): Extracting archive
8 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package php-http/message-factory is abandoned, you should avoid using it. Use psr/http-factory instead.
Generating autoload files
29 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Detected change in environment, reloading shell...
$ make test
node tests/server.js &> /dev/null &
./vendor/bin/http_test_server &> /dev/null &
vendor/bin/phpunit
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.21. in /home/runner/OSS-GATE/guzzle/vendor/composer/platform_check.php on line 24
make: *** [Makefile:34: test] Error 255
from workshop.
composer installの段階でphp80Packages.composerを選択したが、
ローカルのバージョンが7.4.21だったので7.4のパッケージに変えられないかをしらべてみる
from workshop.
php 8.0を選択したときになにが動いていたのかがわからないので直後のログを検索する
Adding php80Packages.composer to replit.nix
from workshop.
Replitのドキュメントが見つかった
https://docs.replit.com/programming-ide/nix-on-replit#switch-the-nix-channel
どうやらReplitはNixという仮想環境で動いている
ようでその設定を切り替える必要があるようだ。
from workshop.
Replitのドキュメントにパッケージの検索のリンクがあったが、
php7.4のcomposerパッケージは見当たらなかった
https://search.nixos.org/
from workshop.
composer.lockとvenderディレクトリを削除してもう一度バージョンの選択が出てこないかを検証
結果:選択画面は出ずに、php8.0の想定でcomposerが動いてしまった。
from workshop.
Replitのドキュメント上にnixパッケージの記述は、replit.nix上にあると記載があった。
そのため、一度ファイルのバックアップを取ってreplit.nixファイルを削除して、compoer installを再実行
結果:変わらずphp8.0の想定でcomposerが動作した
from workshop.
これ以上は、本題から逸れそうなため、別の実行環境を用意する
その際はphp74Packages.composer
を選択する。
$ composer install
composer: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
Adding php74Packages.composer to replit.nix
success
/nix/store/bj42fydviywwww8g81gm0ygx7rx28z3n-php-composer-2.1.5
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Info from https://repo.packagist.org: #StandWithUkraine
Updating dependencies
Lock file operations: 42 installs, 0 updates, 0 removals
- Locking bamarni/composer-bin-plugin (1.8.2)
- Locking clue/stream-filter (v1.6.0)
- Locking doctrine/instantiator (1.5.0)
- Locking guzzlehttp/promises (2.0.1)
- Locking guzzlehttp/psr7 (2.6.1)
- Locking myclabs/deep-copy (1.11.1)
- Locking nikic/php-parser (v4.17.1)
- Locking phar-io/manifest (2.0.3)
- Locking phar-io/version (3.2.1)
- Locking php-http/client-integration-tests (dev-master 2c02584)
- Locking php-http/message (1.16.0)
- Locking php-http/message-factory (1.1.0)
- Locking phpunit/php-code-coverage (9.2.29)
- Locking phpunit/php-file-iterator (3.0.6)
- Locking phpunit/php-invoker (3.1.1)
- Locking phpunit/php-text-template (2.0.4)
- Locking phpunit/php-timer (5.0.3)
- Locking phpunit/phpunit (9.6.13)
- Locking psr/http-client (1.0.3)
- Locking psr/http-factory (1.0.2)
- Locking psr/http-message (2.0)
- Locking psr/log (1.1.4)
- Locking ralouphie/getallheaders (3.0.3)
- Locking sebastian/cli-parser (1.0.1)
- Locking sebastian/code-unit (1.0.8)
- Locking sebastian/code-unit-reverse-lookup (2.0.3)
- Locking sebastian/comparator (4.0.8)
- Locking sebastian/complexity (2.0.2)
- Locking sebastian/diff (4.0.5)
- Locking sebastian/environment (5.1.5)
- Locking sebastian/exporter (4.0.5)
- Locking sebastian/global-state (5.0.6)
- Locking sebastian/lines-of-code (1.0.3)
- Locking sebastian/object-enumerator (4.0.4)
- Locking sebastian/object-reflector (2.0.4)
- Locking sebastian/recursion-context (4.0.5)
- Locking sebastian/resource-operations (3.0.3)
- Locking sebastian/type (3.2.1)
- Locking sebastian/version (3.0.2)
- Locking symfony/deprecation-contracts (v2.5.2)
- Locking th3n3rd/cartesian-product (v0.3.0)
- Locking theseer/tokenizer (1.2.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 42 installs, 0 updates, 0 removals
- Downloading bamarni/composer-bin-plugin (1.8.2)
- Downloading guzzlehttp/promises (2.0.1)
- Downloading th3n3rd/cartesian-product (v0.3.0)
- Downloading sebastian/version (3.0.2)
- Downloading sebastian/type (3.2.1)
- Downloading sebastian/resource-operations (3.0.3)
- Downloading sebastian/recursion-context (4.0.5)
- Downloading sebastian/object-reflector (2.0.4)
- Downloading sebastian/object-enumerator (4.0.4)
- Downloading sebastian/global-state (5.0.6)
- Downloading sebastian/exporter (4.0.5)
- Downloading sebastian/environment (5.1.5)
- Downloading sebastian/diff (4.0.5)
- Downloading sebastian/comparator (4.0.8)
- Downloading sebastian/code-unit (1.0.8)
- Downloading sebastian/cli-parser (1.0.1)
- Downloading phpunit/php-timer (5.0.3)
- Downloading phpunit/php-text-template (2.0.4)
- Downloading phpunit/php-invoker (3.1.1)
- Downloading phpunit/php-file-iterator (3.0.6)
- Downloading theseer/tokenizer (1.2.1)
- Downloading nikic/php-parser (v4.17.1)
- Downloading sebastian/lines-of-code (1.0.3)
- Downloading sebastian/complexity (2.0.2)
- Downloading sebastian/code-unit-reverse-lookup (2.0.3)
- Downloading phpunit/php-code-coverage (9.2.29)
- Downloading phar-io/version (3.2.1)
- Downloading phar-io/manifest (2.0.3)
- Downloading myclabs/deep-copy (1.11.1)
- Downloading doctrine/instantiator (1.5.0)
- Downloading phpunit/phpunit (9.6.13)
- Downloading psr/http-message (2.0)
- Downloading clue/stream-filter (v1.6.0)
- Downloading php-http/message (1.16.0)
- Downloading ralouphie/getallheaders (3.0.3)
- Downloading psr/http-factory (1.0.2)
- Downloading guzzlehttp/psr7 (2.6.1)
- Downloading php-http/client-integration-tests (dev-master 2c02584)
- Downloading php-http/message-factory (1.1.0)
- Downloading psr/http-client (1.0.3)
- Downloading psr/log (1.1.4)
- Downloading symfony/deprecation-contracts (v2.5.2)
- Installing bamarni/composer-bin-plugin (1.8.2): Extracting archive
- Installing guzzlehttp/promises (2.0.1): Extracting archive
- Installing th3n3rd/cartesian-product (v0.3.0): Extracting archive
- Installing sebastian/version (3.0.2): Extracting archive
- Installing sebastian/type (3.2.1): Extracting archive
- Installing sebastian/resource-operations (3.0.3): Extracting archive
- Installing sebastian/recursion-context (4.0.5): Extracting archive
- Installing sebastian/object-reflector (2.0.4): Extracting archive
- Installing sebastian/object-enumerator (4.0.4): Extracting archive
- Installing sebastian/global-state (5.0.6): Extracting archive
- Installing sebastian/exporter (4.0.5): Extracting archive
- Installing sebastian/environment (5.1.5): Extracting archive
- Installing sebastian/diff (4.0.5): Extracting archive
- Installing sebastian/comparator (4.0.8): Extracting archive
- Installing sebastian/code-unit (1.0.8): Extracting archive
- Installing sebastian/cli-parser (1.0.1): Extracting archive
- Installing phpunit/php-timer (5.0.3): Extracting archive
- Installing phpunit/php-text-template (2.0.4): Extracting archive
- Installing phpunit/php-invoker (3.1.1): Extracting archive
- Installing phpunit/php-file-iterator (3.0.6): Extracting archive
- Installing theseer/tokenizer (1.2.1): Extracting archive
- Installing nikic/php-parser (v4.17.1): Extracting archive
- Installing sebastian/lines-of-code (1.0.3): Extracting archive
- Installing sebastian/complexity (2.0.2): Extracting archive
- Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
- Installing phpunit/php-code-coverage (9.2.29): Extracting archive
- Installing phar-io/version (3.2.1): Extracting archive
- Installing phar-io/manifest (2.0.3): Extracting archive
- Installing myclabs/deep-copy (1.11.1): Extracting archive
- Installing doctrine/instantiator (1.5.0): Extracting archive
- Installing phpunit/phpunit (9.6.13): Extracting archive
- Installing psr/http-message (2.0): Extracting archive
- Installing clue/stream-filter (v1.6.0): Extracting archive
- Installing php-http/message (1.16.0): Extracting archive
- Installing ralouphie/getallheaders (3.0.3): Extracting archive
- Installing psr/http-factory (1.0.2): Extracting archive
- Installing guzzlehttp/psr7 (2.6.1): Extracting archive
- Installing php-http/client-integration-tests (dev-master 2c02584): Extracting archive
- Installing php-http/message-factory (1.1.0): Extracting archive
- Installing psr/http-client (1.0.3): Extracting archive
- Installing psr/log (1.1.4): Extracting archive
- Installing symfony/deprecation-contracts (v2.5.2): Extracting archive
8 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package php-http/message-factory is abandoned, you should avoid using it. Use psr/http-factory instead.
Generating autoload files
29 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
Detected change in environment, reloading shell...
from workshop.
composerのインストールが終わったので、
Makefileからテストを実行
https://docs.guzzlephp.org/en/stable/overview.html#contributing
$ make test
node tests/server.js &> /dev/null &
./vendor/bin/http_test_server &> /dev/null &
vendor/bin/phpunit
PHPUnit 9.6.13 by Sebastian Bergmann and contributors.
Error in bootstrap script: RuntimeException:
Unable to contact node.js server
#0 /home/runner/OSS-GATE-2/guzzle/tests/Server.php(177): GuzzleHttp\Tests\Server::wait()
#1 /home/runner/OSS-GATE-2/guzzle/tests/bootstrap.php(13): GuzzleHttp\Tests\Server::start()
#2 /home/runner/OSS-GATE-2/guzzle/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once('/home/runner/OS...')
#3 /home/runner/OSS-GATE-2/guzzle/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load('/home/runner/OS...')
#4 /home/runner/OSS-GATE-2/guzzle/vendor/phpunit/phpunit/src/TextUI/Command.php(565): PHPUnit\Util\FileLoader::checkAndLoad('/home/runner/OS...')
#5 /home/runner/OSS-GATE-2/guzzle/vendor/phpunit/phpunit/src/TextUI/Command.php(345): PHPUnit\TextUI\Command->handleBootstrap('/home/runner/OS...')
#6 /home/runner/OSS-GATE-2/guzzle/vendor/phpunit/phpunit/src/TextUI/Command.php(112): PHPUnit\TextUI\Command->handleArguments(Array)
#7 /home/runner/OSS-GATE-2/guzzle/vendor/phpunit/phpunit/src/TextUI/Command.php(97): PHPUnit\TextUI\Command->run(Array, true)
#8 /home/runner/OSS-GATE-2/guzzle/vendor/phpunit/phpunit/phpunit(107): PHPUnit\TextUI\Command::main()
#9 {main}
make: *** [Makefile:34: test] Error 1
from workshop.
どうやらNodejsが存在しないことが問題のようだった。
ドキュメントには注意書きで統合テストを実施するにはnode.js v8以上が必要とのことなので、node.jsをインストールする方法を考える
from workshop.
先ほどのNixのパッケージサイトから現在のLTSをインストールしてみる
$ nix-shell -p nodejs_18
error: undefined variable 'nodejs_18' at (string):1:94
(use '--show-trace' to show detailed location information)
Replitにはnode.jsの18が見当たらなさそうなため複数の旧バージョンを試してみる
$ nix-shell -p nodejs_16
error: undefined variable 'nodejs_16' at (string):1:94
(use '--show-trace' to show detailed location information)
$ nix-shell -p nodejs_12
error: undefined variable 'nodejs_12' at (string):1:94
(use '--show-trace' to show detailed location information)
$ nix-shell -p nodejs_10
error: undefined variable 'nodejs_10' at (string):1:94
(use '--show-trace' to show detailed location information)
$ nix-shell -p nodejs_8
error: undefined variable 'nodejs_8' at (string):1:94
(use '--show-trace' to show detailed location information)
from workshop.
aptコマンドが見つかったのでそこからできないかやってみたが権限的にダメそう
$ which apt
/usr/bin/apt
$ apt update
Reading package lists... Done
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (30: Read-only file system)
$ sudo apt update
You don't need sudo in Replit, all files that
can be modified already have the correct permissions
and you can install new software using Nix.
Reading package lists... Done
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (30: Read-only file system)
from workshop.
試しにNodeコマンドを実行してみたらセットアップが進行!
$ node -v
node: command not installed. Multiple versions of this command were found in Nix.
Select one to run (or press Ctrl-C to cancel):
Adding nodejs-12_x to replit.nix
success
/nix/store/lzbxhi9f9l0p0qj6m8amgdc24j27rfl9-nodejs-12.22.5
v12.22.5
今回は、少し古めのNode.js12を入れてみる
# replit.nix
{ pkgs }: {
deps = [
pkgs.nodejs-12_x
pkgs.php74Packages.composer
pkgs.php74
];
}
from workshop.
PHPUnitのSkipをチェックしてみる
@requiere
が記述されていると、別途パッケージが存在するかを確認して実行するので、なければSkipされる
例えばこれ
# ClientTest.php
/**
* @requires extension idn
*/
public function testIdnIsTranslatedToAsciiWhenConversionIsEnabled()
{
$mockHandler = new MockHandler([new Response()]);
$client = new Client(['handler' => $mockHandler]);
$client->request('GET', 'https://яндекс.рф/images', ['idn_conversion' => true]);
$request = $mockHandler->getLastRequest();
self::assertSame('https://xn--d1acpjx3f.xn--p1ai/images', (string) $request->getUri());
self::assertSame('xn--d1acpjx3f.xn--p1ai', (string) $request->getHeaderLine('Host'));
}
from workshop.
Composer.jsonでexe-curlは必須であるが、
テストケースではexe-curlがない場合の分岐が用意されている。
Composer.json側
https://github.com/guzzle/guzzle/blob/7.8/composer.json#L64-L71
テストケース側
https://github.com/guzzle/guzzle/blob/7.8/tests/RedirectMiddlewareTest.php#L275-L303
from workshop.
テストケース側で、この分岐は4件利用されている
-
testRemoveCurlAuthorizationOptionsOnRedirectCrossHost
guzzle/guzzle@1dd98b0
16ヶ月まえ -
testRemoveCurlAuthorizationOptionsOnRedirectCrossPort
guzzle/guzzle@1dd98b0
16ヶ月まえ -
testRemoveCurlAuthorizationOptionsOnRedirectCrossScheme
guzzle/guzzle@1dd98b0
16ヶ月まえ -
testRemoveCurlAuthorizationOptionsOnRedirectCrossSchemeSamePort
guzzle/guzzle@cc80b00
19ヶ月前
from workshop.
https://www.php.net/manual/ja/function.curl-setopt.php
from workshop.
markTestSkippedを設定している分岐条件を確認してみる
/**
* @testWith ["digest"]
* ["ntlm"]
*/
public function testRemoveCurlAuthorizationOptionsOnRedirectCrossHost($auth)
{
if (!defined('\CURLOPT_HTTPAUTH')) {
self::markTestSkipped('ext-curl is required for this test');
}
$mock = new MockHandler([
new Response(302, ['Location' => 'http://test.com']),
static function (RequestInterface $request, $options) {
self::assertFalse(
isset($options['curl'][\CURLOPT_HTTPAUTH]),
'curl options still contain CURLOPT_HTTPAUTH entry'
);
self::assertFalse(
isset($options['curl'][\CURLOPT_USERPWD]),
'curl options still contain CURLOPT_USERPWD entry'
);
return new Response(200);
},
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$client->get('http://example.com?a=b', ['auth' => ['testuser', 'testpass', $auth]]);
}
from workshop.
CURLOPT_HTTPAUTHという定数が存在している前提でテストケースがあり、
定数が存在しない場合はスキップするという条件になっている。
if (!defined('\CURLOPT_HTTPAUTH')) {
self::markTestSkipped('ext-curl is required for this test');
}
この定数(CURLOPT_HTTPAUTH)はPHPのcURLのオプション設定の1つであり、
HTTPの認証設定を追加するときに設定するものである。
from workshop.
オプションの定数が名称変更、または削除となったときはスキップとなる。
from workshop.
ライブラリやフレームワークでは様々な環境で動作するかを確認できる必要があるようだが、
今回のCURLOPT_HTTPAUTHの定数の取り扱いにおいては、取り扱うレベルが異なっている箇所があった。
testRemoveCurlAuthorizationOptionsOnRedirectCrossHost()
では、CURLOPT_HTTPAUTH
という定数が存在しない場合を想定したテストコードになっているが、testAuthCanBeArrayForDigestAuth()
では、CURLOPT_HTTPAUTH
が存在する前提でテストコードが用意されいるので一貫性がない状態である。
/**
* @testWith ["digest"]
* ["ntlm"]
*/
public function testRemoveCurlAuthorizationOptionsOnRedirectCrossHost($auth)
{
if (!defined('\CURLOPT_HTTPAUTH')) {
self::markTestSkipped('ext-curl is required for this test');
}
$mock = new MockHandler([
new Response(302, ['Location' => 'http://test.com']),
static function (RequestInterface $request, $options) {
self::assertFalse(
isset($options['curl'][\CURLOPT_HTTPAUTH]),
'curl options still contain CURLOPT_HTTPAUTH entry'
);
self::assertFalse(
isset($options['curl'][\CURLOPT_USERPWD]),
'curl options still contain CURLOPT_USERPWD entry'
);
return new Response(200);
},
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$client->get('http://example.com?a=b', ['auth' => ['testuser', 'testpass', $auth]]);
}
public function testAuthCanBeArrayForDigestAuth()
{
$mock = new MockHandler([new Response()]);
$client = new Client(['handler' => $mock]);
$client->get('http://foo.com', ['auth' => ['a', 'b', 'digest']]);
$last = $mock->getLastOptions();
self::assertSame([
\CURLOPT_HTTPAUTH => 2,
\CURLOPT_USERPWD => 'a:b',
], $last['curl']);
}
from workshop.
composer.json
でext-curl
のライブラリがrequire-dev
に設定されているため、CURLOPT_HTTPAUTH
の存在を担保するのはライブラリの責務である
テストでは、CURLOPT_HTTPAUTH
の定義が確認できなかったときはext-curlのライブラリが不足しているというスキップメッセージになっている。
ext-curl
が常に存在するのか、何らかの状態において存在しない状況が必要でこの分岐が追記されたのかを確認していく。
「何らかの状態において存在しない状況が必要」この場合であるならば、
ClientTest.php
内のCURLOPT_HTTPAUTH
という定数が存在するかをかくにんするテストコードに変更したい!
from workshop.
composer.json
のrequire-dev
にext-curl
が設定されるより後に、CURLOPT_HTTPAUTH
の存在に関する分岐が追加されているので、後に変更されたものの背景を確認してみる
guzzle/guzzle#2845
guzzle/guzzle#1477
from workshop.
おつかれさまでした!
ワークショップの終了にともないissueを閉じますが、このまま作業メモとして使っても構いません 👌
ワークショップの感想を集めています!
ブログなどに書かれた際は、このページへリンクの追加をお願いします 🙏
またの参加をお待ちしています!
from workshop.
Related Issues (20)
- OSS Gate Workshop: PHP Lovers: 2024-01-15: kouki.miura: baserCMS: Work log HOT 28
- OSS Gate Workshop: PHP Lovers: 2024-01-15: taisukearase: laravel/sail: Work log HOT 7
- OSS Gate Workshop: PHP Lovers: 2024-01-15: OHMORIYUSUKE: erusev/parsedown: Work log HOT 20
- OSS Gate Workshop: PHP Lovers: 2024-01-15: WataruNishimura : @aws-amplify/cli : Work log HOT 8
- OSS Gateオンラインワークショップ2024-03-09 HOT 1
- OSS Gate Workshop: online: 2024-01-27: daipom: Fluentd: Work log HOT 10
- OSS Gate Workshop: online: 2024-01-27: びきニキ: doc-ja : Work log HOT 28
- OSS Gate Workshop: online: 2024-01-27: s1a: SCP: Work log HOT 15
- OSS Gate Workshop: online: 2024-01-27: ochi_work: ${OSS_NAME}: Work log HOT 24
- OSS Gate Workshop: PHP Lovers: 2024-02-12: zonuexe: Symfony VarDumper: Work log HOT 3
- OSS Gate Workshop: PHP Lovers: 2024-02-12: akinoriakatsuka: larastan: Work log HOT 32
- OSS Gate Workshop: PHP Lovers: 2024-02-12: ehimemikan: pecl-mail-mailparse: Work log HOT 27
- OSS Gate Workshop: PHP Lovers: 2024-02-12: azuki-penguin: Lighthouse: Work log HOT 26
- OSS Gate Workshop: PHP Lovers: 2024-02-12: hayato07: quill: Work log HOT 23
- OSS Gateオンラインワークショップ2024-04-27
- OSS Gate Workshop: online: 2024-03-09: daipom: OurBoard: Work log HOT 15
- OSS Gate Workshop: online: 2024-03-09: SotaYamaguchi: chikamichi: Work log HOT 27
- OSS Gate Workshop: online: 2024-03-09: unikounio: minimist Work log HOT 38
- OSS Gate Workshop: online: 2024-03-09: chihara: use-web-animations: Work log HOT 12
- OSS Gate Workshop: online: 2024-03-09: hdkzkg: OrgChart: Work log HOT 24
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workshop.