Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSS Gate Workshop: PHP Lovers: 2024-01-15: OHMORIYUSUKE: erusev/parsedown: Work log #1760

Closed
OHMORIYUSUKE opened this issue Jan 14, 2024 · 20 comments
Labels
work log ワークショップ作業メモ

Comments

@OHMORIYUSUKE
Copy link
Contributor

This is a work log of a "OSS Gate workshop".
"OSS Gate workshop" is an activity to increase OSS developers.
Here's been discussed in Japanese. Thanks.

作業ログ作成時の説明

以下のテンプレートを埋めてタイトルに設定します。埋め方例はスクロールすると見えてきます。

OSS Gate Workshop: ${LOCATION}: ${YEAR}-${MONTH}-${DAY}: ${ACCOUNT_NAME}: ${OSS_NAME}: Work log

タイトル例↓:

OSS Gate Workshop: Tokyo: 2017-01-16: kou: Rabbit: Work log

OSS Gateワークショップ関連情報

  • スライド:ワークショップの進行に使っているスライドがあります。
  • チャット:OSS開発に関することならなんでも相談できます。ワークショップが終わった後もオンラインで相談しながら継続的にOSSの開発に参加しましょう!
  • シナリオ:ワークショップの目的・内容・進め方の詳細が書いています。
  • 過去のビギナーの作業ログ:他の人の作業ログから学べることがいろいろあるはずです。
@OHMORIYUSUKE OHMORIYUSUKE added the work log ワークショップ作業メモ label Jan 14, 2024
@OHMORIYUSUKE OHMORIYUSUKE changed the title OSS Gate Workshop: PHP Lovers: 2024-01-15: OHMORIYUSUKE: ${OSS_NAME}: Work log OSS Gate Workshop: PHP Lovers: 2024-01-15: OHMORIYUSUKE: erusev/parsedown: Work log Jan 14, 2024
@OHMORIYUSUKE
Copy link
Contributor Author

マークダウンパーサーにPRを出したい
https://github.com/erusev/parsedown

@OHMORIYUSUKE
Copy link
Contributor Author

https://github.com/OHMORIYUSUKE/parsedown
フォークしました。

@OHMORIYUSUKE
Copy link
Contributor Author

OHMORIYUSUKE commented Jan 14, 2024

READMEのexampleコードを実行しました。

php main.php

main.php

<?php
$Parsedown = new Parsedown();

echo $Parsedown->text('Hello _Parsedown_!');

その結果、以下のような結果になりました。
ターミナルのログ

y_omori@MacBook-Pro-5 oss_gate % composer require erusev/parsedown
./composer.json has been created
Running composer update erusev/parsedown
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
  - Locking erusev/parsedown (1.7.4)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Downloading erusev/parsedown (1.7.4)
  - Installing erusev/parsedown (1.7.4): Extracting archive
Generating autoload files
No security vulnerability advisories found.
Using version ^1.7 for erusev/parsedown
y_omori@MacBook-Pro-5 oss_gate % php main.php
PHP Fatal error:  Uncaught Error: Class "Parsedown" not found in /Users/y_omori/project/oss_gate/main.php:2
Stack trace:
#0 {main}
  thrown in /Users/y_omori/project/oss_gate/main.php on line 2

Fatal error: Uncaught Error: Class "Parsedown" not found in /Users/y_omori/project/oss_gate/main.php:2
Stack trace:
#0 {main}
  thrown in /Users/y_omori/project/oss_gate/main.php on line 2
y_omori@MacBook-Pro-5 oss_gate % 

@OHMORIYUSUKE
Copy link
Contributor Author

main.phpを以下のコードにすることで実行できました。

<?php
require_once __DIR__ . '/vendor/autoload.php';

$Parsedown = new Parsedown();

echo $Parsedown->text('Hello _Parsedown_!');

@OHMORIYUSUKE
Copy link
Contributor Author

OHMORIYUSUKE commented Jan 14, 2024

https://github.com/erusev/parsedown/issues?page=1&q=is%3Aissue+is%3Aopen+example

exampleコードをコピペで動作しないことに関するissueは見つかりませんでした。

@OHMORIYUSUKE
Copy link
Contributor Author

OHMORIYUSUKE commented Jan 14, 2024

日本語でissueの下書きをしました。

issueのタイトル:READMEのexampleコードをそのまま実行したところ実行できませんでした
本文:
READMEのexampleでは以下のようなコードがありました。

$Parsedown = new Parsedown();

echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>

しかし、このコードではエラーが発生します。
正常に実行するにはautoloadを使ってParsedownを読み込む必要があります。

<?php
require_once __DIR__ . '/vendor/autoload.php';

$Parsedown = new Parsedown();

echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>

上記のようなコードにexampleを変更していただけませんか。

@OHMORIYUSUKE
Copy link
Contributor Author

OHMORIYUSUKE commented Jan 14, 2024

英語でissueを書きました。

I tried executing the example code in the README as is, but it did not work.

The README example had the following code.

$Parsedown = new Parsedown();

echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>

But this code gives me an error.
Parsedown must be loaded using autoload for it to run properly.

<?php
require_once __DIR__ . '/vendor/autoload.php';

$Parsedown = new Parsedown();

echo $Parsedown->text('Hello _Parsedown_!'); # prints: <p>Hello <em>Parsedown</em>!</p>

Could you please change the example to the code above?

@OHMORIYUSUKE
Copy link
Contributor Author

erusev/parsedown#862
issueを出しました。

@OHMORIYUSUKE
Copy link
Contributor Author

PHP UnitがPHP 8.3だと落ちる

y_omori@MacBook-Pro-5 parsedown % vendor/bin/phpunit 
PHP Fatal error:  Uncaught Error: Call to undefined function each() in /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/Util/Getopt.php:38
Stack trace:
#0 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/TextUI/Command.php(237): PHPUnit_Util_Getopt::getopt(Array, 'd:c:hv', Array)
#1 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/TextUI/Command.php(111): PHPUnit_TextUI_Command->handleArguments(Array)
#2 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/TextUI/Command.php(100): PHPUnit_TextUI_Command->run(Array, true)
#3 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/phpunit(52): PHPUnit_TextUI_Command::main()
#4 /Users/y_omori/project/parsedown/vendor/bin/phpunit(122): include('/Users/y_omori/...')
#5 {main}
  thrown in /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/Util/Getopt.php on line 38

Fatal error: Uncaught Error: Call to undefined function each() in /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/Util/Getopt.php:38
Stack trace:
#0 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/TextUI/Command.php(237): PHPUnit_Util_Getopt::getopt(Array, 'd:c:hv', Array)
#1 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/TextUI/Command.php(111): PHPUnit_TextUI_Command->handleArguments(Array)
#2 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/TextUI/Command.php(100): PHPUnit_TextUI_Command->run(Array, true)
#3 /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/phpunit(52): PHPUnit_TextUI_Command::main()
#4 /Users/y_omori/project/parsedown/vendor/bin/phpunit(122): include('/Users/y_omori/...')
#5 {main}
  thrown in /Users/y_omori/project/parsedown/vendor/phpunit/phpunit/src/Util/Getopt.php on line 38

原因はPHP 8ではeach関数がないため

@OHMORIYUSUKE
Copy link
Contributor Author

https://github.com/erusev/parsedown/tree/2.0.x

2.0.xブランチではPHP 8.x で動作する

@OHMORIYUSUKE
Copy link
Contributor Author

PHP 8.3 では composer install時にエラーになる。

y_omori@MacBook-Pro-5 parsedown % composer install
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
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - roave/infection-static-analysis-plugin[1.10.0, ..., 1.18.0] require php ~7.4.7|~8.0.0|~8.1.0 -> your php version (8.3.1) does not satisfy that requirement.
    - roave/infection-static-analysis-plugin[1.19.0, ..., 1.22.0] require php ~8.0.0|~8.1.0 -> your php version (8.3.1) does not satisfy that requirement.
    - roave/infection-static-analysis-plugin[1.23.0, ..., 1.25.0] require php ~8.0.0|~8.1.0|~8.2.0 -> your php version (8.3.1) does not satisfy that requirement.
    - roave/infection-static-analysis-plugin[1.26.0, ..., 1.32.0] require php ~8.1.0 || ~8.2.0 -> your php version (8.3.1) does not satisfy that requirement.
    - roave/infection-static-analysis-plugin 1.33.0 requires infection/infection 0.27.0 -> found infection/infection[0.27.0] but it conflicts with your root composer.json require (^0.25.0).
    - roave/infection-static-analysis-plugin 1.34.0 requires infection/infection 0.27.8 -> found infection/infection[0.27.8] but it conflicts with your root composer.json require (^0.25.0).
    - Root composer.json requires roave/infection-static-analysis-plugin ^1.10.0 -> satisfiable by roave/infection-static-analysis-plugin[1.10.0, ..., 1.34.0].

y_omori@MacBook-Pro-5 parsedown % 

@OHMORIYUSUKE
Copy link
Contributor Author

infection/infection のバージョンを0.27.0 に変更することで解決する

@OHMORIYUSUKE
Copy link
Contributor Author

変更後にvendorとcomposer.lockを削除し、改めてcomposer installを行うとインストールが完了する。

composer.jsonは以下のように変更される。
https://github.com/erusev/parsedown/pull/863/files

"config": {
        "allow-plugins": {
            "infection/extension-installer": true
        }
    }

@OHMORIYUSUKE
Copy link
Contributor Author

y_omori@MacBook-Pro-5 parsedown % composer install        
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
Updating dependencies
Lock file operations: 80 installs, 0 updates, 0 removals
  - Locking amphp/amp (v2.6.2)
  - Locking amphp/byte-stream (v1.8.1)
  - Locking colinodell/json5 (v2.3.0)
  - Locking composer/pcre (3.1.1)
  - Locking composer/semver (3.4.0)
  - Locking composer/xdebug-handler (3.0.3)
  - Locking dnoegel/php-xdg-base-dir (v0.1.1)
  - Locking doctrine/deprecations (1.1.2)
  - Locking doctrine/instantiator (2.0.0)
  - Locking felixfbecker/advanced-json-rpc (v3.2.1)
  - Locking felixfbecker/language-server-protocol (v1.5.2)
  - Locking fidry/cpu-core-counter (1.0.0)
  - Locking friendsofphp/php-cs-fixer (v3.46.0)
  - Locking infection/abstract-testframework-adapter (0.5.0)
  - Locking infection/extension-installer (0.1.2)
  - Locking infection/include-interceptor (0.2.5)
  - Locking infection/infection (0.27.8)
  - Locking justinrainbow/json-schema (v5.2.13)
  - Locking myclabs/deep-copy (1.11.1)
  - Locking netresearch/jsonmapper (v4.2.0)
  - Locking nikic/php-parser (v4.18.0)
  - Locking ocramius/package-versions (2.8.0)
  - Locking ondram/ci-detector (4.1.0)
  - Locking openlss/lib-array2xml (1.0.0)
  - Locking phar-io/manifest (2.0.3)
  - Locking phar-io/version (3.2.1)
  - Locking phpdocumentor/reflection-common (2.2.0)
  - Locking phpdocumentor/reflection-docblock (5.3.0)
  - Locking phpdocumentor/type-resolver (1.8.0)
  - Locking phpstan/phpdoc-parser (1.25.0)
  - Locking phpunit/php-code-coverage (9.2.30)
  - 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.15)
  - Locking psr/container (2.0.2)
  - Locking psr/event-dispatcher (1.0.0)
  - Locking psr/log (3.0.0)
  - Locking roave/infection-static-analysis-plugin (1.34.0)
  - Locking sanmai/later (0.1.4)
  - Locking sanmai/pipeline (v6.9)
  - 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.3)
  - 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.4)
  - 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/console (v6.4.2)
  - Locking symfony/deprecation-contracts (v3.4.0)
  - Locking symfony/event-dispatcher (v7.0.2)
  - Locking symfony/event-dispatcher-contracts (v3.4.0)
  - Locking symfony/filesystem (v7.0.0)
  - Locking symfony/finder (v7.0.0)
  - Locking symfony/options-resolver (v7.0.0)
  - Locking symfony/polyfill-ctype (v1.28.0)
  - Locking symfony/polyfill-intl-grapheme (v1.28.0)
  - Locking symfony/polyfill-intl-normalizer (v1.28.0)
  - Locking symfony/polyfill-mbstring (v1.28.0)
  - Locking symfony/polyfill-php80 (v1.28.0)
  - Locking symfony/polyfill-php81 (v1.28.0)
  - Locking symfony/process (v7.0.2)
  - Locking symfony/service-contracts (v3.4.1)
  - Locking symfony/stopwatch (v7.0.0)
  - Locking symfony/string (v7.0.2)
  - Locking thecodingmachine/safe (v2.5.0)
  - Locking theseer/tokenizer (1.2.2)
  - Locking vimeo/psalm (4.30.0)
  - Locking webmozart/assert (1.11.0)
  - Locking webmozart/path-util (2.3.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 80 installs, 0 updates, 0 removals
infection/extension-installer contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "infection/extension-installer" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
  - Installing infection/extension-installer (0.1.2): Extracting archive
  - Installing symfony/polyfill-mbstring (v1.28.0): Extracting archive
  - Installing colinodell/json5 (v2.3.0): Extracting archive
  - Installing composer/pcre (3.1.1): Extracting archive
  - Installing fidry/cpu-core-counter (1.0.0): Extracting archive
  - Installing psr/container (2.0.2): Extracting archive
  - Installing symfony/service-contracts (v3.4.1): Extracting archive
  - Installing symfony/stopwatch (v7.0.0): Extracting archive
  - Installing symfony/process (v7.0.2): Extracting archive
  - Installing symfony/polyfill-php81 (v1.28.0): Extracting archive
  - Installing symfony/polyfill-php80 (v1.28.0): Extracting archive
  - Installing symfony/deprecation-contracts (v3.4.0): Extracting archive
  - Installing symfony/options-resolver (v7.0.0): Extracting archive
  - Installing symfony/finder (v7.0.0): Extracting archive
  - Installing symfony/polyfill-ctype (v1.28.0): Extracting archive
  - Installing symfony/filesystem (v7.0.0): Extracting archive
  - Installing psr/event-dispatcher (1.0.0): Extracting archive
  - Installing symfony/event-dispatcher-contracts (v3.4.0): Extracting archive
  - Installing symfony/event-dispatcher (v7.0.2): Extracting archive
  - Installing symfony/polyfill-intl-normalizer (v1.28.0): Extracting archive
  - Installing symfony/polyfill-intl-grapheme (v1.28.0): Extracting archive
  - Installing symfony/string (v7.0.2): Extracting archive
  - Installing symfony/console (v6.4.2): Extracting archive
  - Installing sebastian/diff (4.0.5): Extracting archive
  - Installing psr/log (3.0.0): Extracting archive
  - Installing composer/xdebug-handler (3.0.3): Extracting archive
  - Installing composer/semver (3.4.0): Extracting archive
  - Installing friendsofphp/php-cs-fixer (v3.46.0): Extracting archive
  - Installing infection/abstract-testframework-adapter (0.5.0): Extracting archive
  - Installing infection/include-interceptor (0.2.5): Extracting archive
  - Installing justinrainbow/json-schema (v5.2.13): Extracting archive
  - Installing ondram/ci-detector (4.1.0): Extracting archive
  - Installing webmozart/assert (1.11.0): Extracting archive
  - Installing phpstan/phpdoc-parser (1.25.0): Extracting archive
  - Installing phpdocumentor/reflection-common (2.2.0): Extracting archive
  - Installing doctrine/deprecations (1.1.2): Extracting archive
  - Installing phpdocumentor/type-resolver (1.8.0): Extracting archive
  - Installing phpdocumentor/reflection-docblock (5.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/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.2): Extracting archive
  - Installing nikic/php-parser (v4.18.0): Extracting archive
  - Installing sebastian/lines-of-code (1.0.4): Extracting archive
  - Installing sebastian/complexity (2.0.3): Extracting archive
  - Installing sebastian/code-unit-reverse-lookup (2.0.3): Extracting archive
  - Installing phpunit/php-code-coverage (9.2.30): 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 (2.0.0): Extracting archive
  - Installing phpunit/phpunit (9.6.15): Extracting archive
  - Installing webmozart/path-util (2.3.0): Extracting archive
  - Installing openlss/lib-array2xml (1.0.0): Extracting archive
  - Installing netresearch/jsonmapper (v4.2.0): Extracting archive
  - Installing felixfbecker/language-server-protocol (v1.5.2): Extracting archive
  - Installing felixfbecker/advanced-json-rpc (v3.2.1): Extracting archive
  - Installing dnoegel/php-xdg-base-dir (v0.1.1): Extracting archive
  - Installing ocramius/package-versions (2.8.0): Extracting archive
  - Installing amphp/amp (v2.6.2): Extracting archive
  - Installing amphp/byte-stream (v1.8.1): Extracting archive
  - Installing vimeo/psalm (4.30.0): Extracting archive
  - Installing sanmai/later (0.1.4): Extracting archive
  - Installing thecodingmachine/safe (v2.5.0): Extracting archive
  - Installing sanmai/pipeline (v6.9): Extracting archive
  - Installing infection/infection (0.27.8): Extracting archive
  - Installing roave/infection-static-analysis-plugin (1.34.0): Extracting archive
5 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package webmozart/path-util is abandoned, you should avoid using it. Use symfony/filesystem instead.
Generating autoload files
57 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
infection/extension-installer: No extensions found
y_omori@MacBook-Pro-5 parsedown % 

@OHMORIYUSUKE
Copy link
Contributor Author

PHPUnitも正常に完了する。

y_omori@MacBook-Pro-5 parsedown % vendor/bin/phpunit      
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.

...............................................................  63 / 713 (  8%)
............................................................... 126 / 713 ( 17%)
............................................................... 189 / 713 ( 26%)
............................................................... 252 / 713 ( 35%)
............................................................... 315 / 713 ( 44%)
............................................................... 378 / 713 ( 53%)
............................................................... 441 / 713 ( 61%)
............................................................... 504 / 713 ( 70%)
............................................................... 567 / 713 ( 79%)
............................................................... 630 / 713 ( 88%)
............................................................... 693 / 713 ( 97%)
....................                                            713 / 713 (100%)

Time: 00:00.078, Memory: 16.00 MB

OK (713 tests, 804 assertions)
y_omori@MacBook-Pro-5 parsedown % 

@OHMORIYUSUKE
Copy link
Contributor Author

自分のアカウントにフォークする。
https://github.com/OHMORIYUSUKE/parsedown

@OHMORIYUSUKE
Copy link
Contributor Author

自分のアカウントのレポジトリ、2.0.xブランチからブランチ( https://github.com/OHMORIYUSUKE/parsedown/tree/feat/php8.3-phpunit )を作る。

作ったブランチからフォーク元のレポジトリの2.0.xブランチ( https://github.com/erusev/parsedown/tree/2.0.x )にPRを出す。

@OHMORIYUSUKE
Copy link
Contributor Author

PRを作成しました。

erusev/parsedown#863

@OHMORIYUSUKE
Copy link
Contributor Author

erusev/parsedown@c045020

ciにphp 8.3を追加しました。

Copy link

おつかれさまでした!

ワークショップの終了にともないissueを閉じますが、このまま作業メモとして使っても構いません 👌

ワークショップの感想を集めています!

ブログなどに書かれた際は、このページへリンクの追加をお願いします 🙏

またの参加をお待ちしています!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work log ワークショップ作業メモ
Projects
None yet
Development

No branches or pull requests

1 participant