From 20252eee4b70863b7dc7b3f58aab6ffe2d9691de Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Mon, 22 May 2017 16:09:24 +0200 Subject: [PATCH] Add nette tester support --- README.md | 18 ++++++++++++++ composer.json | 9 ++++++- composer.lock | 58 ++++++++++++++++++++++++++++++++++++++++++++- tests/bootstrap.php | 3 +++ tests/php.ini | 1 + 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 tests/bootstrap.php create mode 100644 tests/php.ini diff --git a/README.md b/README.md index d8fc4fc..9e52750 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,24 @@ To run the server inside docker, run docker-compose up -d +## Nette Tester + +[Nette Tester](https://github.com/nette/tester/) is a lightweight alternative to [PHPUnit](https://phpunit.de/). + +Place your tests under `./tests/` followed by PSR-4 compatible directory structure, so a class `App\Controllers\Hello` goes into `./tests/App/Controllers/Hello.phpt`. + +Remember to `require_once __DIR__ .'/../bootstrap.php'` (add appropriate number of `../` to point to `./tests/bootstrap.php`) to enable autoloading of your classes. + +Tests should be under `Tests\` namespace followed by the namespace of the class being tested, so the test class `App\Controllers\HelloTest` goes under `Tests\App\Controllers` namespace. + +Run + + composer tester + +to run the testsuite. + +If you need additional extensions to load during tests, add them to `./tests/php.ini` (`json` is included by default). + ## PHPStan - PHP Static analysis [PHPStan](https://github.com/phpstan/phpstan) is a static code analysis tool. It is already set up in the repo, to run the report use diff --git a/composer.json b/composer.json index a4ef710..878fd34 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "php": ">=7.0.0", "slim/slim": "^3.1", "monolog/monolog": "^1.17", - "nette/neon": "^2.4" + "nette/neon": "^2.4", + "nette/tester": "^1.7" }, "require-dev": { "phpstan/phpstan": "^0.7.0", @@ -21,12 +22,18 @@ "App\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, "config": { "process-timeout" : 0 }, "scripts": { "start": "php -S 0.0.0.0:8080 -t public public/index.php", "phpstan": "phpstan analyze -l 7 -c tests/phpstan.neon src", + "tester": "tester -p php -c tests/php.ini tests", "phpcs": "phpcs src" } } diff --git a/composer.lock b/composer.lock index 0be10ed..cfe38f1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "66278e88a0530e32639cb0755b82ba44", + "content-hash": "7394a00cf4db40b6104be45d4e47a11e", "packages": [ { "name": "container-interop/container-interop", @@ -169,6 +169,62 @@ "homepage": "http://ne-on.org", "time": "2017-01-13T08:00:19+00:00" }, + { + "name": "nette/tester", + "version": "v1.7.1", + "source": { + "type": "git", + "url": "https://github.com/nette/tester.git", + "reference": "d97534578e8cf66eabe081e7d5eaa4dd527ab0c8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/tester/zipball/d97534578e8cf66eabe081e7d5eaa4dd527ab0c8", + "reference": "d97534578e8cf66eabe081e7d5eaa4dd527ab0c8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "bin": [ + "src/tester" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0", + "GPL-3.0" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "An easy-to-use PHP unit testing framework.", + "homepage": "https://tester.nette.org", + "keywords": [ + "nette", + "testing", + "unit" + ], + "time": "2016-03-19T14:34:02+00:00" + }, { "name": "nikic/fast-route", "version": "v1.2.0", diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..e71010a --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,3 @@ +