-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PhpUnit) - Add unit test generator
- Add TestGenerator - Add MockGenerator - Add DataProviderGenerator
- Loading branch information
0 parents
commit 1d6b433
Showing
59 changed files
with
5,540 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM php:7.4-cli | ||
|
||
RUN apt-get update && apt-get install -y git unzip | ||
|
||
ENV COMPOSER_ALLOW_SUPERUSER 1 | ||
ENV COMPOSER_MEMORY_LIMIT -1 | ||
|
||
RUN mkdir /.composer_cache | ||
ENV COMPOSER_CACHE_DIR /.composer_cache | ||
|
||
RUN mkdir /packages | ||
COPY packages /packages/ | ||
WORKDIR /packages/Saga | ||
|
||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | ||
RUN composer -vvv global require hirak/prestissimo | ||
RUN composer install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM php:7.4-cli | ||
|
||
RUN apt-get update && apt-get install -y git unzip | ||
|
||
ENV COMPOSER_ALLOW_SUPERUSER 1 | ||
ENV COMPOSER_MEMORY_LIMIT -1 | ||
|
||
RUN mkdir /.composer_cache | ||
ENV COMPOSER_CACHE_DIR /.composer_cache | ||
|
||
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer | ||
|
||
RUN composer -vvv global require hirak/prestissimo | ||
|
||
# php extensions | ||
RUN pecl install xdebug | ||
RUN docker-php-ext-enable xdebug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
charset = utf-8 | ||
|
||
# 4 space indentation | ||
[*.php] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
# Tab indentation (no size specified) | ||
[Makefile] | ||
indent_style = tab | ||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[{*.yml, *.yaml}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[composer.json] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
###> common variables ### | ||
GENERATOR_COMPOSE_PROJECT_NAME=unit-test-generator | ||
CI_COMMIT_REF_SLUG=master | ||
###< common variables ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
###> symfony/framework-bundle ### | ||
.env.local | ||
.env.local.php | ||
.env.*.local | ||
.env.dist | ||
|
||
var/ | ||
vendor/ | ||
###< symfony/framework-bundle ### | ||
|
||
###> PhpStorm project profile ### | ||
.idea/ | ||
###< PhpStorm project profile ### | ||
|
||
###> phpunit/phpunit ### | ||
phpunit.xml | ||
.phpunit.result.cache | ||
###< phpunit/phpunit ### | ||
|
||
###> friendsofphp/php-cs-fixer ### | ||
.php_cs.cache | ||
###< friendsofphp/php-cs-fixer ### | ||
|
||
###> squizlabs/php_codesniffer ### | ||
.phpcs-cache | ||
phpcs.xml | ||
###< squizlabs/php_codesniffer ### | ||
|
||
###> sensiolabs-de/deptrac ### | ||
.deptrac.cache | ||
###< sensiolabs-de/deptrac ### | ||
|
||
# Build data | ||
build/ | ||
|
||
###> Phpunit ### | ||
bin/.phpunit | ||
###< Phpunit ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
version = $(shell git describe --tags --dirty --always) | ||
build_name = application-$(version) | ||
# use the rest as arguments for "run" | ||
RUN_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) | ||
# ...and turn them into do-nothing targets | ||
#$(eval $(RUN_ARGS):;@:) | ||
|
||
.PHONY: fix-permission | ||
fix-permission: ## fix permission for docker env | ||
sudo chown -R $(shell whoami):$(shell whoami) * | ||
sudo chown -R $(shell whoami):$(shell whoami) .docker/* | ||
|
||
.PHONY: build | ||
build: ## build environment and initialize composer and project dependencies | ||
docker-compose build | ||
make composer-install | ||
|
||
.PHONY: composer-install | ||
composer-install: ## Install project dependencies | ||
docker-compose run --rm --no-deps php sh -lc 'composer install' | ||
|
||
.PHONY: composer-update | ||
composer-update: ## Update project dependencies | ||
docker-compose run --rm --no-deps php sh -lc 'composer update' | ||
|
||
.PHONY: composer-outdated | ||
composer-outdated: ## Show outdated project dependencies | ||
docker-compose run --rm --no-deps php sh -lc 'composer outdated' | ||
|
||
.PHONY: composer-validate | ||
composer-validate: ## Validate composer config | ||
docker-compose run --rm --no-deps php sh -lc 'composer validate --no-check-publish' | ||
|
||
.PHONY: composer | ||
composer: ## Execute composer command | ||
docker-compose run --rm --no-deps php sh -lc "composer $(RUN_ARGS)" | ||
|
||
.PHONY: phpunit | ||
phpunit: ## execute project unit tests | ||
docker-compose run --rm php sh -lc "./vendor/bin/phpunit $(conf)" | ||
|
||
.PHONY: style | ||
style: ## executes php analizers | ||
docker-compose run --rm --no-deps php sh -lc './vendor/bin/phpstan analyse -l 6 -c phpstan.neon src' | ||
docker-compose run --rm --no-deps php sh -lc './vendor/bin/psalm --config=psalm.xml' | ||
|
||
.PHONY: lint | ||
lint: ## checks syntax of PHP files | ||
docker-compose run --rm --no-deps php sh -lc './vendor/bin/parallel-lint ./ --exclude vendor --exclude bin/.phpunit' | ||
|
||
.PHONY: logs | ||
logs: ## look for service logs | ||
docker-compose logs -f $(RUN_ARGS) | ||
|
||
.PHONY: help | ||
help: ## Display this help message | ||
@cat $(MAKEFILE_LIST) | grep -e "^[a-zA-Z_\-]*: *.*## *" | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
.PHONY: php-shell | ||
php-shell: ## PHP shell | ||
docker-compose run --rm php sh -l | ||
|
||
unit-tests: ## Run unit-tests suite | ||
docker-compose run --rm php sh -lc 'vendor/bin/phpunit --testsuite unit-tests' | ||
|
||
static-analysis: style coding-standards ## Run phpstan, easycoding standarts code static analysis | ||
|
||
coding-standards: ## Run check and validate code standards tests | ||
docker-compose run --rm --no-deps php sh -lc 'vendor/bin/ecs check src' | ||
docker-compose run --rm --no-deps php sh -lc 'vendor/bin/phpmd src/ text phpmd.xml' | ||
|
||
coding-standards-fixer: ## Run code standards fixer | ||
docker-compose run --rm --no-deps php sh -lc 'vendor/bin/ecs check src --fix' | ||
|
||
security-tests: ## The SensioLabs Security Checker | ||
docker-compose run --rm --no-deps php sh -lc 'vendor/bin/security-checker security:check --end-point=http://security.sensiolabs.org/check_lock' | ||
|
||
.PHONY: test lint static-analysis phpunit coding-standards composer-validate | ||
test: build lint static-analysis phpunit coding-standards composer-validate stop ## Run all test suites |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Unit test generator | ||
===================== | ||
|
||
Proof-of-concept component providing unit test generator. | ||
|
||
## Documentation | ||
This project can generate or single unit for one class or for all project with all needed mocks. | ||
|
||
## Getting started | ||
* For example if you want generate unit test for one class use following code: | ||
|
||
`$testGenerator = new MicroModule\UnitTestGenerator\Service\TestClass();` | ||
`$testGenerator->generate(FooService::class);` | ||
|
||
* For generate tests and mocks for all project use: | ||
|
||
`$testGenerator = new MicroModule\UnitTestGenerator\Service\TestProject(realpath('src'), ['Migrations', 'Presentation', 'Exception']);` | ||
`$testGenerator->generate();` | ||
|
||
second argument is array of excluded folders | ||
|
||
## License | ||
This project is licensed under the MIT License - see the LICENSE file for details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "micro-module/unit-test-generator", | ||
"description": "POC for unit test generator", | ||
"type": "library", | ||
"license": "proprietary", | ||
"require": { | ||
"php": "^7.4", | ||
"ext-json": "*", | ||
"fzaninotto/faker": "^1.9" | ||
}, | ||
"require-dev": { | ||
"jakub-onderka/php-console-highlighter": "^0.4", | ||
"jakub-onderka/php-parallel-lint": "^1.0", | ||
"mockery/mockery": "^1.2", | ||
"phpmd/phpmd": "^2.6", | ||
"phpstan/phpstan": "^0.11", | ||
"phpstan/phpstan-mockery": "^0.11", | ||
"phpstan/phpstan-phpunit": "^0.11", | ||
"phpunit/phpunit": "^8.0", | ||
"roave/security-advisories": "dev-master", | ||
"symplify/easy-coding-standard": "^5.4", | ||
"vimeo/psalm": "^3.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"MicroModule\\UnitTestGenerator\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: "3.7" | ||
|
||
services: | ||
php: | ||
container_name: ${GENERATOR_COMPOSE_PROJECT_NAME}_php | ||
user: 1000:1000 | ||
build: | ||
context: .docker/php7.4-dev | ||
volumes: | ||
- ~/.composer/cache/:/.composer_cache/:rw | ||
- ../:/packages:rw | ||
working_dir: /packages/UnitTestGenerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
imports: | ||
- { resource: 'vendor/symplify/easy-coding-standard/config/set/clean-code.yaml' } | ||
- { resource: 'vendor/symplify/easy-coding-standard/config/set/symfony.yaml' } | ||
- { resource: 'vendor/symplify/easy-coding-standard/config/set/php71.yaml' } | ||
- { resource: 'vendor/symplify/easy-coding-standard/config/set/psr12.yaml' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset name="Ruleset" | ||
xmlns="http://pmd.sf.net/ruleset/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"> | ||
<description>Ruleset for PHP Mess Detector that enforces coding standards</description> | ||
|
||
<rule ref="rulesets/cleancode.xml"> | ||
<exclude name="StaticAccess"/> | ||
</rule> | ||
|
||
<rule ref="rulesets/codesize.xml"/> | ||
|
||
<rule ref="rulesets/controversial.xml"/> | ||
|
||
<rule ref="rulesets/design.xml"/> | ||
|
||
<rule ref="rulesets/naming.xml"> | ||
<exclude name="ShortVariable"/> | ||
<exclude name="LongVariable"/> | ||
<exclude name="ShortMethodName"/> | ||
</rule> | ||
|
||
<rule ref="rulesets/unusedcode.xml"> | ||
<!-- PHPMD cannot recognize parameters that are enforced by an interface --> | ||
<exclude name="UnusedFormalParameter"/> | ||
</rule> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-mockery/extension.neon | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="vendor/autoload.php" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1" /> | ||
<env name="APP_ENV" value="test" /> | ||
<env name="APP_DEBUG" value="1" /> | ||
<env name="GENERATOR_COMPOSE_PROJECT_NAME" value="unit-test-generator" /> | ||
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" /> | ||
</php> | ||
|
||
<testsuites> | ||
<testsuite name="unit-tests"> | ||
<directory>tests/unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<logging> | ||
<log type="coverage-html" target="var/report/html" lowUpperBound="35" highLowerBound="70"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
totallyTyped="false" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config file:///app/vendor/vimeo/psalm/config.xsd" | ||
> | ||
<projectFiles> | ||
<directory name="src" /> | ||
<ignoreFiles> | ||
<directory name="vendor" /> | ||
</ignoreFiles> | ||
</projectFiles> | ||
|
||
<issueHandlers> | ||
<LessSpecificReturnType errorLevel="info" /> | ||
|
||
<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives --> | ||
|
||
<DeprecatedMethod errorLevel="info" /> | ||
<DeprecatedProperty errorLevel="info" /> | ||
<DeprecatedClass errorLevel="info" /> | ||
<DeprecatedConstant errorLevel="info" /> | ||
<DeprecatedInterface errorLevel="info" /> | ||
<DeprecatedTrait errorLevel="info" /> | ||
|
||
<InternalMethod errorLevel="info" /> | ||
<InternalProperty errorLevel="info" /> | ||
<InternalClass errorLevel="info" /> | ||
|
||
<MissingClosureReturnType errorLevel="info" /> | ||
<MissingReturnType errorLevel="info" /> | ||
<MissingPropertyType errorLevel="info" /> | ||
<InvalidDocblock errorLevel="info" /> | ||
<MisplacedRequiredParam errorLevel="info" /> | ||
|
||
<PropertyNotSetInConstructor errorLevel="info" /> | ||
<MissingConstructor errorLevel="info" /> | ||
<MissingClosureParamType errorLevel="info" /> | ||
<MissingParamType errorLevel="info" /> | ||
|
||
<RedundantCondition errorLevel="info" /> | ||
|
||
<DocblockTypeContradiction errorLevel="info" /> | ||
<RedundantConditionGivenDocblockType errorLevel="info" /> | ||
|
||
<UnresolvableInclude errorLevel="info" /> | ||
|
||
<RawObjectIteration errorLevel="info" /> | ||
|
||
<InvalidStringClass errorLevel="info" /> | ||
</issueHandlers> | ||
</psalm> |
Oops, something went wrong.