diff --git a/.gitignore b/.gitignore index 95bd72b9..a777289c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -bin obj *.sln.DotSettings.user .vs diff --git a/php/README.md b/php/README.md index 91ca1475..daa62345 100644 --- a/php/README.md +++ b/php/README.md @@ -1,3 +1,7 @@ +# 高木追記 +php8のバイナリをgitにあげているので以下コマンドで一時的にパスを通してください +export PATH=./bin:$PATH + # GildedRose Kata - PHP Version See the [top level readme](../README.md) for general information about this exercise. This is the PHP version of the diff --git a/php/bin/pear b/php/bin/pear new file mode 100755 index 00000000..92c3caf1 --- /dev/null +++ b/php/bin/pear @@ -0,0 +1,28 @@ +#!/bin/sh + +# first find which PHP binary to use +if test "x$PHP_PEAR_PHP_BIN" != "x"; then + PHP="$PHP_PEAR_PHP_BIN" +else + if test "/Applications/MAMP/bin/php/php8.0.8/bin/php" = '@'php_bin'@'; then + PHP=php + else + PHP="/Applications/MAMP/bin/php/php8.0.8/bin/php" + fi +fi + +# then look for the right pear include dir +if test "x$PHP_PEAR_INSTALL_DIR" != "x"; then + INCDIR=$PHP_PEAR_INSTALL_DIR + INCARG="-d include_path=$PHP_PEAR_INSTALL_DIR" +else + if test "/Applications/MAMP/bin/php/php8.0.8/lib/php" = '@'php_dir'@'; then + INCDIR=`dirname $0` + INCARG="" + else + INCDIR="/Applications/MAMP/bin/php/php8.0.8/lib/php" + INCARG="-d include_path=/Applications/MAMP/bin/php/php8.0.8/lib/php" + fi +fi + +exec $PHP -C -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d auto_append_file="" $INCDIR/pearcmd.php "$@" diff --git a/php/bin/peardev b/php/bin/peardev new file mode 100755 index 00000000..0f6d9b26 --- /dev/null +++ b/php/bin/peardev @@ -0,0 +1,28 @@ +#!/bin/sh + +# first find which PHP binary to use +if test "x$PHP_PEAR_PHP_BIN" != "x"; then + PHP="$PHP_PEAR_PHP_BIN" +else + if test "/Applications/MAMP/bin/php/php8.0.8/bin/php" = '@'php_bin'@'; then + PHP=php + else + PHP="/Applications/MAMP/bin/php/php8.0.8/bin/php" + fi +fi + +# then look for the right pear include dir +if test "x$PHP_PEAR_INSTALL_DIR" != "x"; then + INCDIR=$PHP_PEAR_INSTALL_DIR + INCARG="-d include_path=$PHP_PEAR_INSTALL_DIR" +else + if test "/Applications/MAMP/bin/php/php8.0.8/lib/php" = '@'php_dir'@'; then + INCDIR=`dirname $0` + INCARG="" + else + INCDIR="/Applications/MAMP/bin/php/php8.0.8/lib/php" + INCARG="-d include_path=/Applications/MAMP/bin/php/php8.0.8/lib/php" + fi +fi + +exec $PHP -d date.timezone=UTC -d memory_limit="-1" -C -q $INCARG -d output_buffering=1 -d open_basedir="" -d safe_mode=0 -d register_argc_argv="On" -d auto_prepend_file="" -d variables_order=EGPCS -d auto_append_file="" $INCDIR/pearcmd.php "$@" diff --git a/php/bin/pecl b/php/bin/pecl new file mode 100755 index 00000000..087626a7 --- /dev/null +++ b/php/bin/pecl @@ -0,0 +1,28 @@ +#!/bin/sh + +# first find which PHP binary to use +if test "x$PHP_PEAR_PHP_BIN" != "x"; then + PHP="$PHP_PEAR_PHP_BIN" +else + if test "/Applications/MAMP/bin/php/php8.0.8/bin/php" = '@'php_bin'@'; then + PHP=php + else + PHP="/Applications/MAMP/bin/php/php8.0.8/bin/php" + fi +fi + +# then look for the right pear include dir +if test "x$PHP_PEAR_INSTALL_DIR" != "x"; then + INCDIR=$PHP_PEAR_INSTALL_DIR + INCARG="-d include_path=$PHP_PEAR_INSTALL_DIR" +else + if test "/Applications/MAMP/bin/php/php8.0.8/lib/php" = '@'php_dir'@'; then + INCDIR=`dirname $0` + INCARG="" + else + INCDIR="/Applications/MAMP/bin/php/php8.0.8/lib/php" + INCARG="-d include_path=/Applications/MAMP/bin/php/php8.0.8/lib/php" + fi +fi + +exec $PHP -C -q $INCARG -d date.timezone=UTC -d output_buffering=1 -d variables_order=EGPCS -d safe_mode=0 -d register_argc_argv="On" $INCDIR/peclcmd.php "$@" diff --git a/php/bin/phar b/php/bin/phar new file mode 100755 index 00000000..eae27ad1 Binary files /dev/null and b/php/bin/phar differ diff --git a/php/bin/phar.phar b/php/bin/phar.phar new file mode 100755 index 00000000..eae27ad1 Binary files /dev/null and b/php/bin/phar.phar differ diff --git a/php/bin/php b/php/bin/php new file mode 100755 index 00000000..390066a7 Binary files /dev/null and b/php/bin/php differ diff --git a/php/bin/php-cgi b/php/bin/php-cgi new file mode 100755 index 00000000..85e7e622 Binary files /dev/null and b/php/bin/php-cgi differ diff --git a/php/bin/php-config b/php/bin/php-config new file mode 100755 index 00000000..08e577f0 --- /dev/null +++ b/php/bin/php-config @@ -0,0 +1,98 @@ +#! /bin/sh + +SED="/usr/bin/sed" +prefix="/Applications/MAMP/bin/php/php8.0.8" +datarootdir="/Applications/MAMP/bin/php/php8.0.8/php" +exec_prefix="/Applications/MAMP/bin/php/php8.0.8" +version="8.0.8" +vernum="80008" +include_dir="${prefix}/include/php" +includes="-I$include_dir -I$include_dir/main -I$include_dir/TSRM -I$include_dir/Zend -I$include_dir/ext -I$include_dir/ext/date/lib" +ldflags=" -L/Applications/MAMP/Library/lib" +libs=" -largon2 -lreadline -lncurses -lldap -llber -lstdc++ -liconv -lintl -lbz2 -lnetwork -lm -lresolv -lxml2 -lkrb5 -lssl -lcrypto -lsqlite3 -lz -lcurl -lssl -lcrypto -lxml2 -lssl -lcrypto -lz -lpng16 -lz -lwebp -ljpeg -lfreetype -licuio -licui18n -licuuc -licudata -lonig -lsqlite3 -lxml2 -lxml2 -lsodium -largon2 -lxml2 -lxml2 -lxml2 -lxslt -lxml2 -lz -llzma -lpthread -liconv -licui18n -licuuc -licudata -lm -lxml2 -lexslt -lxslt -lxml2 -lz -llzma -lpthread -liconv -licui18n -licuuc -licudata -lm -lxml2 -lzip -lz -lssl -lcrypto " +extension_dir='/Applications/MAMP/bin/php/php8.0.8/lib/php/extensions/no-debug-non-zts-20200930' +man_dir=`eval echo ${datarootdir}/man` +program_prefix="" +program_suffix="" +exe_extension="" +php_cli_binary=NONE +php_cgi_binary=NONE +configure_options=" '--with-apxs2=/Applications/MAMP/Library/bin/apxs' '--with-zlib' '--with-zlib-dir=/Applications/MAMP/Library' '--prefix=/Applications/MAMP/bin/php/php8.0.8' '--exec-prefix=/Applications/MAMP/bin/php/php8.0.8' '--sysconfdir=/Applications/MAMP/bin/php/php8.0.8/conf' '--with-config-file-path=/Applications/MAMP/bin/php/php8.0.8/conf' '--enable-ftp' '--with-bz2=/Applications/MAMP/Library' '--with-mysqli=mysqlnd' '--enable-mbstring=all' '--with-curl=/Applications/MAMP/Library' '--enable-sockets' '--enable-bcmath' '--enable-soap' '--enable-calendar' '--with-pgsql=shared,/Applications/MAMP/Library/pg' '--enable-exif' '--with-xsl=/Applications/MAMP/Library' '--with-pdo-mysql=mysqlnd' '--with-pdo-pgsql=shared,/Applications/MAMP/Library/pg' '--with-openssl=/Applications/MAMP/Library' '--enable-opcache' '--with-tidy=shared,/Applications/MAMP/Library' '--with-readline' '--with-mhash' '--with-sodium=/Applications/MAMP/Library' '--with-password-argon2=/Applications/MAMP/Library' '--with-zip' '--with-xmlrpc' '--with-kerberos' '--with-pdo-sqlite' '--with-sqlite3' '--with-ldap=/Applications/MAMP/Library' '--with-ldap-sasl' '--with-imap=shared,/Applications/MAMP/Library/lib/imap-2007f/lib' '--with-imap-ssl=/Applications/MAMP/Library' '--disable-phpdbg' '--enable-cgi' '--with-webp' '--with-jpeg' '--with-freetype' '--enable-pcntl' '--enable-intl' '--with-iconv=/Applications/MAMP/Library' '--with-gettext=/Applications/MAMP/Library' '--enable-gd' 'KERBEROS_CFLAGS=-I/usr/include' 'KERBEROS_LIBS=-lkrb5' 'SQLITE_CFLAGS= ' 'SQLITE_LIBS=-lsqlite3' 'JPEG_CFLAGS= ' 'JPEG_LIBS=-ljpeg' 'SASL_CFLAGS=-I/usr/include/sasl' 'SASL_LIBS=-lsasl2'" +php_sapis=" apache2handler cli cgi" +ini_dir="" +ini_path="/Applications/MAMP/bin/php/php8.0.8/conf" + +# Set php_cli_binary and php_cgi_binary if available +for sapi in $php_sapis; do + case $sapi in + cli) + php_cli_binary="${exec_prefix}/bin/${program_prefix}php${program_suffix}${exe_extension}" + ;; + cgi) + php_cgi_binary="${exec_prefix}/bin/${program_prefix}php-cgi${program_suffix}${exe_extension}" + ;; + esac +done + +# Determine which (if any) php binary is available +if test "$php_cli_binary" != "NONE"; then + php_binary="$php_cli_binary" +else + php_binary="$php_cgi_binary" +fi + +# Remove quotes +configure_options=`echo $configure_options | $SED -e "s#'##g"` + +case "$1" in +--prefix) + echo $prefix;; +--includes) + echo $includes;; +--ldflags) + echo $ldflags;; +--libs) + echo $libs;; +--extension-dir) + echo $extension_dir;; +--include-dir) + echo $include_dir;; +--php-binary) + echo $php_binary;; +--php-sapis) + echo $php_sapis;; +--configure-options) + echo $configure_options;; +--man-dir) + echo $man_dir;; +--ini-path) + echo $ini_path;; +--ini-dir) + echo $ini_dir;; +--version) + echo $version;; +--vernum) + echo $vernum;; +*) + cat << EOF +Usage: $0 [OPTION] +Options: + --prefix [$prefix] + --includes [$includes] + --ldflags [$ldflags] + --libs [$libs] + --extension-dir [$extension_dir] + --include-dir [$include_dir] + --man-dir [$man_dir] + --php-binary [$php_binary] + --php-sapis [$php_sapis] + --ini-path [$ini_path] + --ini-dir [$ini_dir] + --configure-options [$configure_options] + --version [$version] + --vernum [$vernum] +EOF + exit 1;; +esac + +exit 0 diff --git a/php/bin/phpdbg b/php/bin/phpdbg new file mode 100755 index 00000000..1cf73263 Binary files /dev/null and b/php/bin/phpdbg differ diff --git a/php/bin/phpize b/php/bin/phpize new file mode 100755 index 00000000..7c2f0be6 --- /dev/null +++ b/php/bin/phpize @@ -0,0 +1,211 @@ +#!/bin/sh + +# Variable declaration +prefix='/Applications/MAMP/bin/php/php8.0.8' +datarootdir='/Applications/MAMP/bin/php/php8.0.8/php' +exec_prefix="`eval echo /Applications/MAMP/bin/php/php8.0.8`" +phpdir="`eval echo ${exec_prefix}/lib/php`/build" +includedir="`eval echo ${prefix}/include`/php" +builddir="`pwd`" +SED="/usr/bin/sed" + +FILES_BUILD="php.m4 shtool libtool.m4 ax_check_compile_flag.m4 ax_gcc_func_attribute.m4 php_cxx_compile_stdcxx.m4 pkg.m4 \ + config.guess config.sub ltmain.sh Makefile.global gen_stub.php" +FILES="run-tests*.php" +CLEAN_FILES="$FILES *.o *.lo *.la .libs/ build/ modules/ \ + config.nice configure configure.ac \ + config.h config.h.in conftest* libtool config.cache autom4te.cache/ \ + config.log config.status Makefile Makefile.fragments Makefile.objects confdefs.h \ + run-tests*.php tests/*.diff tests/*.exp tests/*.log tests/*.out tests/*.php" + +# function declaration +phpize_usage() +{ + echo "Usage: $0 [--clean|--help|--version|-v]" +} + +phpize_no_configm4() +{ + if test $@ -eq 1; then + clean=" --clean" + fi + + echo "Cannot find config.m4. " + echo "Make sure that you run '$0$clean' in the top level source directory of the module" + echo +} + +phpize_clean() +{ + echo "Cleaning.." + for i in $CLEAN_FILES; do + if test -f "$i"; then + rm -f $i + elif test -d "$i"; then + rm -rf $i + fi + done +} + +phpize_check_configm4() +{ + if test ! -r config.m4; then + phpize_no_configm4 $@ + exit 1 + fi + +} + +phpize_get_api_numbers() +{ + # extracting API NOs: + PHP_API_VERSION=`grep '#define PHP_API_VERSION' $includedir/main/php.h|$SED 's/#define PHP_API_VERSION//'` + ZEND_MODULE_API_NO=`grep '#define ZEND_MODULE_API_NO' $includedir/Zend/zend_modules.h|$SED 's/#define ZEND_MODULE_API_NO//'` + ZEND_EXTENSION_API_NO=`grep '#define ZEND_EXTENSION_API_NO' $includedir/Zend/zend_extensions.h|$SED 's/#define ZEND_EXTENSION_API_NO//'` +} + +phpize_print_api_numbers() +{ + phpize_get_api_numbers + echo "Configuring for:" + echo "PHP Api Version: "$PHP_API_VERSION + echo "Zend Module Api No: "$ZEND_MODULE_API_NO + echo "Zend Extension Api No: "$ZEND_EXTENSION_API_NO +} + +phpize_check_build_files() +{ + if test ! -d "$phpdir"; then + cat < configure.ac +} + +phpize_autotools() +{ + # Remove aclocal.m4 if present. It is automatically included by autoconf but + # not used by the PHP build system since PHP 7.4. + rm -f aclocal.m4 + + $PHP_AUTOCONF || exit 1 + $PHP_AUTOHEADER || exit 1 +} + +# Main script + +case "$1" in + # Cleanup + --clean) + phpize_check_configm4 1 + phpize_clean + exit 0 + ;; + + # Usage + --help) + phpize_usage + exit 0 + ;; + + # Version + --version|-v) + phpize_print_api_numbers + exit 0 + ;; + + # Default + *) + phpize_check_configm4 0 + + phpize_check_build_files + + phpize_print_api_numbers + + phpize_copy_files + + phpize_replace_prefix + + phpize_check_shtool + + phpize_check_autotools + + phpize_autotools + ;; +esac + +exit 0 diff --git a/php/tests/GildedRoseTest.php b/php/tests/GildedRoseTest.php index 52e7ddc6..19003687 100644 --- a/php/tests/GildedRoseTest.php +++ b/php/tests/GildedRoseTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Tests; +use ApprovalTests\Approvals; use GildedRose\GildedRose; use GildedRose\Item; use PHPUnit\Framework\TestCase; @@ -17,4 +18,30 @@ class GildedRoseTest extends TestCase $gildedRose->updateQuality(); $this->assertSame('fixme', $items[0]->name); } -} + + public function testApproveArray() + { + $list = ['zero', 'oxe', 'two', 'three', 'four', 'five']; + Approvals::approveList($list); + } + + public function testApproveMap() + { + $list = [ + 'zero' => 'Lance', + 'one' => 'Jam', + 'two' => 'James', + 'three' => 'LLewellyn', + 'four' => 'Asaph', + 'five' => 'Dana' + ]; + Approvals::approveList($list); + } + + public function testApproveString() + { + $fudge = 'fadge'; + Approvals::approveString($fudge); + + } +} \ No newline at end of file diff --git a/php/tests/approvals/GildedRoseTest.testApproveArray.approved.txt b/php/tests/approvals/GildedRoseTest.testApproveArray.approved.txt new file mode 100644 index 00000000..37c79b3d --- /dev/null +++ b/php/tests/approvals/GildedRoseTest.testApproveArray.approved.txt @@ -0,0 +1,6 @@ +[0] -> zero +[1] -> one +[2] -> two +[3] -> three +[4] -> four +[5] -> five diff --git a/php/tests/approvals/GildedRoseTest.testApproveArray.received.txt b/php/tests/approvals/GildedRoseTest.testApproveArray.received.txt new file mode 100644 index 00000000..a4c7afb6 --- /dev/null +++ b/php/tests/approvals/GildedRoseTest.testApproveArray.received.txt @@ -0,0 +1,6 @@ +[0] -> zero +[1] -> oxe +[2] -> two +[3] -> three +[4] -> four +[5] -> five diff --git a/php/tests/approvals/GildedRoseTest.testApproveMap.approved.txt b/php/tests/approvals/GildedRoseTest.testApproveMap.approved.txt new file mode 100644 index 00000000..d700139a --- /dev/null +++ b/php/tests/approvals/GildedRoseTest.testApproveMap.approved.txt @@ -0,0 +1,6 @@ +[zero] -> Lance +[one] -> Jim +[two] -> James +[three] -> LLewellyn +[four] -> Asaph +[five] -> Dana diff --git a/php/tests/approvals/GildedRoseTest.testApproveMap.received.txt b/php/tests/approvals/GildedRoseTest.testApproveMap.received.txt new file mode 100644 index 00000000..23a0c1b7 --- /dev/null +++ b/php/tests/approvals/GildedRoseTest.testApproveMap.received.txt @@ -0,0 +1,6 @@ +[zero] -> Lance +[one] -> Jam +[two] -> James +[three] -> LLewellyn +[four] -> Asaph +[five] -> Dana diff --git a/php/tests/approvals/GildedRoseTest.testApproveString.approved.txt b/php/tests/approvals/GildedRoseTest.testApproveString.approved.txt new file mode 100644 index 00000000..dd422ba1 --- /dev/null +++ b/php/tests/approvals/GildedRoseTest.testApproveString.approved.txt @@ -0,0 +1 @@ +fudge \ No newline at end of file diff --git a/php/tests/approvals/GildedRoseTest.testApproveString.received.txt b/php/tests/approvals/GildedRoseTest.testApproveString.received.txt new file mode 100644 index 00000000..21d3f582 --- /dev/null +++ b/php/tests/approvals/GildedRoseTest.testApproveString.received.txt @@ -0,0 +1 @@ +fadge \ No newline at end of file