Skip to content

Commit

Permalink
Add PhpStan, unify tests structure
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam committed Feb 5, 2018
1 parent 1b7a5e2 commit 33bd8e9
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
composer.lock
vendor

tests/php-unix.generated.ini
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion run-tests.sh → bin/run-tests.sh
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
16 changes: 8 additions & 8 deletions src/Helper/DataApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class DataApi
{
/**
* @var Tp\MerchantConfig
* @var Trejjam\ThePay\MerchantConfig
*/
protected $config;

Expand All @@ -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
{
Expand All @@ -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);
}
Expand All @@ -67,7 +67,7 @@ public function getPayments(
}

/**
* @param $type
* @param mixed $type
* @param array $paymentMethods
*
* @return Tp\DataApi\Responses\SetPaymentMethodsResponse
Expand Down
2 changes: 1 addition & 1 deletion src/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/PermanentPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ReturnedPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
15 changes: 9 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@

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);
}

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();
12 changes: 6 additions & 6 deletions tests/TpPaymentTest.phpt → tests/cases/TpPaymentTest.phpt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
declare(strict_types=1);

namespace Test;
namespace Tests;

use Nette;
use Tester;
use Tester\Assert;
use Trejjam;

$container = require_once __DIR__ . '/bootstrap.php';
$container = require_once dirname(__DIR__) . '/bootstrap.php';

class TpPaymentTest extends Tester\TestCase
{
Expand All @@ -34,7 +34,7 @@ class TpPaymentTest extends Tester\TestCase

protected function createConfig()
{
return new Trejjam\ThePay\MerchantConfig();
return new Trejjam\ThePay\MerchantConfig;
}


Expand All @@ -47,8 +47,8 @@ class TpPaymentTest extends Tester\TestCase
{
$payment = new Trejjam\ThePay\Payment($this->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');
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion tests/config/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Empty file added tests/config/php-unix.ini
Empty file.
2 changes: 2 additions & 0 deletions tests/config/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors: []
1 change: 0 additions & 1 deletion tests/php-unix.ini

This file was deleted.

26 changes: 0 additions & 26 deletions tests/php.ini

This file was deleted.

21 changes: 21 additions & 0 deletions tests/src/Router/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);

namespace Tests\Router;

use Nette\Application\Routers\RouteList;
use Nette\Application\Routers\Route;

class Factory
{
public static function createRouter() : RouteList
{
$router = new RouteList;
$router[] = $front = new RouteList;

$front[] = new Route('<presenter>[/<action>[/<id>]]', 'Homepage:default');

return $router;
}
}

0 comments on commit 33bd8e9

Please sign in to comment.