diff --git a/.travis.yml b/.travis.yml index 037ad21f..52f60934 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,15 @@ matrix: include: - # FIXME: skipped for now since we use a different php version on the live server - # - language: php - # php: 7.0 - # cache: - # directories: src/vendor - # before_script: - # - composer install --dev --prefer-dist - # script: - # - sh bin/build.sh + - language: php + php: + - 7.1 + cache: + directories: src/vendor + before_script: + - composer install --dev --prefer-dist + script: + - sh bin/build.sh + - ./src/vendor/bin/phpunit - language: node_js node_js: 10 cache: yarn diff --git a/CHANGELOG.md b/CHANGELOG.md index aebc0e4d..e0024626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] + +### Added + +- Add unit tests based on PHPUnit ([#824](https://github.com/serlo-org/athene2/pull/824)) + - Add yarn script `unit` that executes `./src/vendor/bin/phpunit` + ## [Build 5] - 2018-12-01 ### Added diff --git a/README.md b/README.md index 13873066..45534b66 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ Open _package.json_ and make sure the values you got from running the two comman Most of these are outdated: - [Knowledge base](https://github.com/serlo-org/athene2/wiki/Knowledge-base) +- [Testing](https://github.com/serlo-org/athene2/wiki/Testing) - [Development workflow (outdated)](https://github.com/serlo-org/athene2/wiki/Development-workflow) - [Installation (totally outdated, do not look at this)](https://github.com/serlo-org/athene2/wiki/Installation) - [Athene2 Guide (somewhat outdated)](https://serlo-org.github.io/athene2-guide/) diff --git a/composer.json b/composer.json index 9d2032a9..c472d65d 100644 --- a/composer.json +++ b/composer.json @@ -33,5 +33,8 @@ }, "config": { "vendor-dir": "src/vendor" + }, + "require-dev": { + "phpunit/phpunit": "^5" } } diff --git a/composer.lock b/composer.lock index 033770e8..44d6d406 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_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#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d300de3eec940d7c452b8df97a4eaa87", + "content-hash": "4022385d666574c0cb7a6b63adaa0731", "packages": [ { "name": "dnode/dnode", @@ -3824,14 +3824,1290 @@ "time": "2014-02-06T14:18:34+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "myclabs/deep-copy", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "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": "2018-06-11T23:09:50+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": "4.0.8", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "reference": "ef7b2f56815df854e66ceaee8ebe9393ae36a40d", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-xmlwriter": "*", + "php": "^5.6 || ^7.0", + "phpunit/php-file-iterator": "^1.3", + "phpunit/php-text-template": "^1.2", + "phpunit/php-token-stream": "^1.4.2 || ^2.0", + "sebastian/code-unit-reverse-lookup": "^1.0", + "sebastian/environment": "^1.3.2 || ^2.0", + "sebastian/version": "^1.0 || ^2.0" + }, + "require-dev": { + "ext-xdebug": "^2.1.4", + "phpunit/phpunit": "^5.7" + }, + "suggest": { + "ext-xdebug": "^2.5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.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": "2017-04-02T07:44:40+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "1.4.5", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", + "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "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": "2017-11-27T13:52:08+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": "1.0.9", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "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": "sb@sebastian-bergmann.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "time": "2017-02-26T11:10:40+00:00" + }, + { + "name": "phpunit/php-token-stream", + "version": "2.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-token-stream.git", + "reference": "791198a2c6254db10131eecfe8c06670700904db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/791198a2c6254db10131eecfe8c06670700904db", + "reference": "791198a2c6254db10131eecfe8c06670700904db", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": "^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^6.2.4" + }, + "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": "Wrapper around PHP's tokenizer extension.", + "homepage": "https://github.com/sebastianbergmann/php-token-stream/", + "keywords": [ + "tokenizer" + ], + "time": "2017-11-27T05:48:46+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "5.7.27", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "reference": "b7803aeca3ccb99ad0a506fa80b64cd6a56bbc0c", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "myclabs/deep-copy": "~1.3", + "php": "^5.6 || ^7.0", + "phpspec/prophecy": "^1.6.2", + "phpunit/php-code-coverage": "^4.0.4", + "phpunit/php-file-iterator": "~1.4", + "phpunit/php-text-template": "~1.2", + "phpunit/php-timer": "^1.0.6", + "phpunit/phpunit-mock-objects": "^3.2", + "sebastian/comparator": "^1.2.4", + "sebastian/diff": "^1.4.3", + "sebastian/environment": "^1.3.4 || ^2.0", + "sebastian/exporter": "~2.0", + "sebastian/global-state": "^1.1", + "sebastian/object-enumerator": "~2.0", + "sebastian/resource-operations": "~1.0", + "sebastian/version": "^1.0.6|^2.0.1", + "symfony/yaml": "~2.1|~3.0|~4.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "3.0.2" + }, + "require-dev": { + "ext-pdo": "*" + }, + "suggest": { + "ext-xdebug": "*", + "phpunit/php-invoker": "~1.1" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.7.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": "2018-02-01T05:50:59+00:00" + }, + { + "name": "phpunit/phpunit-mock-objects", + "version": "3.4.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/a23b761686d50a560cc56233b9ecf49597cc9118", + "reference": "a23b761686d50a560cc56233b9ecf49597cc9118", + "shasum": "" + }, + "require": { + "doctrine/instantiator": "^1.0.2", + "php": "^5.6 || ^7.0", + "phpunit/php-text-template": "^1.2", + "sebastian/exporter": "^1.2 || ^2.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.4" + }, + "suggest": { + "ext-soap": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.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": "Mock Object library for PHPUnit", + "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", + "keywords": [ + "mock", + "xunit" + ], + "time": "2017-06-30T09:13: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": "1.2.4", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.2", + "sebastian/exporter": "~1.2 || ~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.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" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2017-01-29T09:50:25+00:00" + }, + { + "name": "sebastian/diff", + "version": "1.4.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + }, + "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": "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" + ], + "time": "2017-05-22T07:24:03+00:00" + }, + { + "name": "sebastian/environment", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "reference": "5795ffe5dc5b02460c3e34222fee8cbe245d8fac", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.0" + }, + "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" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "http://www.github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "time": "2016-11-26T07:53:53+00:00" + }, + { + "name": "sebastian/exporter", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "reference": "ce474bdd1a34744d7ac5d6aad3a46d48d9bac4c4", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "ext-mbstring": "*", + "phpunit/phpunit": "~4.4" + }, + "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": "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": "2016-11-19T08:54:04+00:00" + }, + { + "name": "sebastian/global-state", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", + "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", + "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": "2015-10-12T03:26:01+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/1311872ac850040a79c3c058bea3e22d0f09cbb7", + "reference": "1311872ac850040a79c3c058bea3e22d0f09cbb7", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "sebastian/recursion-context": "~2.0" + }, + "require-dev": { + "phpunit/phpunit": "~5" + }, + "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" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "time": "2017-02-18T15:18:39+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "reference": "2c3ba150cbec723aa057506e73a8d33bdb286c9a", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "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": "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": "2016-11-19T07:33:16+00:00" + }, + { + "name": "sebastian/resource-operations", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/resource-operations.git", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "shasum": "" + }, + "require": { + "php": ">=5.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": "Provides a list of PHP built-in functions that operate on resources", + "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "time": "2015-07-28T20:34:47+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/yaml", + "version": "v4.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "c41175c801e3edfda90f32e292619d10c27103d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/c41175c801e3edfda90f32e292619d10c27103d7", + "reference": "c41175c801e3edfda90f32e292619d10c27103d7", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "symfony/console": "<3.4" + }, + "require-dev": { + "symfony/console": "~3.4|~4.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.2-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2018-11-11T19:52:12+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/webmozart/assert.git", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozart/assert/zipball/0df1908962e7a3071564e857d86874dad1ef204a", + "reference": "0df1908962e7a3071564e857d86874dad1ef204a", + "shasum": "" + }, + "require": { + "php": "^5.3.3 || ^7.0" + }, + "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-01-29T19:49:41+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.5" + "php": ">=7.0" }, "platform-dev": [] } diff --git a/docker-compose.dist.yml b/docker-compose.dist.yml index b749700e..f529fc45 100644 --- a/docker-compose.dist.yml +++ b/docker-compose.dist.yml @@ -23,6 +23,7 @@ services: - '4567:80' volumes: # For macOS, add `:delegated` to every volume for improved performance, see also https://docs.docker.com/docker-for-mac/osxfs-caching/#semantics + - ./phpunit.xml:/var/www/html/phpunit.xml - ./src/config:/var/www/html/src/config - ./src/lang:/var/www/html/src/lang - ./src/module:/var/www/html/src/module diff --git a/package.json b/package.json index f2ce6ed3..dcc39419 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "lint": "npm-run-all lint:*", "license": "ts-node scripts/license-headers", "e2e": "cypress open", + "unit": "./src/vendor/bin/phpunit", "format:php-cs-fixer": "yarn _php-cs-fixer", "format:prettier": "yarn _prettier --write", "lint:php-cs-fixer": "yarn _php-cs-fixer --dry-run", diff --git a/phpunit.xml b/phpunit.xml index 1665f848..eda360a7 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,19 +1,16 @@ - - - - ./src/module/ClassResolver/test - - - - - ./src/module - - ./src/module - ./src/module - ./src/module - - - + + + + ./src/module/Blog/test + + + ./src/module/Type/test + + + ./src/module/ClassResolver/test + + \ No newline at end of file diff --git a/src/module/Blog/src/Blog/Manager/BlogManager.php b/src/module/Blog/src/Blog/Manager/BlogManager.php index bec736ff..87a55939 100644 --- a/src/module/Blog/src/Blog/Manager/BlogManager.php +++ b/src/module/Blog/src/Blog/Manager/BlogManager.php @@ -34,7 +34,6 @@ use Instance\Manager\InstanceManagerInterface; use Taxonomy\Manager\TaxonomyManagerAwareTrait; use Taxonomy\Manager\TaxonomyManagerInterface; -use Uuid\Manager\UuidManagerAwareTrait; use Zend\EventManager\EventManagerAwareTrait; use Zend\Form\FormInterface; use ZfcRbac\Service\AuthorizationService; @@ -46,6 +45,15 @@ class BlogManager implements BlogManagerInterface use InstanceManagerAwareTrait, AuthorizationAssertionTrait; use EventManagerAwareTrait; + /** + * @TODO AuthorizationService should be AuthorizationServiceInterface (depends on zf-commons) + * + * @param ClassResolverInterface $classResolver + * @param TaxonomyManagerInterface $taxonomyManager + * @param ObjectManager $objectManager + * @param InstanceManagerInterface $instanceManager + * @param AuthorizationService $authorizationService + */ public function __construct( ClassResolverInterface $classResolver, TaxonomyManagerInterface $taxonomyManager, diff --git a/src/module/Blog/test/BlogTest/Entity/PostTest.php b/src/module/Blog/test/BlogTest/Entity/PostTest.php new file mode 100644 index 00000000..a25c08a2 --- /dev/null +++ b/src/module/Blog/test/BlogTest/Entity/PostTest.php @@ -0,0 +1,57 @@ +post = new Post(); + parent::setObject($this->post); + } + + protected function getData() + { + return array( + "author" => $this->createMock("User\Entity\UserInterface"), + "blog" => $this->createMock("Taxonomy\Entity\TaxonomyTermInterface"), + "title" => "title", + "content" => "content", + "timestamp" => new DateTime(), + "publish" => new DateTime(), + + ); + } + + public function testIsPublished() + { + $post = new Post(); + //set DateTime in past + $post->setPublish(new Datetime("2000-03-14")); + $this->assertTrue($post->isPublished()); + } + + public function testAddTaxonomyTerm() + { + $post = new Post(); + $taxTerm = $this->createMock("Taxonomy\Entity\TaxonomyTermInterface"); + $post->addTaxonomyTerm($taxTerm); + $this->assertSame($taxTerm, $post->getBlog()); + } + + public function testRemoveTaxonomyTerm() + { + $post = new Post(); + + //test for unimplemented method -> exception + $this->expectException(Exception::class); + $post->removeTaxonomyTerm($this->createMock("Taxonomy\Entity\TaxonomyTermInterface")); + } +} diff --git a/src/module/Blog/test/BlogTest/Manager/BlogManagerTest.php b/src/module/Blog/test/BlogTest/Manager/BlogManagerTest.php new file mode 100644 index 00000000..23943c43 --- /dev/null +++ b/src/module/Blog/test/BlogTest/Manager/BlogManagerTest.php @@ -0,0 +1,228 @@ +classResolver = $this->mockClassResolver(); + $this->objectManager = $this->mockObjectManager(); + $this->authorizationService = $this->mockAuthorizationService(); + $this->eventManager = $this->mockEventManager(); + + $this->taxonomyManager = $this->createMock(TaxonomyManagerInterface::class); + $this->instanceManager = $this->createMock(InstanceManagerInterface::class); + + $this->blogManager = new BlogManager($this->classResolver, $this->taxonomyManager, $this->objectManager, $this->instanceManager, $this->authorizationService); + $this->blogManager->setEventManager($this->eventManager); + } + + + public function testGetBlog_Granted() + { + $blog = new TaxonomyTerm(); + + $this->taxonomyManager->expects($this->once()) + ->method('getTerm') + ->with($this->equalTo(1)) + ->will($this->returnValue($blog)); + $this->prepareIsGranted($this->authorizationService, 'blog.get', $blog, true); + $this->assertEquals($blog, $this->blogManager->getBlog(1)); + } + + /** + *@expectedException \ZfcRbac\Exception\UnauthorizedException + */ + public function testGetBlog_NotGranted() + { + $blog = new TaxonomyTerm(); + + $this->taxonomyManager->expects($this->once()) + ->method('getTerm') + ->with($this->equalTo(1)) + ->will($this->returnValue($blog)); + + $this->prepareIsGranted($this->authorizationService, 'blog.get', $blog, false); + $this->blogManager->getBlog(1); + } + + public function testFindAllBlogs_Granted() + { + //dummy objects + $childDummy = new TaxonomyTerm(); + $taxonomyDummy = new Taxonomy(); + $taxonomyDummy->addTerm($childDummy); + $instanceDummy = new Instance(); + + $this->taxonomyManager->expects($this->once()) + ->method('findTaxonomyByName') + ->with($this->equalTo('blog'), $instanceDummy) + ->will($this->returnValue($taxonomyDummy)); + $this->prepareIsGranted($this->authorizationService, 'blog.get', $childDummy, true); + + $this->assertEquals($taxonomyDummy->getChildren(), $this->blogManager->findAllBlogs($instanceDummy)); + } + + /** + *@expectedException \ZfcRbac\Exception\UnauthorizedException + */ + public function testFindAllBlogs_NotGranted() + { + $childDummy = new TaxonomyTerm(); + $taxonomyDummy = new Taxonomy(); + $taxonomyDummy->addTerm($childDummy); + $instanceDummy = new Instance(); + + $this->taxonomyManager->expects($this->once()) + ->method('findTaxonomyByName') + ->with($this->equalTo('blog'), $instanceDummy) + ->will($this->returnValue($taxonomyDummy)); + $this->prepareIsGranted($this->authorizationService, 'blog.get', $childDummy, false); + $this->blogManager->findAllBlogs($instanceDummy); + } + + public function testGetPost_FoundGranted() + { + $repoName = "Blog\Entity\Post"; + $post = new Post(); + $post->setTitle("Post1"); + + $this->prepareResolveClass( + $this->classResolver, + "Blog\Entity\PostInterface", + $repoName + ); + $this->prepareFind($this->objectManager, $repoName, 1, $post); + $this->prepareIsGranted($this->authorizationService, 'blog.post.get', $post, true); + + $this->assertEquals($post, $this->blogManager->getPost(1)); + } + + /** + *@expectedException \Blog\Exception\PostNotFoundException + */ + public function testGetPost_NotFound() + { + $repoName = "Blog\Entity\Post"; + + $this->prepareResolveClass( + $this->classResolver, + PostInterface::class, + $repoName + ); + $this->prepareIsGranted($this->authorizationService, 'blog.post.get', null, true); + $this->prepareFind($this->objectManager, $repoName, 1, null); + $this->blogManager->getPost(1); + } + + public function testUpdatePost_Granted_Valid() + { + $post = new Post(); + $post->setTitle("Title"); + + $form = $this->createMock(FormInterface::class); + $form->expects($this->once())->method('getObject')->will($this->returnValue($post)); + $form->expects($this->any())->method('isValid')->will($this->returnValue(true)); + + $this->prepareIsGranted($this->authorizationService, 'blog.post.update', $post, true); + + //check persist + $this->objectManager->expects($this->once())->method("persist")->with($this->equalTo($post)); + //check event trigger + $this->eventManager->expects($this->once())->method("trigger")->with( + $this->equalTo("update"), + $this->equalTo($this->blogManager), + $this->equalTo(['post' => $post]) + ); + + $this->blogManager->updatePost($form); + } + + /** + *@expectedException \RuntimeException + */ + public function testUpdatePost_Granted_NotValid() + { + $post = new Post(); + $post->setTitle("Title"); + + $form = $this->createMock(FormInterface::class); + $form->expects($this->once())->method('getObject')->will($this->returnValue($post)); + $form->expects($this->any())->method('isValid')->will($this->returnValue(false)); + $this->prepareIsGranted($this->authorizationService, 'blog.post.update', $post, true); + $this->blogManager->updatePost($form); + } + + public function testCreatePost_Granted_Valid() + { + $post = new Post(); + $post->setTitle("Title"); + + $this->prepareResolve( + $this->classResolver, + PostInterface::class, + $post + ); + + $form = $this->createMock(FormInterface::class); + $form->expects($this->any())->method('isValid')->will($this->returnValue(true)); + $this->prepareIsGranted($this->authorizationService, 'blog.post.create', $post, true); + //check persist + $this->objectManager->expects($this->once())->method("persist")->with($this->equalTo($post)); + //check event trigger + $this->eventManager->expects($this->once())->method("trigger")->with( + $this->equalTo("create"), + $this->equalTo($this->blogManager), + $this->equalTo(['post' => $post]) + ); + + $this->blogManager->createPost($form); + } + + /** + *@expectedException \RuntimeException + */ + public function testCreatePost_NotValid() + { + $post = new Post(); + $post->setTitle("Title"); + + $this->prepareResolve( + $this->classResolver, + PostInterface::class, + $post + ); + + $form = $this->createMock(FormInterface::class); + $form->expects($this->any())->method('isValid')->will($this->returnValue(false)); + $this->blogManager->createPost($form); + } +} diff --git a/src/module/ClassResolver/test/ClassResolverTest/ClassResolverAwareTraitTest.php b/src/module/ClassResolver/test/ClassResolverTest/ClassResolverAwareTraitTest.php index c438369e..2a58925e 100644 --- a/src/module/ClassResolver/test/ClassResolverTest/ClassResolverAwareTraitTest.php +++ b/src/module/ClassResolver/test/ClassResolverTest/ClassResolverAwareTraitTest.php @@ -23,9 +23,8 @@ namespace ClassResolverTest; use ClassResolverTest\Fake\ClassResolverAware; -use PHPUnit\Framework\TestCase; -class ClassResolverAwareTraitTest extends TestCase +class ClassResolverAwareTraitTest extends \PHPUnit_Framework_TestCase { protected $trait; @@ -36,7 +35,7 @@ public function setUp() public function testSetGet() { - $mock = $this->getMock('ClassResolver\ClassResolver'); + $mock = $this->createMock('ClassResolver\ClassResolver'); $this->trait->setClassResolver($mock); $this->assertSame($mock, $this->trait->getClassResolver()); } diff --git a/src/module/ClassResolver/test/ClassResolverTest/ClassResolverFactoryTest.php b/src/module/ClassResolver/test/ClassResolverTest/ClassResolverFactoryTest.php index 92f4b42b..a2b7c2a8 100644 --- a/src/module/ClassResolver/test/ClassResolverTest/ClassResolverFactoryTest.php +++ b/src/module/ClassResolver/test/ClassResolverTest/ClassResolverFactoryTest.php @@ -24,9 +24,8 @@ use ClassResolver\ClassResolverFactory; use Zend\ServiceManager\ServiceManager; -use PHPUnit\Framework\TestCase; -class ClassResolverFactoryTest extends TestCase +class ClassResolverFactoryTest extends \PHPUnit_Framework_TestCase { public function testFactory() { diff --git a/src/module/ClassResolver/test/ClassResolverTest/ClassResolverTest.php b/src/module/ClassResolver/test/ClassResolverTest/ClassResolverTest.php index 84529d86..cc0a3e32 100644 --- a/src/module/ClassResolver/test/ClassResolverTest/ClassResolverTest.php +++ b/src/module/ClassResolver/test/ClassResolverTest/ClassResolverTest.php @@ -25,9 +25,8 @@ use ClassResolver\ClassResolver; use ClassResolverTest\Fake\Foo; use Zend\ServiceManager\ServiceManager; -use PHPUnit\Framework\TestCase; -class ClassResolverTest extends TestCase +class ClassResolverTest extends \PHPUnit_Framework_TestCase { protected $classResolver; protected $serviceLocatorMock; diff --git a/src/module/Type/test/TypeTest/Manager/TypeManagerTest.php b/src/module/Type/test/TypeTest/Manager/TypeManagerTest.php new file mode 100644 index 00000000..c88e1115 --- /dev/null +++ b/src/module/Type/test/TypeTest/Manager/TypeManagerTest.php @@ -0,0 +1,49 @@ +classResolver = $this->mockClassResolver(); + $this->objectManager = $this->mockObjectManager(); + $this->typeManager = new TypeManager($this->classResolver, $this->objectManager); + } + + public function testFindTypeByNames_OK() + { + $names = ["name1","name2"]; + $className = "Type\Entity\Type"; + $types = new ArrayCollection([new Type(),new Type()]); + + $this->prepareResolveClass($this->classResolver, TypeInterface::class, $className); + $this->prepareFindBy($this->objectManager, $className, ['name' => $names], $types->toArray()); + + $this->assertEquals($types, $this->typeManager->findTypesByNames($names)); + } + + public function testFindTypeByName_OK() + { + $name = "name"; + $className = "Type\Entity\Type"; + $type = new Type(); + + $this->prepareResolveClass($this->classResolver, TypeInterface::class, $className); + $this->prepareFindOneBy($this->objectManager, $className, ['name' => $name], $type); + + $this->assertEquals($type, $this->typeManager->findTypeByName($name)); + } +} diff --git a/src/test/AtheneTest/Bootstrap.php b/src/test/AtheneTest/Bootstrap.php index e6645bbb..feaea750 100644 --- a/src/test/AtheneTest/Bootstrap.php +++ b/src/test/AtheneTest/Bootstrap.php @@ -36,6 +36,7 @@ class Bootstrap { protected static $serviceManager; + protected static $application; public static function getApplication() diff --git a/src/test/AtheneTest/TestCase/ControllerTestCase.php b/src/test/AtheneTest/TestCase/AbstractControllerTestCase.php similarity index 61% rename from src/test/AtheneTest/TestCase/ControllerTestCase.php rename to src/test/AtheneTest/TestCase/AbstractControllerTestCase.php index f10babdd..16bcce0b 100644 --- a/src/test/AtheneTest/TestCase/ControllerTestCase.php +++ b/src/test/AtheneTest/TestCase/AbstractControllerTestCase.php @@ -22,32 +22,27 @@ */ namespace AtheneTest\TestCase; -abstract class ControllerTestCase extends ObjectManagerTestCase -{ +use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase; +/** + * @TODO please implement me if needed + * + * @package AtheneTest\TestCase + */ +abstract class AbstractControllerTestCase extends AbstractHttpControllerTestCase +{ /** * @var \Zend\Mvc\Controller\AbstractActionController */ protected $controller; - protected function prepareLanguageFromRequest($id, $code) + public function setUp() { - $languageManagerMock = $this->getMock('Language\Manager\LanguageManager'); - $languageServiceMock = $this->getMock('Language\Service\LanguageService'); - - $languageManagerMock->expects($this->atLeastOnce()) - ->method('getLanguageFromRequest') - ->will($this->returnValue($languageServiceMock)); - - $languageServiceMock->expects($this->any()) - ->method('getId') - ->will($this->returnValue($id)); - - $languageServiceMock->expects($this->any()) - ->method('getCode') - ->will($this->returnValue($code)); +// $this->setApplicationConfig( +// include __DIR__ . '/../../../config/application.config.php' +// ); - return $languageManagerMock; + parent::setUp(); } protected function preparePluginManager() @@ -56,7 +51,7 @@ protected function preparePluginManager() return $this->controller->getPluginManager(); } - $pluginManager = $this->getMock('Zend\Mvc\Controller\PluginManager'); + $pluginManager = $this->createMock('Zend\Mvc\Controller\PluginManager'); $this->controller->setPluginManager($pluginManager); return $pluginManager; diff --git a/src/test/AtheneTest/TestCase/Model.php b/src/test/AtheneTest/TestCase/AbstractGetterSetterTestCase.php similarity index 60% rename from src/test/AtheneTest/TestCase/Model.php rename to src/test/AtheneTest/TestCase/AbstractGetterSetterTestCase.php index ae35d070..355842ba 100644 --- a/src/test/AtheneTest/TestCase/Model.php +++ b/src/test/AtheneTest/TestCase/AbstractGetterSetterTestCase.php @@ -20,15 +20,25 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://github.com/serlo-org/athene2 for the canonical source repository */ -namespace AtheneTest\TestCase; -use PHPUnit\Framework\TestCase; +namespace AtheneTest\TestCase; -abstract class Model extends TestCase +/** + * abstract class for auto-testing getter and setter methods. + * + * usage: extend this class, override getData() and call setObject($objectToTest) in your PHPUnit setUp() method; + * + * All get- and set-methods specified via getData() will be tested automatically. + * + * @package AtheneTest\TestCase + */ +abstract class AbstractGetterSetterTestCase extends \PHPUnit_Framework_TestCase { /** - * @return array + * example: for auto testing getTitle() and setTitle($title) return array("title" => "title") + * + * @return array data for get- and set-methods (key: name of get/set-method, value: value) */ abstract protected function getData(); @@ -44,34 +54,34 @@ protected function getObject() } /** - * @param mixed $reference + * @param mixed $objectToTest * @return $this */ - protected function setObject($object) + protected function setObject($objectToTest) { - $this->object = $object; + $this->object = $objectToTest; return $this; } + protected function inject() { - if (! is_array($this->data)) { + if (!is_array($this->data)) { $this->data = $this->getData(); } foreach ($this->data as $key => $value) { $method = 'set' . ucfirst($key); - if (method_exists($this->getObject(), $method)) { - $this->assertSame($this->getObject(), $this->getObject() - ->$method($value)); - } + $this->assertSame($this->getObject(), $this->getObject() + ->$method($value)); } return $this; } + public function testSetter() { - $object = $this->getObject(); + $this->object = $this->getObject(); $this->inject(); } @@ -81,12 +91,10 @@ public function testGetter() $this->inject(); foreach ($this->data as $key => $value) { $method = 'get' . ucfirst($key); - if (method_exists($object, $method)) { - if (is_object($object->$method())) { - $this->assertSame($value, $object->$method(), $method); - } else { - $this->assertEquals($value, $object->$method(), $method); - } + if (is_object($object->$method())) { + $this->assertSame($value, $object->$method(), $method); + } else { + $this->assertEquals($value, $object->$method(), $method); } } } diff --git a/src/test/AtheneTest/TestCase/AbstractManagerTestCase.php b/src/test/AtheneTest/TestCase/AbstractManagerTestCase.php new file mode 100644 index 00000000..9e89d80c --- /dev/null +++ b/src/test/AtheneTest/TestCase/AbstractManagerTestCase.php @@ -0,0 +1,208 @@ +createMock(ClassResolverInterface::class); + } + + /** + * Creates a mocked version of Zend\ServiceManager\ServiceManager + */ + final protected function mockServiceLocator() + { + return $this->createMock(ServiceManager::class); + } + + /** + * Creates a mocked version of Doctrine\Common\Persistence\ObjectManager + */ + final protected function mockObjectManager() + { + return $this->createMock(ObjectManager::class); + } + + /** + * Creates a mocked version of ZfcRbac\Service\AuthorizationService + */ + final protected function mockAuthorizationService() + { + return $this->createMock(AuthorizationService::class); + } + + /** + * Creates a mocked version of Zend\EventManager\EventManagerInterface + */ + final protected function mockEventManager() + { + return $this->createMock(EventManagerInterface::class); + } + + /** + * Registers a new expectation for method 'find' on $objectManager + * + * @param \PHPUnit_Framework_MockObject_MockObject $objectManager Mocked ObjectManager + * @param string $repositoryName Name of the repository + * @param mixed $id The identity of the object to find + * @param mixed $expectedReturn Expected return value for method "find" + */ + final protected function prepareFind(\PHPUnit_Framework_MockObject_MockObject $objectManager, $repositoryName, $id, $expectedReturn) + { + $objectManager->expects($this->once()) + ->method('find') + ->with($this->equalTo($repositoryName), $this->equalTo($id)) + ->will($this->returnValue($expectedReturn)); + } + + /** + * Registers a new expectation for method 'resolveClassName' on $classResolver + * + * @param \PHPUnit_Framework_MockObject_MockObject $classResolver Mocked ClassResolver + * @param string $classNameToResolve Name of class to resolve + * @param string $expectedReturn Expected return value for method "resolveClassName" + */ + final protected function prepareResolveClass(\PHPUnit_Framework_MockObject_MockObject $classResolver, $classNameToResolve, $expectedReturn) + { + $classResolver->expects($this->once()) + ->method('resolveClassName') + ->with($this->equalTo($classNameToResolve)) + ->will($this->returnValue($expectedReturn)); + } + + /** + * Registers a new expectation for method 'resolve' on $classResolver + * + * @param \PHPUnit_Framework_MockObject_MockObject $classResolver Mocked ClassResolver + * @param string $classNameToResolve Name of class to resolve + * @param mixed $expectedReturn Expected return value for method "resolve" + */ + final protected function prepareResolve(\PHPUnit_Framework_MockObject_MockObject $classResolver, $classNameToResolve, $expectedReturn) + { + $classResolver->expects($this->once()) + ->method('resolve') + ->with($this->equalTo($classNameToResolve)) + ->will($this->returnValue($expectedReturn)); + } + + /** + * Registers a new expectation for method 'isGranted' on $authorizationService + * + * @param \PHPUnit_Framework_MockObject_MockObject $authorizationService The mocked AuthorizationService + * @param string $permission The permission to check + * @param mixed $context Context of the permission + * @param boolean $expectedReturn Granted or not + */ + final protected function prepareIsGranted(\PHPUnit_Framework_MockObject_MockObject $authorizationService, $permission, $context, $expectedReturn) + { + $authorizationService->expects($this->once()) + ->method('isGranted') + ->with($this->equalTo($permission), $this->equalTo($context)) + ->will($this->returnValue($expectedReturn)); + } + + + /** + * Registers a new expectation for method 'findBy' on a mocked Repository specified via $repository + * + * @param \PHPUnit_Framework_MockObject_MockObject $objectManager Mocked ObjectManager for the Repository + * @param string $repository Name of the Repository + * @param array $criteria Criteria for findBy + * @param mixed $expectedReturn Expected return value for findBy + */ + final protected function prepareFindBy($objectManager, $repository, array $criteria, $expectedReturn) + { + $repo = $this->mockEntityRepository(); + + $objectManager->expects($this->once()) + ->method('getRepository') + ->with($repository) + ->will($this->returnValue($repo)); + + $repo->expects($this->once()) + ->method('findBy') + ->with($criteria) + ->will($this->returnValue($expectedReturn)); + } + + /** + * Registers a new expectation for method 'findOneBy' on a mocked Repository specified via $repository + * + * @param \PHPUnit_Framework_MockObject_MockObject $objectManager Mocked ObjectManager for the Repository + * @param string $repository Name of the Repository + * @param array $criteria Criteria for findOneBy + * @param mixed $expectedReturn Expected return value for findOneBy + */ + final protected function prepareFindOneBy($objectManager, $repository, array $criteria, $expectedReturn) + { + $repo = $this->mockEntityRepository(); + + $objectManager->expects($this->once()) + ->method('getRepository') + ->with($repository) + ->will($this->returnValue($repo)); + + $repo->expects($this->once()) + ->method('findOneBy') + ->with($criteria) + ->will($this->returnValue($expectedReturn)); + } +} diff --git a/src/test/AtheneTest/TestCase/ObjectManagerTestCase.php b/src/test/AtheneTest/TestCase/AbstractObjectManagerTestCase.php similarity index 73% rename from src/test/AtheneTest/TestCase/ObjectManagerTestCase.php rename to src/test/AtheneTest/TestCase/AbstractObjectManagerTestCase.php index d1c14d62..f9ba91d0 100644 --- a/src/test/AtheneTest/TestCase/ObjectManagerTestCase.php +++ b/src/test/AtheneTest/TestCase/AbstractObjectManagerTestCase.php @@ -22,15 +22,23 @@ */ namespace AtheneTest\TestCase; -use PHPUnit\Framework\TestCase; - -class ObjectManagerTestCase extends TestCase +abstract class AbstractObjectManagerTestCase extends \PHPUnit_Framework_TestCase { + /** + * Creates a mocked version of Doctrine\ORM\EntityManager + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ final protected function mockEntityManager() { - return $this->getMock('Doctrine\ORM\EntityManager', array(), array(), '', false); + return $this->createMock('Doctrine\ORM\EntityManager'); } + /** + * Creates a mocked version of Doctrine\ORM\EntityRepository + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ final protected function mockEntityRepository() { return $this->getMockBuilder('Doctrine\ORM\EntityRepository') diff --git a/src/test/AtheneTest/TestCase/ManagerTest.php b/src/test/AtheneTest/TestCase/ManagerTest.php deleted file mode 100644 index 7ec67a76..00000000 --- a/src/test/AtheneTest/TestCase/ManagerTest.php +++ /dev/null @@ -1,135 +0,0 @@ -manager; - } - - final public function setManager($manager) - { - $this->manager = $manager; - return $this; - } - - final protected function mockEntity($className, $id) - { - $entity = $this->getMock($className); - $entity->expects($this->any()) - ->method('getId') - ->will($this->returnValue(1)); - return $entity; - } - - final protected function prepareClassResolver(array $config) - { - if ($this->classResolver) { - return $this->classResolver; - } - - $this->classResolver = new ClassResolver($config); - $serviceLocator = $this->prepareServiceLocator(false); - - $this->getManager()->setClassResolver($this->classResolver); - $this->classResolver->setServiceLocator($serviceLocator); - - return $this->classResolver; - } - - final protected function prepareServiceLocator($inject = true) - { - if (! $this->serviceLocator) { - $this->serviceLocator = $this->getMock('Zend\ServiceManager\ServiceManager'); - } - - if ($inject) { - $this->getManager()->setServiceLocator($this->serviceLocator); - } - - return $this->serviceLocator; - } - - final protected function prepareObjectManager($inject = true) - { - if (! $this->objectManager) { - $this->objectManager = $this->mockEntityManager(); - } - if ($inject) { - $this->getManager()->setObjectManager($this->objectManager); - } - return $this->objectManager; - } - - final protected function prepareFind($repositoryName, $key, $return) - { - $objectManager = $this->prepareObjectManager(); - - $objectManager->expects($this->once()) - ->method('find') - ->with($repositoryName, $key) - ->will($this->returnValue($return)); - } - - final protected function prepareFindBy($repositoryName, array $criteria, $return) - { - $objectManager = $this->prepareObjectManager(); - $repository = $this->mockEntityRepository(); - - $objectManager->expects($this->once()) - ->method('getRepository') - ->with($repositoryName) - ->will($this->returnValue($repository)); - - $repository->expects($this->once()) - ->method('findBy') - ->with($criteria) - ->will($this->returnValue($return)); - } - - final protected function prepareFindOneBy($repositoryName, array $criteria, $return) - { - $objectManager = $this->prepareObjectManager(); - $repository = $this->mockEntityRepository(); - - $objectManager->expects($this->once()) - ->method('getRepository') - ->with($repositoryName) - ->will($this->returnValue($repository)); - - $repository->expects($this->once()) - ->method('findOneBy') - ->with($criteria) - ->will($this->returnValue($return)); - } -} diff --git a/src/test/AtheneTest/deprecated.xml b/src/test/AtheneTest/deprecated.xml deleted file mode 100644 index ab03b8ab..00000000 --- a/src/test/AtheneTest/deprecated.xml +++ /dev/null @@ -1,44 +0,0 @@ - - - ../../module/User/test - - - ../../module/LearningResource/test - - - ../../module/Entity/test - - - ../../module/Link/test - - - ../../module/Blog/test - - - ../../module/Language/test - - - ../../module/Uuid/test - - - ../../module/Term/test - - - ../../module/Versioning/test - - - ../../module/Subject/test - - - ../../module/ClassResolver/test - - - ../../module/Common/test - - - ../../module/Token/test - - - ../../module/Page/test - - \ No newline at end of file