Skip to content

Commit

Permalink
CakePHP 4.0 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
hakito committed Jun 22, 2020
1 parent 052eff8 commit 6ca84b4
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 193 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -10,4 +10,5 @@ nbproject
.vscode/
vendor/
composer.lock
build/
build/
.phpunit.result.cache
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -4,7 +4,7 @@

# CakePHP-EpsBankTransfer-Plugin

CakePHP 3.x plugin
CakePHP 4.x plugin

# Installation

Expand Down Expand Up @@ -85,7 +85,7 @@ In your payment handling controller:

```php
// Load the component
public function initialize()
public function initialize(): void
{
parent::initialize();
$this->loadComponent('EpsBankTransfer.Eps');
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -23,14 +23,14 @@
}
},
"require": {
"cakephp/cakephp": "^3.8",
"cakephp/cakephp": "^4.0",
"hakito/php-stuzza-eps-banktransfer": "^2.0"
},
"extra": {
"installer-name": "EpsBankTransfer"
},
"require-dev": {
"phpunit/phpunit": "^6.0",
"phpunit/phpunit": "^8.5",
"hakito/publisher": "^1.3"
}
}
5 changes: 3 additions & 2 deletions src/Controller/Component/EpsComponent.php
Expand Up @@ -34,7 +34,7 @@ class EpsComponent extends Component
/** @var string */
private $EncryptionKey;

public function initialize(array $config)
public function initialize(array $config): void
{
parent::initialize($config);
$defaults = array(
Expand Down Expand Up @@ -229,8 +229,9 @@ public function HandleConfirmationUrl($eRemittanceIdentifier, $rawPostStream = '
$vitalityCheckCallbackWrapper,
$rawPostStream,
$outputStream);
} catch (Exception $ex) {
} catch (\Exception $ex) {
Log::error('Exception in SoCommunicator::HandleConfirmationUrl: ' . $ex->getMessage(), ['scope' => Plugin::$LogScope]);
throw $ex;
}

Log::info('END: Handle confirmation url', ['scope' => Plugin::$LogScope]);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/PaymentNotificationsController.php
Expand Up @@ -8,7 +8,7 @@
class PaymentNotificationsController extends AppController
{

public function initialize()
public function initialize(): void
{
parent::initialize();
$this->loadComponent('EpsBankTransfer.Eps', []);
Expand Down
1 change: 0 additions & 1 deletion src/Template/Layout/default.ctp

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions templates/layout/default.php
@@ -0,0 +1 @@
<?php echo $this->fetch('content');
71 changes: 36 additions & 35 deletions tests/TestApp/Application.php
@@ -1,35 +1,36 @@
<?php

namespace EpsBankTransfer\Test\TestApp;

use Cake\Http\BaseApplication;
use Cake\Routing\Middleware\RoutingMiddleware;

class Application extends BaseApplication
{

/**
* {@inheritDoc}
*/
public function bootstrap()
{
// Call parent to load bootstrap from files.
parent::bootstrap();

$this->addPlugin(\EpsBankTransfer\Plugin::class);
}

/**
* Setup the middleware queue your application will use.
*
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
* @return \Cake\Http\MiddlewareQueue The updated middleware queue.
*/
public function middleware($middlewareQueue)
{
$middlewareQueue
->add(new RoutingMiddleware($this));

return $middlewareQueue;
}
}
<?php

namespace EpsBankTransfer\Test\TestApp;

use Cake\Http\BaseApplication;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\RoutingMiddleware;

class Application extends BaseApplication
{

/**
* {@inheritDoc}
*/
public function bootstrap(): void
{
// Call parent to load bootstrap from files.
parent::bootstrap();

$this->addPlugin(\EpsBankTransfer\Plugin::class, ['routes' => true]);
}

/**
* Setup the middleware queue your application will use.
*
* @param MiddlewareQueue $middlewareQueue The middleware queue to setup.
* @return MiddlewareQueue The updated middleware queue.
*/
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
{
$middlewareQueue
->add(new RoutingMiddleware($this));

return $middlewareQueue;
}
}
68 changes: 45 additions & 23 deletions tests/TestCase/Controller/Component/EpsComponentTest.php
Expand Up @@ -2,40 +2,44 @@

namespace EpsBankTransfer\Test\TestCase\Controller\Component;

use at\externet\eps_bank_transfer;
use Cake\Cache\Cache;
use Cake\Controller\ComponentRegistry;
use Cake\Controller\Controller;
use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Event\EventList;
use Cake\TestSuite\TestCase;

use at\externet\eps_bank_transfer;

use Cake\Event\EventManager;
use EpsBankTransfer\Controller\Component\EpsComponent;
use EpsBankTransfer\Plugin;
use PHPUnit\Framework\MockObject\MockObject;

class EpsComponentTest extends TestCase
{

/** @var \EpsComponent eps component */
/** @var EpsComponent eps component */
public $Eps = null;

/** @var MockObject|Controller */
public $Controller = null;

/**
* setUp method
*
* @return void
*/
public function setUp()
public function setUp(): void
{
parent::setUp();

$this->loadPlugins([\EpsBankTransfer\Plugin::class => ['routes' => true]]);

date_default_timezone_set("UTC");

/** @var MockObject|Controller */
$this->Controller = $this->getMockBuilder('\Cake\Controller\Controller')
->setMethods(['redirect', 'afterEpsBankTransferNotification'])
->getMock();
$this->Controller->getEventManager()->setEventList(new EventList());

/** @var EventManager */
$eventmanager = $this->Controller->getEventManager();
$eventmanager->setEventList(new EventList());

$registry = new ComponentRegistry($this->Controller);
$this->Eps = new EpsComponent($registry);
Expand All @@ -53,7 +57,9 @@ public function setUp()
public function testGetBanksArray()
{
$expected = 'foo';
Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('TryGetBanksArray')
->will($this->returnValue($expected));
$actual = $this->Eps->GetBanksArray();
Expand All @@ -71,7 +77,9 @@ public function testGetBanksArrayCached()
public function testGetBanksArrayInvalidateCache()
{
$expected = 'Foo';
Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('TryGetBanksArray')
->will($this->returnValue($expected));
Cache::write(Plugin::$CacheKeyPrefix . 'BanksArray', 'Bar');
Expand All @@ -82,10 +90,12 @@ public function testGetBanksArrayInvalidateCache()
public function testGetBanksArrayEmptyResultNotCached()
{
$expected = 'Foo';
Plugin::GetSoCommunicator()->expects($this->at(0))
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->at(0))
->method('TryGetBanksArray')
->will($this->returnValue(null));
Plugin::GetSoCommunicator()->expects($this->at(1))
$communicator->expects($this->at(1))
->method('TryGetBanksArray')
->will($this->returnValue($expected));
$this->Eps->GetBanksArray();
Expand Down Expand Up @@ -123,7 +133,9 @@ public function testAddArticleIncreasesTotal()

public function testHandleConfirmationUrlCallsSoCommunicator()
{
Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('HandleConfirmationUrl')
->with($this->isType('callable'), $this->isType('callable'), 'foo', 'bar');
$this->Eps->HandleConfirmationUrl('remi', 'foo', 'bar');
Expand All @@ -142,7 +154,9 @@ public function testHandleConfirmationUrlFiresConfirmationEvent()
$wrapperCallback('raw', $bankConfirmationDetails);
};

Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('HandleConfirmationUrl')
->will($this->returnCallback($mockSoCommunicatorBehavior));

Expand All @@ -158,17 +172,19 @@ public function testHandleConfirmationUrlFiresConfirmationEvent()

public function testHandleConfirmationUrlChecksRemittanceIdentifier()
{
$remittanceIdentifier = 'remi';
$remittanceIdentifier = 'invalid_remittance_identifier';
$eRemittanceIdentifier = Plugin::Base64Encode(
\Cake\Utility\Security::encrypt($remittanceIdentifier, Configure::read('Security.salt')));
\Cake\Utility\Security::encrypt($remittanceIdentifier, Configure::read('EpsBankTransfer.encryptionKey')));
$bankConfirmationDetails = new eps_bank_transfer\BankConfirmationDetails(
new \SimpleXMLElement(eps_bank_transfer\BaseTest::GetEpsData('BankConfirmationDetailsWithoutSignature.xml')));

$mockSoCommunicatorBehavior = function( $wrapperCallback ) use ($bankConfirmationDetails) {
$wrapperCallback('raw', $bankConfirmationDetails);
};

Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('HandleConfirmationUrl')
->will($this->returnCallback($mockSoCommunicatorBehavior));

Expand All @@ -182,7 +198,9 @@ public function testHandleConfirmationUrlCallsFiresVitalityCheckEvent()
$vitalityCallback('raw', 'dummy vitality check details');
};

Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('HandleConfirmationUrl')
->with($this->isType('callable'), $this->isType('callable'), 'foo', 'bar')
->will($this->returnCallback($mockSoCommunicatorBehavior));
Expand All @@ -199,7 +217,9 @@ public function testHandleConfirmationUrlCallsFiresVitalityCheckEvent()
public function testPaymentRedirectErrorResponse()
{
$this->Eps->AddArticle('Foo', 3, "7");
Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('SendTransferInitiatorDetails')
->will($this->returnValue(eps_bank_transfer\BaseTest::GetEpsData('BankResponseDetails004.xml')));
$exception = null;
Expand All @@ -214,7 +234,9 @@ public function testPaymentRedirectErrorResponse()

public function testPaymentRedirectSuccess()
{
Plugin::GetSoCommunicator()->expects($this->once())
/** @var MockObject */
$communicator = Plugin::GetSoCommunicator();
$communicator->expects($this->once())
->method('SendTransferInitiatorDetails')
->will($this->returnValue(eps_bank_transfer\BaseTest::GetEpsData('BankResponseDetails000.xml')));

Expand Down
Expand Up @@ -3,16 +3,14 @@

use Cake\TestSuite\TestCase;
use Cake\TestSuite\IntegrationTestTrait;
use EpsBankTransfer\Test\TestApp\Application;

use EpsBankTransfer\PaymentNotificationsController;

class PaymentNotificationsControllerTest extends TestCase
{
use IntegrationTestTrait;

public function setUp()
public function setUp(): void
{
parent::setUp();
$this->disableErrorHandlerMiddleware();
$this->component = $this->getMockBuilder(\EpsBankTransfer\Controller\Component\EpsComponent::class)
->setMethods(['HandleConfirmationUrl'])
Expand Down

0 comments on commit 6ca84b4

Please sign in to comment.