From d1b63063249ff9eb374a38c9f9282d6e3d1f0433 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Tue, 23 Apr 2019 14:56:30 -0700 Subject: [PATCH 1/6] Move php to php5 and add a php7 example that uses composer --- .gitignore | 1 + {php => php5}/.buildpath | 0 {php => php5}/.project | 0 .../com.piece_framework.makegood.core.prefs | 0 .../.settings/org.eclipse.php.core.prefs | 0 ....eclipse.wst.common.project.facet.core.xml | 0 {php => php5}/phpunit.xml | 0 {php => php5}/src/gilded_rose.php | 0 {php => php5}/src/texttest_fixture.php | 0 {php => php5}/test/bootstrap.php | 0 {php => php5}/test/gilded_rose_test.php | 0 php7/composer.json | 10 + php7/composer.lock | 1491 +++++++++++++++++ php7/fixtures/texttest_fixture.php | 38 + php7/phpunit.xml | 13 + php7/src/GildedRose.php | 63 + php7/src/Item.php | 21 + php7/test/GildedRoseTest.php | 14 + php7/test/bootstrap.php | 2 + 19 files changed, 1653 insertions(+) rename {php => php5}/.buildpath (100%) rename {php => php5}/.project (100%) rename {php => php5}/.settings/com.piece_framework.makegood.core.prefs (100%) rename {php => php5}/.settings/org.eclipse.php.core.prefs (100%) rename {php => php5}/.settings/org.eclipse.wst.common.project.facet.core.xml (100%) rename {php => php5}/phpunit.xml (100%) rename {php => php5}/src/gilded_rose.php (100%) rename {php => php5}/src/texttest_fixture.php (100%) rename {php => php5}/test/bootstrap.php (100%) rename {php => php5}/test/gilded_rose_test.php (100%) create mode 100644 php7/composer.json create mode 100644 php7/composer.lock create mode 100644 php7/fixtures/texttest_fixture.php create mode 100644 php7/phpunit.xml create mode 100644 php7/src/GildedRose.php create mode 100644 php7/src/Item.php create mode 100644 php7/test/GildedRoseTest.php create mode 100644 php7/test/bootstrap.php diff --git a/.gitignore b/.gitignore index 42abe190..1ff57af1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bin obj *.sln.DotSettings.user .vs +vendor diff --git a/php/.buildpath b/php5/.buildpath similarity index 100% rename from php/.buildpath rename to php5/.buildpath diff --git a/php/.project b/php5/.project similarity index 100% rename from php/.project rename to php5/.project diff --git a/php/.settings/com.piece_framework.makegood.core.prefs b/php5/.settings/com.piece_framework.makegood.core.prefs similarity index 100% rename from php/.settings/com.piece_framework.makegood.core.prefs rename to php5/.settings/com.piece_framework.makegood.core.prefs diff --git a/php/.settings/org.eclipse.php.core.prefs b/php5/.settings/org.eclipse.php.core.prefs similarity index 100% rename from php/.settings/org.eclipse.php.core.prefs rename to php5/.settings/org.eclipse.php.core.prefs diff --git a/php/.settings/org.eclipse.wst.common.project.facet.core.xml b/php5/.settings/org.eclipse.wst.common.project.facet.core.xml similarity index 100% rename from php/.settings/org.eclipse.wst.common.project.facet.core.xml rename to php5/.settings/org.eclipse.wst.common.project.facet.core.xml diff --git a/php/phpunit.xml b/php5/phpunit.xml similarity index 100% rename from php/phpunit.xml rename to php5/phpunit.xml diff --git a/php/src/gilded_rose.php b/php5/src/gilded_rose.php similarity index 100% rename from php/src/gilded_rose.php rename to php5/src/gilded_rose.php diff --git a/php/src/texttest_fixture.php b/php5/src/texttest_fixture.php similarity index 100% rename from php/src/texttest_fixture.php rename to php5/src/texttest_fixture.php diff --git a/php/test/bootstrap.php b/php5/test/bootstrap.php similarity index 100% rename from php/test/bootstrap.php rename to php5/test/bootstrap.php diff --git a/php/test/gilded_rose_test.php b/php5/test/gilded_rose_test.php similarity index 100% rename from php/test/gilded_rose_test.php rename to php5/test/gilded_rose_test.php diff --git a/php7/composer.json b/php7/composer.json new file mode 100644 index 00000000..48e981e6 --- /dev/null +++ b/php7/composer.json @@ -0,0 +1,10 @@ +{ + "require-dev": { + "phpunit/phpunit": "^8.1" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } + } +} diff --git a/php7/composer.lock b/php7/composer.lock new file mode 100644 index 00000000..fd005c09 --- /dev/null +++ b/php7/composer.lock @@ -0,0 +1,1491 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "cfb0b0d6a2a4e815ce74cdf8e7afdd1f", + "packages": [], + "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "a2c590166b2133a4633738648b6b064edae0814a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2019-03-17T17:37:11+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.9.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", + "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" + }, + "require-dev": { + "doctrine/collections": "^1.0", + "doctrine/common": "^2.6", + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + }, + "files": [ + "src/DeepCopy/deep_copy.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "time": "2019-04-07T13:18:21+00:00" + }, + { + "name": "phar-io/manifest", + "version": "1.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "phar-io/version": "^2.0", + "php": "^5.6 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "time": "2018-07-08T19:23:20+00:00" + }, + { + "name": "phar-io/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "time": "2018-07-08T19:19:57+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "phpunit/phpunit": "^4.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "time": "2017-09-11T18:02:19+00:00" + }, + { + "name": "phpdocumentor/reflection-docblock", + "version": "4.3.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", + "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "shasum": "" + }, + "require": { + "php": "^7.0", + "phpdocumentor/reflection-common": "^1.0.0", + "phpdocumentor/type-resolver": "^0.4.0", + "webmozart/assert": "^1.0" + }, + "require-dev": { + "doctrine/instantiator": "~1.0.5", + "mockery/mockery": "^1.0", + "phpunit/phpunit": "^6.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "time": "2017-11-30T07:14:17+00:00" + }, + { + "name": "phpdocumentor/type-resolver", + "version": "0.4.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", + "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "shasum": "" + }, + "require": { + "php": "^5.5 || ^7.0", + "phpdocumentor/reflection-common": "^1.0" + }, + "require-dev": { + "mockery/mockery": "^0.9.4", + "phpunit/phpunit": "^5.2||^4.8.24" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mike van Riel", + "email": "me@mikevanriel.com" + } + ], + "time": "2017-07-14T14:27:02+00:00" + }, + { + "name": "phpspec/prophecy", + "version": "1.8.0", + "source": { + "type": "git", + "url": "https://github.com/phpspec/prophecy.git", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.3|^7.0", + "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", + "sebastian/recursion-context": "^1.0|^2.0|^3.0" + }, + "require-dev": { + "phpspec/phpspec": "^2.5|^3.2", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.8.x-dev" + } + }, + "autoload": { + "psr-0": { + "Prophecy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + }, + { + "name": "Marcello Duarte", + "email": "marcello.duarte@gmail.com" + } + ], + "description": "Highly opinionated mocking framework for PHP 5.3+", + "homepage": "https://github.com/phpspec/prophecy", + "keywords": [ + "Double", + "Dummy", + "fake", + "mock", + "spy", + "stub" + ], + "time": "2018-08-05T17:53:17+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "7.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0317a769a81845c390e19684d9ba25d7f6aa4707", + "reference": "0317a769a81845c390e19684d9ba25d7f6aa4707", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^7.2", + "phpunit/php-file-iterator": "^2.0.2", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-token-stream": "^3.0.1", + "sebastian/code-unit-reverse-lookup": "^1.0.1", + "sebastian/environment": "^4.1", + "sebastian/version": "^2.0.1", + "theseer/tokenizer": "^1.1" + }, + "require-dev": { + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "ext-xdebug": "^2.6.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "time": "2019-02-26T07:38:26+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "050bedf145a257b1ff02746c31894800e5122946" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", + "reference": "050bedf145a257b1ff02746c31894800e5122946", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "time": "2018-09-13T20:33:42+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "time": "2015-06-21T13:50:34+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "2.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/8b389aebe1b8b0578430bda0c7c95a829608e059", + "reference": "8b389aebe1b8b0578430bda0c7c95a829608e059", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2019-02-20T10:12:59+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/c99e3be9d3e85f60646f152f9002d46ed7770d18", + "reference": "c99e3be9d3e85f60646f152f9002d46ed7770d18", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2018-10-30T05:52:18+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "8.1.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "2a676677982b484ee36b54961f570c02eabbe7e1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2a676677982b484ee36b54961f570c02eabbe7e1", + "reference": "2a676677982b484ee36b54961f570c02eabbe7e1", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.1", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", + "php": "^7.2", + "phpspec/prophecy": "^1.7", + "phpunit/php-code-coverage": "^7.0", + "phpunit/php-file-iterator": "^2.0.1", + "phpunit/php-text-template": "^1.2.1", + "phpunit/php-timer": "^2.1", + "sebastian/comparator": "^3.0", + "sebastian/diff": "^3.0", + "sebastian/environment": "^4.1", + "sebastian/exporter": "^3.1", + "sebastian/global-state": "^3.0", + "sebastian/object-enumerator": "^3.0.3", + "sebastian/resource-operations": "^2.0", + "sebastian/version": "^2.0.1" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-soap": "*", + "ext-xdebug": "*", + "phpunit/php-invoker": "^2.0" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "8.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2019-04-19T15:52:00+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "time": "2017-03-04T06:30:41+00:00" + }, + { + "name": "sebastian/comparator", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "shasum": "" + }, + "require": { + "php": "^7.1", + "sebastian/diff": "^3.0", + "sebastian/exporter": "^3.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2018-07-12T15:12:46+00:00" + }, + { + "name": "sebastian/diff", + "version": "3.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "reference": "720fcc7e9b5cf384ea68d9d930d480907a0c1a29", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5 || ^8.0", + "symfony/process": "^2 || ^3.3 || ^4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "time": "2019-02-04T06:01:07+00:00" + }, + { + "name": "sebastian/environment", + "version": "4.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6fda8ce1974b62b14935adc02a9ed38252eca656", + "reference": "6fda8ce1974b62b14935adc02a9ed38252eca656", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.5" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2019-02-01T05:27:49+00:00" + }, + { + "name": "sebastian/exporter", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/234199f4528de6d12aaa58b612e98f7d36adb937", + "reference": "234199f4528de6d12aaa58b612e98f7d36adb937", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "http://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "time": "2017-04-03T13:19:02+00:00" + }, + { + "name": "sebastian/global-state", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "reference": "edf8a461cf1d4005f19fb0b6b8b95a9f7fa0adc4", + "shasum": "" + }, + "require": { + "php": "^7.2", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "time": "2019-02-01T05:30:01+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "shasum": "" + }, + "require": { + "php": "^7.0", + "sebastian/object-reflector": "^1.1.1", + "sebastian/recursion-context": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-08-03T12:35:26+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "773f97c67f28de00d397be301821b06708fca0be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", + "reference": "773f97c67f28de00d397be301821b06708fca0be", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "time": "2017-03-29T09:07:27+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "shasum": "" + }, + "require": { + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2017-03-03T06:23:57+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2018-10-04T04:07:39+00:00" + }, + { + "name": "sebastian/version", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/99732be0ddb3361e16ad77b68ba41efc8e979019", + "reference": "99732be0ddb3361e16ad77b68ba41efc8e979019", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2016-10-03T07:35:21+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.11.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "82ebae02209c21113908c229e9883c419720738a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", + "reference": "82ebae02209c21113908c229e9883c419720738a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.11-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2019-02-06T07:57:58+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/1c42705be2b6c1de5904f8afacef5895cab44bf8", + "reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "time": "2019-04-04T09:56:43+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.4.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", + "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0", + "symfony/polyfill-ctype": "^1.8" + }, + "require-dev": { + "phpunit/phpunit": "^4.6", + "sebastian/version": "^1.0.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "time": "2018-12-25T11:19:39+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/php7/fixtures/texttest_fixture.php b/php7/fixtures/texttest_fixture.php new file mode 100644 index 00000000..a5676658 --- /dev/null +++ b/php7/fixtures/texttest_fixture.php @@ -0,0 +1,38 @@ + 1) { + $days = (int) $argv[1]; +} + +for ($i = 0; $i < $days; $i++) { + echo("-------- day $i --------\n"); + echo("name, sellIn, quality\n"); + foreach ($items as $item) { + echo $item . PHP_EOL; + } + echo PHP_EOL; + $app->updateQuality(); +} diff --git a/php7/phpunit.xml b/php7/phpunit.xml new file mode 100644 index 00000000..f09680b8 --- /dev/null +++ b/php7/phpunit.xml @@ -0,0 +1,13 @@ + + + + + + test + + + diff --git a/php7/src/GildedRose.php b/php7/src/GildedRose.php new file mode 100644 index 00000000..d088e46c --- /dev/null +++ b/php7/src/GildedRose.php @@ -0,0 +1,63 @@ +items = $items; + } + + function updateQuality() { + foreach ($this->items as $item) { + if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { + if ($item->quality > 0) { + if ($item->name != 'Sulfuras, Hand of Ragnaros') { + $item->quality = $item->quality - 1; + } + } + } else { + if ($item->quality < 50) { + $item->quality = $item->quality + 1; + if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') { + if ($item->sell_in < 11) { + if ($item->quality < 50) { + $item->quality = $item->quality + 1; + } + } + if ($item->sell_in < 6) { + if ($item->quality < 50) { + $item->quality = $item->quality + 1; + } + } + } + } + } + + if ($item->name != 'Sulfuras, Hand of Ragnaros') { + $item->sell_in = $item->sell_in - 1; + } + + if ($item->sell_in < 0) { + if ($item->name != 'Aged Brie') { + if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') { + if ($item->quality > 0) { + if ($item->name != 'Sulfuras, Hand of Ragnaros') { + $item->quality = $item->quality - 1; + } + } + } else { + $item->quality = $item->quality - $item->quality; + } + } else { + if ($item->quality < 50) { + $item->quality = $item->quality + 1; + } + } + } + } + } +} + diff --git a/php7/src/Item.php b/php7/src/Item.php new file mode 100644 index 00000000..8a1dfd04 --- /dev/null +++ b/php7/src/Item.php @@ -0,0 +1,21 @@ +name = $name; + $this->sell_in = $sell_in; + $this->quality = $quality; + } + + public function __toString() { + return "{$this->name}, {$this->sell_in}, {$this->quality}"; + } +} + diff --git a/php7/test/GildedRoseTest.php b/php7/test/GildedRoseTest.php new file mode 100644 index 00000000..d8ccb190 --- /dev/null +++ b/php7/test/GildedRoseTest.php @@ -0,0 +1,14 @@ +updateQuality(); + $this->assertEquals("fixme", $items[0]->name); + } +} diff --git a/php7/test/bootstrap.php b/php7/test/bootstrap.php new file mode 100644 index 00000000..57eddb69 --- /dev/null +++ b/php7/test/bootstrap.php @@ -0,0 +1,2 @@ + Date: Tue, 23 Apr 2019 20:20:04 -0700 Subject: [PATCH 2/6] Full test suite with 100% coverage. --- php7/phpunit.xml | 6 ++++++ php7/src/GildedRose.php | 6 +++--- php7/src/Item.php | 2 +- php7/test/GildedRoseTest.php | 38 +++++++++++++++++++++++++++++++++--- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/php7/phpunit.xml b/php7/phpunit.xml index f09680b8..281edc63 100644 --- a/php7/phpunit.xml +++ b/php7/phpunit.xml @@ -10,4 +10,10 @@ test + + + + src + + diff --git a/php7/src/GildedRose.php b/php7/src/GildedRose.php index d088e46c..5a7cd7c9 100644 --- a/php7/src/GildedRose.php +++ b/php7/src/GildedRose.php @@ -2,15 +2,15 @@ namespace App; -class GildedRose { +final class GildedRose { private $items = []; - function __construct($items) { + public function __construct($items) { $this->items = $items; } - function updateQuality() { + public function updateQuality() { foreach ($this->items as $item) { if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { if ($item->quality > 0) { diff --git a/php7/src/Item.php b/php7/src/Item.php index 8a1dfd04..9ff2741b 100644 --- a/php7/src/Item.php +++ b/php7/src/Item.php @@ -2,7 +2,7 @@ namespace App; -class Item { +final class Item { public $name; public $sell_in; diff --git a/php7/test/GildedRoseTest.php b/php7/test/GildedRoseTest.php index d8ccb190..49cb3ad2 100644 --- a/php7/test/GildedRoseTest.php +++ b/php7/test/GildedRoseTest.php @@ -2,13 +2,45 @@ namespace App; -require_once __DIR__ . '/../vendor/autoload.php'; - class GildedRoseTest extends \PHPUnit\Framework\TestCase { public function testFoo() { $items = array(new Item("foo", 0, 0)); $gildedRose = new GildedRose($items); $gildedRose->updateQuality(); - $this->assertEquals("fixme", $items[0]->name); + $this->assertEquals("foo", $items[0]->name); + $this->assertEquals("foo, -1, 0", (string)$items[0]); + } + + /** + * @dataProvider itemProvider + */ + public function testItems(Item $item, $expected, $sellIn) { + $rose = new GildedRose([$item]); + + while ($sellIn > 1) { + $rose->updateQuality(); + $sellIn--; + } + + $actual = $item->quality; + $this->assertEquals($expected, $actual); + } + + public function itemProvider() { + // if you comment out any assignment/increment/decrement operation in updateQuality, + // at least one of these tests should fail. If there isn't a failure, then perhaps + // that line of code does not need to exist. + return [ + 'foo' => ['item' => new Item('foo', 9, 10), 'expected' => 2, 'sell_in' => 9], + 'Aged Brie' => ['item' => new Item('Aged Brie', 9, 10), 'expected' => 18, 'sell_in' => 9], + 'Backstage' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 30, 'sell_in' => 9], + 'Backstage2' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19], + 'Backstage3' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19], + 'Sulfuras1' => ['item' => new Item('Sulfuras, Hand of Ragnaros', 9, 10), 'expected' => 10, 'sell_in' => 9], + 'aged-foo' => ['item' => new Item('foo', 3, 14), 'expected' => 1, 'sell_in' => 9], + 'qualityFoo' => ['item' => new Item('foo', 3, 94), 'expected' => 39, 'sell_in' => 30], + 'qualityBrie' => ['item' => new Item('Aged Brie', 3, 94), 'expected' => 94, 'sell_in' => 30], + 'cheapBrie' => ['item' => new Item('Aged Brie', 3, 3), 'expected' => 50, 'sell_in' => 30], + ]; } } From 501cb7e0413e4174305d62d8236064255fcd96a3 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Tue, 23 Apr 2019 21:40:26 -0700 Subject: [PATCH 3/6] Add a special rule for Sulfuras quality --- php7/src/GildedRose.php | 6 ++++++ php7/test/GildedRoseTest.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/php7/src/GildedRose.php b/php7/src/GildedRose.php index 5a7cd7c9..5ed1df5c 100644 --- a/php7/src/GildedRose.php +++ b/php7/src/GildedRose.php @@ -12,6 +12,12 @@ final class GildedRose { public function updateQuality() { foreach ($this->items as $item) { + if ($item->name === 'Sulfuras, Hand of Ragnaros') { + $item->quality = 80; + + continue; + } + if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { if ($item->quality > 0) { if ($item->name != 'Sulfuras, Hand of Ragnaros') { diff --git a/php7/test/GildedRoseTest.php b/php7/test/GildedRoseTest.php index 49cb3ad2..13a09038 100644 --- a/php7/test/GildedRoseTest.php +++ b/php7/test/GildedRoseTest.php @@ -36,7 +36,7 @@ class GildedRoseTest extends \PHPUnit\Framework\TestCase { 'Backstage' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 30, 'sell_in' => 9], 'Backstage2' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19], 'Backstage3' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19], - 'Sulfuras1' => ['item' => new Item('Sulfuras, Hand of Ragnaros', 9, 10), 'expected' => 10, 'sell_in' => 9], + 'Sulfuras1' => ['item' => new Item('Sulfuras, Hand of Ragnaros', 9, 10), 'expected' => 80, 'sell_in' => 9], 'aged-foo' => ['item' => new Item('foo', 3, 14), 'expected' => 1, 'sell_in' => 9], 'qualityFoo' => ['item' => new Item('foo', 3, 94), 'expected' => 39, 'sell_in' => 30], 'qualityBrie' => ['item' => new Item('Aged Brie', 3, 94), 'expected' => 94, 'sell_in' => 30], From 216f754aeea42a8c917bd6938f3784f86ff0f6f1 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Wed, 22 May 2019 16:46:01 -0700 Subject: [PATCH 4/6] Relocate special Sulfuras exception to be more buried. --- php7/src/GildedRose.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/php7/src/GildedRose.php b/php7/src/GildedRose.php index 5ed1df5c..d11217cc 100644 --- a/php7/src/GildedRose.php +++ b/php7/src/GildedRose.php @@ -12,16 +12,12 @@ final class GildedRose { public function updateQuality() { foreach ($this->items as $item) { - if ($item->name === 'Sulfuras, Hand of Ragnaros') { - $item->quality = 80; - - continue; - } - if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') { if ($item->quality > 0) { if ($item->name != 'Sulfuras, Hand of Ragnaros') { $item->quality = $item->quality - 1; + } else { + $item->quality = 80; } } } else { From 0af329fa9b26cd5e37da07ae80a2e62a1af6e636 Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Wed, 22 May 2019 23:48:16 -0700 Subject: [PATCH 5/6] Add a readme for php7 --- php7/README.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 php7/README.md diff --git a/php7/README.md b/php7/README.md new file mode 100644 index 00000000..71cdf976 --- /dev/null +++ b/php7/README.md @@ -0,0 +1,51 @@ +Requirements +------------ + +**PHP 7:** + +This is usually bundled with your operating system, or fetchable using a package manager like `apt` or `homebrew`. + +Windows users can find the latest version here: https://windows.php.net/download#php-7.3 + +If you want to compile from source code, that can be found here: https://www.php.net/downloads.php + +**Composer:** + +Composer is PHP's main package and dependency management tool. + +It can be downloaded here: https://getcomposer.org/download/ + +Getting Started +--------------- + +To begin the kata, install the dependencies and run `phpunit`: + +``` +cd php7 +composer install +vendor/bin/phpunit +``` + +If the "install" command does not work, try running `composer update` instead. +This will tell composer that it has permission to look for a newer version of +its dependencies. + +If things are still not cooperating, you can try this extreme approach: + +``` +composer remove phpunit/phpunit +composer require phpunit/phpunit +``` + +To exercise the code outside of phpunit, for example to visually confirm that it is working, +use the `texttest_fixture` script: + +``` +php fixtures/texttest_fixture.php +``` + +Tips +---- + +PHPUnit has a very thorough reference manual. It would be particularly useful to explore the +[Data Providers](https://phpunit.readthedocs.io/en/8.1/writing-tests-for-phpunit.html#data-providers) section. From e9e40ef19a83e44faf95936d543d5f8e0307a45c Mon Sep 17 00:00:00 2001 From: Kevin Boyd Date: Wed, 22 May 2019 23:49:12 -0700 Subject: [PATCH 6/6] Restore the test class to the original "fixme" state --- php7/test/GildedRoseTest.php | 38 ++---------------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/php7/test/GildedRoseTest.php b/php7/test/GildedRoseTest.php index 13a09038..6f2ecf70 100644 --- a/php7/test/GildedRoseTest.php +++ b/php7/test/GildedRoseTest.php @@ -4,43 +4,9 @@ namespace App; class GildedRoseTest extends \PHPUnit\Framework\TestCase { public function testFoo() { - $items = array(new Item("foo", 0, 0)); + $items = [new Item("foo", 0, 0)]; $gildedRose = new GildedRose($items); $gildedRose->updateQuality(); - $this->assertEquals("foo", $items[0]->name); - $this->assertEquals("foo, -1, 0", (string)$items[0]); - } - - /** - * @dataProvider itemProvider - */ - public function testItems(Item $item, $expected, $sellIn) { - $rose = new GildedRose([$item]); - - while ($sellIn > 1) { - $rose->updateQuality(); - $sellIn--; - } - - $actual = $item->quality; - $this->assertEquals($expected, $actual); - } - - public function itemProvider() { - // if you comment out any assignment/increment/decrement operation in updateQuality, - // at least one of these tests should fail. If there isn't a failure, then perhaps - // that line of code does not need to exist. - return [ - 'foo' => ['item' => new Item('foo', 9, 10), 'expected' => 2, 'sell_in' => 9], - 'Aged Brie' => ['item' => new Item('Aged Brie', 9, 10), 'expected' => 18, 'sell_in' => 9], - 'Backstage' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 30, 'sell_in' => 9], - 'Backstage2' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19], - 'Backstage3' => ['item' => new Item('Backstage passes to a TAFKAL80ETC concert', 9, 10), 'expected' => 0, 'sell_in' => 19], - 'Sulfuras1' => ['item' => new Item('Sulfuras, Hand of Ragnaros', 9, 10), 'expected' => 80, 'sell_in' => 9], - 'aged-foo' => ['item' => new Item('foo', 3, 14), 'expected' => 1, 'sell_in' => 9], - 'qualityFoo' => ['item' => new Item('foo', 3, 94), 'expected' => 39, 'sell_in' => 30], - 'qualityBrie' => ['item' => new Item('Aged Brie', 3, 94), 'expected' => 94, 'sell_in' => 30], - 'cheapBrie' => ['item' => new Item('Aged Brie', 3, 3), 'expected' => 50, 'sell_in' => 30], - ]; + $this->assertEquals("fixme", $items[0]->name); } }