Skip to content

Commit

Permalink
HOp
Browse files Browse the repository at this point in the history
  • Loading branch information
jokesterfr committed Aug 13, 2024
1 parent 0154152 commit e5bc382
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.env
dist/
vendor/
prestashop/

# Composer
composer.phar
Expand Down
42 changes: 32 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ MODULE_NAME = ps_accounts
VERSION ?= $(shell git describe --tags 2> /dev/null || echo "v0.0.0")
SEM_VERSION ?= $(shell echo ${VERSION} | sed 's/^v//')
PACKAGE ?= ${MODULE_NAME}_mock-${VERSION}
PS_VERSION ?= latest
PS_VERSION ?= 8.1.7
TESTING_IMAGE ?= prestashop/prestashop-flashlight:${PS_VERSION}
PS_ROOT_DIR ?= $(shell pwd)/prestashop/prestashop-${PS_VERSION}

export PHP_CS_FIXER_IGNORE_ENV = 1
export _PS_ROOT_DIR_ ?= ${PS_ROOT_DIR}
export PATH := ./vendor/bin:./tools/vendor/bin:$(PATH)
export PATH := ./vendor/bin:./tests/vendor/bin:$(PATH)

# target: default - Calling build by default
default: build
Expand All @@ -26,7 +26,7 @@ clean:

# target: build - Setup PHP & Node.js locally
.PHONY: build
build: vendor tools/vendor
build: vendor tests/vendor

# target: zip - Make a distributable zip
.PHONY: zip
Expand All @@ -46,13 +46,28 @@ composer.phar:
vendor: composer.phar
./composer.phar install -o;

tools/vendor: composer.phar vendor
./composer.phar install --working-dir tools -o;
tests/vendor: composer.phar vendor
./composer.phar install --working-dir tests -o;

prestashop:
@mkdir -p ./prestashop

prestashop/prestashop-${PS_VERSION}: prestashop composer.phar
@if [ ! -d "prestashop/prestashop-${PS_VERSION}" ]; then \
git clone --depth 1 --branch ${PS_VERSION} https://github.com/PrestaShop/PrestaShop.git prestashop/prestashop-${PS_VERSION} > /dev/null; \
if [ "${PS_VERSION}" != "1.6.1.24" ]; then \
./composer.phar -d ./prestashop/prestashop-${PS_VERSION} install; \
fi \
fi;

# target: test - Static and unit testing
.PHONY: test
test: composer-validate lint php-lint phpstan

# target: docker-test - Static and unit testing in docker
.PHONY: docker-test
docker-test: docker-lint docker-phpstan docker-phpunit

# target: composer-validate (or docker-composer-validate) - Validates composer.json and composer.lock
.PHONY: composer-validate
composer-validate: vendor
Expand All @@ -72,26 +87,33 @@ docker-lint-fix: docker-php-cs-fixer-fix

# target: php-cs-fixer (or docker-php-cs-fixer) - Lint the code and expose errors
.PHONY: php-cs-fixer docker-php-cs-fixer
php-cs-fixer: tools/vendor
php-cs-fixer: tests/vendor
@php-cs-fixer fix --dry-run --diff;
docker-php-cs-fixer: tools/vendor
docker-php-cs-fixer: tests/vendor
@$(call in_docker,make,lint)

# target: php-cs-fixer-fix (or docker-php-cs-fixer-fix) - Lint the code and fix it
.PHONY: php-cs-fixer-fix docker-php-cs-fixer-fix
php-cs-fixer-fix: tools/vendor
php-cs-fixer-fix: tests/vendor
@php-cs-fixer fix
docker-php-cs-fixer-fix: tools/vendor
docker-php-cs-fixer-fix: tests/vendor
@$(call in_docker,make,lint-fix)

# target: php-lint (or docker-php-lint) - Lint the code with the php linter
.PHONY: php-lint docker-php-lint
php-lint:
@find . -type f -name '*.php' -not -path "./vendor/*" -not -path "./tools/*" -not -path "./prestashop/*" -print0 | xargs -0 -n1 php -l -n | (! grep -v "No syntax errors" );
@find . -type f -name '*.php' -not -path "./vendor/*" -not -path "./tests/*" -not -path "./prestashop/*" -print0 | xargs -0 -n1 php -l -n | (! grep -v "No syntax errors" );
@echo "php $(shell php -r 'echo PHP_VERSION;') lint passed";
docker-php-lint:
@$(call in_docker,make,php-lint)

# target: phpstan (or docker-phpstan) - Run phpstan
.PHONY: phpstan docker-phpstan
phpstan: tests/vendor prestashop/prestashop-${PS_VERSION}
phpstan analyse --memory-limit=-1 --configuration=./tests/phpstan/phpstan-local.neon;
docker-phpstan:
@$(call in_docker,/usr/bin/phpstan,analyse --memory-limit=-1 --configuration=./tests/phpstan/phpstan-docker.neon)

define replace_version
echo "Setting up version: ${VERSION}..."
sed -i.bak -e "s/\(VERSION = \).*/\1\'${2}\';/" ${1}/${MODULE_NAME}.php
Expand Down
4 changes: 0 additions & 4 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@ services:
PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter:
class: PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter
public: true

PrestaShop\Module\PsAccounts\Repository\UserTokenRepository:
class: PrestaShop\Module\PsAccounts\Repository\UserTokenRepository
public: true
2 changes: 1 addition & 1 deletion e2e-env/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
- ..:/var/www/html/modules/ps_accounts:rw
- ./init-scripts:/tmp/init-scripts:ro
- /var/www/html/modules/ps_accounts/vendor
- /var/www/html/modules/ps_accounts/tools/vendor
- /var/www/html/modules/ps_accounts/tests/vendor
environment:
- PS_DOMAIN=localhost:8000
- ON_INIT_SCRIPT_FAILURE=fail
Expand Down
4 changes: 2 additions & 2 deletions e2e-env/init-scripts/install-module.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ ps_accounts_mock_install() {
# see multiple mounts on the same files:
# - ..:/var/www/html/modules/ps_eventbus:rw => mount all the sources
# - /var/www/html/modules/ps_eventbus/vendor => void the specific vendor dir, makint it empty
# - /var/www/html/modules/ps_eventbus/tools/vendor => void the specific vendor dev dir, making it empty
# - /var/www/html/modules/ps_eventbus/tests/vendor => void the specific vendor dev dir, making it empty
#
# That said, we now want our container to have RW access on these directories,
# and to install the required composer dependencies for the module to work.
#
# Other scenarios could be imagined, but this is the best way to avoid writes on a mounted volume,
# which would not work on a Linux environment (binding a volume), as opposed to a Windows or Mac one (NFS mount).
chown www-data:www-data ./modules/ps_accounts/vendor
chown www-data:www-data ./modules/ps_accounts/tools/vendor
chown www-data:www-data ./modules/ps_accounts/tests/vendor
run_user composer install -n -d ./modules/ps_accounts

echo "* [ps_accounts_mock] installing the module..."
Expand Down
20 changes: 20 additions & 0 deletions ps_accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ public function __construct()
);
}

/**
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
* @throws Exception
*/
public function install()
{
$db = \Db::getInstance();
Expand All @@ -67,6 +74,12 @@ public function install()
return parent::install();
}

/**
* @return bool
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
public function uninstall()
{
if (parent::uninstall() == false) {
Expand All @@ -76,6 +89,13 @@ public function uninstall()
return true;
}

/**
* @param string $serviceName
*
* @return mixed
*
* @throws Exception
*/
public function getService($serviceName)
{
return $this->serviceContainer->getService($serviceName);
Expand Down
6 changes: 4 additions & 2 deletions src/Presenter/PsAccountsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public function __construct()
{
}

public function present($name)
/**
* @return void
*/
public function present()
{
return $name;
}
}
15 changes: 0 additions & 15 deletions src/Repository/UserTokenRepository.php

This file was deleted.

36 changes: 36 additions & 0 deletions src/Service/PsAccountsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,97 @@ public function __construct()
{
}

/**
* @return string
*/
public function getSuperAdminEmail()
{
return '[email protected]';
}

/**
* @return string
*/
public function getShopUuid()
{
return 'f07181f7-2399-406d-9226-4b6c14cf6068';
}

/**
* @return string
*/
public function getShopUuidV4()
{
return $this->getShopUuid();
}

/**
* @return string
*/
public function getOrRefreshToken()
{
return 'eyJhbGciOiJSUzI1NiIsImtpZCI6IjFlOTczZWUwZTE2ZjdlZWY0ZjkyMWQ1MGRjNjFkNzBiMmVmZWZjMTkiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vcHJlc3Rhc2hvcC1yZWFkeS1wcm9kIiwiYXVkIjoicHJlc3Rhc2hvcC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zari-50PkhsnkD_DQ-dbmgpiKuM3ZFnL6vCSVw';
}

/**
* @return string
*/
public function getUserUuid()
{
return 'f07181f7-2399-406d-9226-4b6c14cf6068';
}

/**
* @return bool
*/
public function isEmailValidated()
{
return true;
}

/**
* @return string
*/
public function getEmail()
{
return '[email protected]';
}

/**
* @return bool
*/
public function isAccountLinked()
{
return true;
}

/**
* @return bool
*/
public function isAccountLinkedV4()
{
return true;
}

/**
* @return string
*/
public function getAccountsVueCdn()
{
return 'test.com';
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/phpstan/phpstan-docker.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
includes:
- /var/opt/prestashop/coding-standards/phpstan/ps-module-extension.neon
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
3 changes: 3 additions & 0 deletions tests/phpstan/phpstan-local.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
includes:
- %currentWorkingDirectory%/tests/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
9 changes: 9 additions & 0 deletions tests/phpstan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
paths:
- ../../src
- ../../config
- ../../ps_accounts.php
reportUnmatchedIgnoredErrors: false
ignoreErrors:
- identifier: missingType.iterableValue
level: 9

0 comments on commit e5bc382

Please sign in to comment.