Skip to content

Commit

Permalink
add php unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karliuka committed Sep 6, 2021
1 parent fa280a7 commit ebd50c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
11 changes: 9 additions & 2 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@
entry: magento-phpstan
language: python
types: [php]
- id: magento-phpunit
name: PHPUnit test
entry: magento-phpunit
language: python
pass_filenames: false
always_run: true
args: ["-c=dev/tests/unit/phpunit.xml"]
- id: magento-webapi-rest-phpunit
name: REST API PHPUnit test
entry: magento-webapi-rest-phpunit
language: python
pass_filenames: false
always_run: true
args: ["-c=dev/tests/api-functional/phpunit_rest.xml"]
args: ["--type=Api", "-c=dev/tests/api-functional/phpunit_rest.xml"]
- id: magento-webapi-soap-phpunit
name: SOAP API PHPUnit test
entry: magento-webapi-soap-phpunit
language: python
pass_filenames: false
always_run: true
args: ["-c=dev/tests/api-functional/phpunit_soap.xml"]
args: ["--type=Api", "-c=dev/tests/api-functional/phpunit_soap.xml"]
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from typing import Sequence
from pathlib import Path

# magento module relative path patern
PATHPATERN = '**/app/code/*/*'

def main(argv: Optional[Sequence[str]] = None) -> int:
# return flag
retval = 0
Expand All @@ -25,14 +22,18 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
'-c', '--configuration', dest = 'config',
help = 'specifies the path to a configuration file'
)
parser.add_argument(
'--type', default = 'Unit', dest = 'type',
help = 'specifies the part of path to a tested files'
)
args = parser.parse_args(argv)

if module.match(PATHPATERN):
if module.match('**/app/code/*/*'):
# path to the root of magento
magento = module.parent.parent.parent.parent
# path to the phpunit
exe = magento / 'vendor/bin/phpunit'
test = module / 'Test/Api/'
test = module / f'Test/{args.type}/'

if test.is_dir():
if exe.is_file():
Expand Down
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pre_commit_hooks
version = 1.0.1
version = 1.0.3
description = Some magento hooks for pre-commit.
long_description = file: README.md
long_description_content_type = text/markdown
Expand All @@ -18,5 +18,6 @@ python_requires = >=3.6.1
console_scripts =
magento-phpcs = pre_commit_hooks.magento_phpcs:main
magento-phpstan = pre_commit_hooks.magento_phpstan:main
magento-webapi-rest-phpunit = pre_commit_hooks.magento_webapi_phpunit:main
magento-webapi-soap-phpunit = pre_commit_hooks.magento_webapi_phpunit:main
magento-phpunit = pre_commit_hooks.magento_phpunit:main
magento-webapi-rest-phpunit = pre_commit_hooks.magento_phpunit:main
magento-webapi-soap-phpunit = pre_commit_hooks.magento_phpunit:main

0 comments on commit ebd50c8

Please sign in to comment.