diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99a6714 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +composer.lock +vendor + +tests/php-unix.generated.ini diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..adadc6c --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +.PHONY: all test + +all: test + echo "Is done" + +test: phpstan + bin/run-tests.sh + +phpstan: + vendor/bin/phpstan analyse -l 7 -c tests/config/phpstan.neon \ + src \ + tests/cases diff --git a/run-tests.sh b/bin/run-tests.sh similarity index 55% rename from run-tests.sh rename to bin/run-tests.sh index 4afeed6..ba12502 100755 --- a/run-tests.sh +++ b/bin/run-tests.sh @@ -1,5 +1,5 @@ #!/bin/bash -cat tests/php-unix.ini > tests/php-unix.generated.ini +cat tests/config/php-unix.ini > tests/php-unix.generated.ini vendor/bin/tester -p php -c tests/php-unix.generated.ini tests diff --git a/composer.json b/composer.json index 83f91a2..ff004ce 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "require": { "php": ">=7.1", - "trejjam/thepay-lib": "dev-namespaces#aef9b4c", + "trejjam/thepay-lib": "dev-namespaces#f9e6cf2", "trejjam/base-extension": "~0.7", "nette/di": "~2.3", "nette/application": "~2.3", @@ -22,7 +22,8 @@ "nette/tester": "@dev", "nette/bootstrap": "@dev", "nette/robot-loader": "@dev", - "tracy/tracy": "@dev" + "tracy/tracy": "@dev", + "phpstan/phpstan": "^0.9.2" }, "autoload": { "psr-4": { diff --git a/src/Helper/DataApi.php b/src/Helper/DataApi.php index 0e268fc..545ebc1 100644 --- a/src/Helper/DataApi.php +++ b/src/Helper/DataApi.php @@ -11,7 +11,7 @@ class DataApi { /** - * @var Tp\MerchantConfig + * @var Trejjam\ThePay\MerchantConfig */ protected $config; @@ -31,10 +31,10 @@ public function getPaymentMethods(bool $onlyActive = TRUE) : Tp\DataApi\Response } /** - * @param Tp\DataApi\Parameters\MerchantAccountMethod $method - * @param string(tight|209x127|86x86) $type + * @param Parameters\MerchantAccountMethod $method + * @param string $type (tight|209x127|86x86) * - * @return null|string + * @return string */ public function getPaymentMethodIcon(Parameters\MerchantAccountMethod $method, string $type = 'tight') : string { @@ -43,17 +43,17 @@ public function getPaymentMethodIcon(Parameters\MerchantAccountMethod $method, s ]) . 'images/logos/public/' . $type . '/' . $method->getId() . '.png'; } - public function getPayment(string $paymentId) : Tp\DataApi\Responses\GetPaymentResponse + public function getPayment(int $paymentId) : Tp\DataApi\Responses\GetPaymentResponse { return Tp\Helper\DataApi::getPayment($this->config, $paymentId); } - public function getPaymentInstructions(string $paymentId) : Tp\DataApi\Responses\GetPaymentInstructionsResponse + public function getPaymentInstructions(int $paymentId) : Tp\DataApi\Responses\GetPaymentInstructionsResponse { return Tp\Helper\DataApi::getPaymentInstructions($this->config, $paymentId); } - public function getPaymentState(string $paymentId) : Tp\DataApi\Responses\GetPaymentStateResponse + public function getPaymentState(int $paymentId) : Tp\DataApi\Responses\GetPaymentStateResponse { return Tp\Helper\DataApi::getPaymentState($this->config, $paymentId); } @@ -67,7 +67,7 @@ public function getPayments( } /** - * @param $type + * @param mixed $type * @param array $paymentMethods * * @return Tp\DataApi\Responses\SetPaymentMethodsResponse diff --git a/src/Payment.php b/src/Payment.php index 43cb11f..d7c309d 100644 --- a/src/Payment.php +++ b/src/Payment.php @@ -14,7 +14,7 @@ class Payment extends Tp\Payment protected $linkGenerator; public function __construct( - MerchantConfig $config = NULL, + MerchantConfig $config, Nette\Application\LinkGenerator $linkGenerator ) { parent::__construct($config); diff --git a/src/PermanentPayment.php b/src/PermanentPayment.php index 92a89be..3a87026 100644 --- a/src/PermanentPayment.php +++ b/src/PermanentPayment.php @@ -28,7 +28,7 @@ public function getMerchantData() : string throw new PermanentPaymentException('Property merchantData was not set', PermanentPaymentException::UNDEFINED_PROPERTY); } - return parent::getMerchantData(); + return $this->merchantData; } public function getDescription() : string @@ -37,7 +37,7 @@ public function getDescription() : string throw new PermanentPaymentException('Property description was not set', PermanentPaymentException::UNDEFINED_PROPERTY); } - return parent::getDescription(); + return $this->description; } public function getReturnUrl() : string @@ -46,7 +46,7 @@ public function getReturnUrl() : string throw new PermanentPaymentException('Property returnUrl was not set', PermanentPaymentException::UNDEFINED_PROPERTY); } - return parent::getReturnUrl(); + return $this->returnUrl; } public function setReturnUrl(string $returnUrl, array $params = []) : void diff --git a/src/ReturnedPayment.php b/src/ReturnedPayment.php index 05997f6..d901efa 100644 --- a/src/ReturnedPayment.php +++ b/src/ReturnedPayment.php @@ -18,7 +18,7 @@ class ReturnedPayment extends Tp\ReturnedPayment protected $linkGenerator; public function __construct( - MerchantConfig $config = NULL, + MerchantConfig $config, Nette\Http\IRequest $request, Nette\Application\LinkGenerator $linkGenerator ) { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9b88b6d..eb7ecbc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,7 +3,7 @@ require dirname(__DIR__) . '/vendor/autoload.php'; -if (!class_exists('Tester\Assert')) { +if ( !class_exists('Tester\Assert')) { echo "Install Nette Tester using `composer update --dev`\n"; exit(1); } @@ -11,15 +11,18 @@ Tester\Environment::setup(); $configurator = new Nette\Configurator; -$configurator->setDebugMode(!FALSE); -Tracy\Debugger::$logDirectory = __DIR__ . '/../log'; -//$configurator->enableDebugger(__DIR__ . '/../log'); -$configurator->setTempDirectory(__DIR__ . '/../temp'); +$configurator->setDebugMode(FALSE); + +Tracy\Debugger::$logDirectory = dirname(__DIR__) . '/log'; +//$configurator->enableDebugger(dirname(__DIR__) . '/log'); +$configurator->setTempDirectory(dirname(__DIR__) . '/temp'); $configurator->createRobotLoader() ->addDirectory(__DIR__ . '/../src') - ->addDirectory(__DIR__ . '/app') + ->addDirectory(__DIR__ . '/src') ->register(); +@mkdir(Tracy\Debugger::$logDirectory, 0775); + $configurator->addConfig(__DIR__ . '/config/config.neon'); $configurator->addConfig(__DIR__ . '/config/config.local.neon'); return $configurator->createContainer(); diff --git a/tests/TpPaymentTest.phpt b/tests/cases/TpPaymentTest.phpt similarity index 90% rename from tests/TpPaymentTest.phpt rename to tests/cases/TpPaymentTest.phpt index e633593..f19bfd2 100644 --- a/tests/TpPaymentTest.phpt +++ b/tests/cases/TpPaymentTest.phpt @@ -1,14 +1,14 @@ createConfig(), $this->linkGenerator); - $payment->setMethodId('21'); - $payment->setValue('2000.23'); + $payment->setMethodId(21); + $payment->setValue(2000.23); $payment->setCurrency('CZK'); $payment->setMerchantData('24'); $payment->setMerchantSpecificSymbol('10'); @@ -72,7 +72,7 @@ class TpPaymentTest extends Tester\TestCase { $payment = $this->createPayment(); - $payment->setValue('23.79'); + $payment->setValue(23.79); $queryArgs = $payment->getArgs(); $queryArgs['signature'] = $payment->getSignature(); diff --git a/tests/config/config.neon b/tests/config/config.neon index 243ea86..aa12a57 100644 --- a/tests/config/config.neon +++ b/tests/config/config.neon @@ -14,7 +14,7 @@ application: services: #routing.router: # autowired: no - router: Test\App\RouterFactory()::createRouter + router: Tests\Router\Factory()::createRouter #simpleRouter: Nette\Application\Routers\SimpleRouter url: Nette\Http\Url('http://localhost.tld/') application.linkGenerator: Nette\Application\LinkGenerator(@router, @url) diff --git a/tests/config/php-unix.ini b/tests/config/php-unix.ini new file mode 100644 index 0000000..e69de29 diff --git a/tests/config/phpstan.neon b/tests/config/phpstan.neon new file mode 100644 index 0000000..aab4991 --- /dev/null +++ b/tests/config/phpstan.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: [] diff --git a/tests/php-unix.ini b/tests/php-unix.ini deleted file mode 100644 index 3ba0ada..0000000 --- a/tests/php-unix.ini +++ /dev/null @@ -1 +0,0 @@ -bcmath.scale=4 diff --git a/tests/php.ini b/tests/php.ini deleted file mode 100644 index 2fddd32..0000000 --- a/tests/php.ini +++ /dev/null @@ -1,26 +0,0 @@ -extension_dir = "/usr/lib/php/modules/" - -extension = json.so -extension = pdo.so -extension = mysqlnd.so -extension = pdo_mysql.so -extension = sqlite3.so -extension = pdo_sqlite.so -extension = iconv.so -extension = xdebug.so - -date.timezone = Europe/Prague - -[xdebug] -zend_extension_ts = /usr/lib/php/modules/xdebug.so -xdebug.profiler_enable = 1 -xdebug.profiler_output_dir = /tmp/php_profile -xdebug.trace_output_dir = /tmp/php_trace -;xdebug.profiler_enable_trigger=1 -xdebug.remote_enable = 1 -xdebug.remote_mode = req -xdebug.remote_port = 9091 -xdebug.remote_host = 127.0.0.1 -xdebug.remote_connect_back = 0 - -zend_debugger.allow_hosts = localhost diff --git a/tests/src/Router/Factory.php b/tests/src/Router/Factory.php new file mode 100644 index 0000000..4cf319b --- /dev/null +++ b/tests/src/Router/Factory.php @@ -0,0 +1,21 @@ +[/[/]]', 'Homepage:default'); + + return $router; + } +} +