From b93d5570d0e84ca7a8945addc313cbcea54e0b3f Mon Sep 17 00:00:00 2001 From: kirkbushell Date: Mon, 28 Sep 2015 15:09:13 +0100 Subject: [PATCH] Removed phpsec as the testing library, added phpunit and converted the first spec test to phpunit format. Also added mockery. --- framework/core/.gitignore | 1 + framework/core/composer.json | 10 +- framework/core/composer.lock | 634 +++++++++++++++++- .../MemoryCacheSettingsRepositorySpec.php | 63 -- .../MemoryCacheSettingsRepositoryTest.php | 44 ++ framework/core/tests/Test/TestCase.php | 20 + framework/core/tests/phpunit.xml | 24 + 7 files changed, 719 insertions(+), 77 deletions(-) delete mode 100644 framework/core/spec/Flarum/Core/Settings/MemoryCacheSettingsRepositorySpec.php create mode 100644 framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php create mode 100644 framework/core/tests/Test/TestCase.php create mode 100644 framework/core/tests/phpunit.xml diff --git a/framework/core/.gitignore b/framework/core/.gitignore index 716cfec7e..1a43f2275 100644 --- a/framework/core/.gitignore +++ b/framework/core/.gitignore @@ -4,3 +4,4 @@ composer.phar Thumbs.db tests/_output/* .vagrant +.idea/ diff --git a/framework/core/composer.json b/framework/core/composer.json index 7f149af7a..deeddd58c 100644 --- a/framework/core/composer.json +++ b/framework/core/composer.json @@ -33,22 +33,24 @@ "dflydev/fig-cookies": "^1.0", "symfony/console": "^2.7", "symfony/yaml": "^2.7", - "doctrine/dbal": "^2.5" + "doctrine/dbal": "^2.5", + "mockery/mockery": "^0.9.4" }, "require-dev": { "squizlabs/php_codesniffer": "2.*", - "phpspec/phpspec": "^2.2" + "phpunit/phpunit": "^4.8" }, "autoload": { "psr-4": { - "Flarum\\": "src/" + "Flarum\\": "src/", + "tests\\": "tests/" }, "files": [ "src/helpers.php" ] }, "scripts": { - "test": "phpspec run", + "test": "vendor/bin/phpunit -c tests/phpunit.xml", "style": "phpcs --standard=PSR2 -np src" } } diff --git a/framework/core/composer.lock b/framework/core/composer.lock index c5ae38dec..453e23cd3 100644 --- a/framework/core/composer.lock +++ b/framework/core/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "eb1e411ff1d02b0d1384c482f34625c5", - "content-hash": "51442663d4096ed0941800baefafda1a", + "hash": "49ba424961939b5b7b6eea7bdcadcbda", + "content-hash": "f2e78efbbe37a6d94428a8e6985fda1f", "packages": [ { "name": "danielstjules/stringy", @@ -642,6 +642,51 @@ ], "time": "2015-08-15 19:32:36" }, + { + "name": "hamcrest/hamcrest-php", + "version": "v1.2.2", + "source": { + "type": "git", + "url": "https://github.com/hamcrest/hamcrest-php.git", + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/b37020aa976fa52d3de9aa904aa2522dc518f79c", + "reference": "b37020aa976fa52d3de9aa904aa2522dc518f79c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "replace": { + "cordoval/hamcrest-php": "*", + "davedevelopment/hamcrest-php": "*", + "kodova/hamcrest-php": "*" + }, + "require-dev": { + "phpunit/php-file-iterator": "1.3.3", + "satooshi/php-coveralls": "dev-master" + }, + "type": "library", + "autoload": { + "classmap": [ + "hamcrest" + ], + "files": [ + "hamcrest/Hamcrest.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "description": "This is the PHP port of Hamcrest Matchers", + "keywords": [ + "test" + ], + "time": "2015-05-11 14:41:42" + }, { "name": "illuminate/bus", "version": "v5.1.16", @@ -1453,6 +1498,71 @@ ], "time": "2015-09-05 12:06:41" }, + { + "name": "mockery/mockery", + "version": "0.9.4", + "source": { + "type": "git", + "url": "https://github.com/padraic/mockery.git", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/padraic/mockery/zipball/70bba85e4aabc9449626651f48b9018ede04f86b", + "reference": "70bba85e4aabc9449626651f48b9018ede04f86b", + "shasum": "" + }, + "require": { + "hamcrest/hamcrest-php": "~1.1", + "lib-pcre": ">=7.0", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9.x-dev" + } + }, + "autoload": { + "psr-0": { + "Mockery": "library/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Pádraic Brady", + "email": "padraic.brady@gmail.com", + "homepage": "http://blog.astrumfutura.com" + }, + { + "name": "Dave Marshall", + "email": "dave.marshall@atstsolutions.co.uk", + "homepage": "http://davedevelopment.co.uk" + } + ], + "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", + "homepage": "http://github.com/padraic/mockery", + "keywords": [ + "BDD", + "TDD", + "library", + "mock", + "mock objects", + "mockery", + "stub", + "test", + "test double", + "testing" + ], + "time": "2015-04-02 19:54:00" + }, { "name": "nesbot/carbon", "version": "1.20.0", @@ -1806,13 +1916,13 @@ "version": "v2.7.4", "source": { "type": "git", - "url": "https://github.com/symfony/Console.git", - "reference": "f1f7376766394f409b9b33a57a5675a52f8aad93" + "url": "https://github.com/symfony/console.git", + "reference": "9ff9032151186bd66ecee727d728f1319f52d1d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/9ff9032151186bd66ecee727d728f1319f52d1d8", - "reference": "f1f7376766394f409b9b33a57a5675a52f8aad93", + "url": "https://api.github.com/repos/symfony/console/zipball/9ff9032151186bd66ecee727d728f1319f52d1d8", + "reference": "9ff9032151186bd66ecee727d728f1319f52d1d8", "shasum": "" }, "require": { @@ -1912,12 +2022,12 @@ "version": "v2.7.4", "source": { "type": "git", - "url": "https://github.com/symfony/HttpFoundation.git", + "url": "https://github.com/symfony/http-foundation.git", "reference": "7253c2041652353e71560bbd300d6256d170ddaf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/7253c2041652353e71560bbd300d6256d170ddaf", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/7253c2041652353e71560bbd300d6256d170ddaf", "reference": "7253c2041652353e71560bbd300d6256d170ddaf", "shasum": "" }, @@ -2446,6 +2556,374 @@ ], "time": "2015-08-13 10:07:40" }, + { + "name": "phpunit/php-code-coverage", + "version": "2.2.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef1ca6835468857944d5c3b48fa503d5554cff2f", + "reference": "ef1ca6835468857944d5c3b48fa503d5554cff2f", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "phpunit/php-file-iterator": "~1.3", + "phpunit/php-text-template": "~1.2", + "phpunit/php-token-stream": "~1.3", + "sebastian/environment": "^1.3.2", + "sebastian/version": "~1.0" + }, + "require-dev": { + "ext-xdebug": ">=2.1.4", + "phpunit/phpunit": "~4" + }, + "suggest": { + "ext-dom": "*", + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.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": "2015-09-14 06:51:16" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.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": "2015-06-21 13:08:43" + }, + { + "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-21 13:50:34" + }, + { + "name": "phpunit/php-timer", + "version": "1.0.7", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", + "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": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2015-06-21 08:01:12" + }, + { + "name": "phpunit/php-token-stream", + "version": "1.4.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", + "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-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": "2015-09-15 10:49:45" + }, + { + "name": "phpunit/phpunit", + "version": "4.8.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "73fad41adb5b7bc3a494bb930d90648df1d5e74b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/73fad41adb5b7bc3a494bb930d90648df1d5e74b", + "reference": "73fad41adb5b7bc3a494bb930d90648df1d5e74b", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=5.3.3", + "phpspec/prophecy": "^1.3.1", + "phpunit/php-code-coverage": "~2.1", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": ">=1.0.6", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.1", + "sebastian/diff": "~1.2", + "sebastian/environment": "~1.3", + "sebastian/exporter": "~1.2", + "sebastian/global-state": "~1.0", + "sebastian/version": "~1.0", + "symfony/yaml": "~2.1|~3.0" + }, + "suggest": { + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.8.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": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "time": "2015-09-20 12:56:44" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "2.3.7", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "5e2645ad49d196e020b85598d7c97e482725786a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5e2645ad49d196e020b85598d7c97e482725786a", + "reference": "5e2645ad49d196e020b85598d7c97e482725786a", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": ">=5.3.3", + "phpunit/php-text-template": "~1.2", + "sebastian/exporter": "~1.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2015-08-19 09:14:08" + }, { "name": "sebastian/comparator", "version": "1.2.0", @@ -2562,6 +3040,56 @@ ], "time": "2015-02-22 15:13:53" }, + { + "name": "sebastian/environment", + "version": "1.3.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6324c907ce7a52478eeeaede764f48733ef5ae44", + "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-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": "2015-08-03 06:14:51" + }, { "name": "sebastian/exporter", "version": "1.2.1", @@ -2628,6 +3156,57 @@ ], "time": "2015-06-21 07:55:53" }, + { + "name": "sebastian/global-state", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, + "suggest": { + "ext-uopz": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.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": "2014-10-06 09:23:50" + }, { "name": "sebastian/recursion-context", "version": "1.0.1", @@ -2681,6 +3260,41 @@ "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "time": "2015-06-21 08:04:50" }, + { + "name": "sebastian/version", + "version": "1.0.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", + "shasum": "" + }, + "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": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "time": "2015-06-21 13:59:46" + }, { "name": "squizlabs/php_codesniffer", "version": "2.3.4", @@ -2760,12 +3374,12 @@ "version": "v2.7.4", "source": { "type": "git", - "url": "https://github.com/symfony/EventDispatcher.git", + "url": "https://github.com/symfony/event-dispatcher.git", "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/b58c916f1db03a611b72dd702564f30ad8fe83fa", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b58c916f1db03a611b72dd702564f30ad8fe83fa", "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa", "shasum": "" }, diff --git a/framework/core/spec/Flarum/Core/Settings/MemoryCacheSettingsRepositorySpec.php b/framework/core/spec/Flarum/Core/Settings/MemoryCacheSettingsRepositorySpec.php deleted file mode 100644 index 0662d3bc5..000000000 --- a/framework/core/spec/Flarum/Core/Settings/MemoryCacheSettingsRepositorySpec.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace spec\Flarum\Core\Settings; - -use Flarum\Core\Settings\SettingsRepository; -use PhpSpec\ObjectBehavior; -use Prophecy\Argument; - -class MemoryCacheSettingsRepositorySpec extends ObjectBehavior -{ - public function let(SettingsRepository $inner) - { - $this->beConstructedWith($inner); - } - - public function it_is_initializable() - { - $this->shouldHaveType('Flarum\Core\Settings\MemoryCacheSettingsRepository'); - } - - public function it_retrieves_data_from_inner(SettingsRepository $inner) - { - $settings = ['a' => 1, 'b' => 2]; - $inner->all()->willReturn($settings); - $inner->all()->shouldBeCalled(); - - // Test fetching all settings - $this->all()->shouldReturn($settings); - - // Test fetching single settings - $this->get('a')->shouldReturn(1); - $this->get('b')->shouldReturn(2); - - // Test invalid key - $this->get('c')->shouldReturn(null); - - // Test invalid key with custom default - $this->get('d', 'foobar')->shouldReturn('foobar'); - } - - public function it_passes_new_data_to_inner(SettingsRepository $inner) - { - $this->set('a', 1); - $inner->set('a', 1)->shouldHaveBeenCalled(); - } - - public function it_caches_new_data(SettingsRepository $inner) - { - $this->set('b', 2); - $this->get('b')->shouldReturn(2); - $inner->all()->shouldNotHaveBeenCalled(); - $inner->get('b')->shouldNotHaveBeenCalled(); - } -} diff --git a/framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php b/framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php new file mode 100644 index 000000000..014e98c38 --- /dev/null +++ b/framework/core/tests/Flarum/Core/Settings/MemoryCacheSettingsRepositoryTest.php @@ -0,0 +1,44 @@ +baseRepository = m::mock(SettingsRepository::class); + $this->repository = new MemoryCacheSettingsRepository($this->baseRepository); + } + + public function test_it_should_return_all_settings_when_not_cached() + { + $this->baseRepository->shouldReceive('all')->once()->andReturn(['key' => 'value']); + + $this->assertEquals(['key' => 'value'], $this->repository->all()); + $this->assertEquals(['key' => 'value'], $this->repository->all()); // Assert twice to ensure we hit the cache + } + + public function test_it_should_retrieve_a_specific_value() + { + $this->baseRepository->shouldReceive('all')->once()->andReturn(['key1' => 'value1', 'key2' => 'value2']); + + $this->assertEquals('value2', $this->repository->get('key2')); + $this->assertEquals('value2', $this->repository->get('key2')); // Assert twice to ensure we hit the cache + } + + public function test_it_should_set_a_key_value_pair() + { + $this->baseRepository->shouldReceive('set')->once(); + + $this->repository->set('key', 'value'); + + $this->assertEquals('value', $this->repository->get('key')); + } +} diff --git a/framework/core/tests/Test/TestCase.php b/framework/core/tests/Test/TestCase.php new file mode 100644 index 000000000..d91ad6f63 --- /dev/null +++ b/framework/core/tests/Test/TestCase.php @@ -0,0 +1,20 @@ +init(); + } + + protected function init() + { + // To be overloaded by children - saves having to do setUp/mockery::close every time + } +} diff --git a/framework/core/tests/phpunit.xml b/framework/core/tests/phpunit.xml new file mode 100644 index 000000000..75d384807 --- /dev/null +++ b/framework/core/tests/phpunit.xml @@ -0,0 +1,24 @@ + + + + + + + ./ + + + + + + + + +