Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doUnsafeAction of Notify Controller, could not resolve gateway_name parameter defined on route #54

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
/.editorconfig export-ignore
55 changes: 55 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Tests

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [7.3, 7.4]
laravel: [5.8, 6.*, 7.*, 8.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 5.8
testbench: 3.8.*
- laravel: 6.*
testbench: 4.*
- laravel: 7.*
testbench: 5.*
guzzle7-adapter: ^0.1
- laravel: 8.*
testbench: 6.*
guzzle7-adapter: ^0.1

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
if: matrix.guzzle7-adapter
run: composer require "php-http/guzzle7-adapter:${{ matrix.guzzle7-adapter }}" --no-interaction --no-update

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: ./bin/phpunit
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea
.phpunit.result.cache
build
composer.lock
coverage
docs
phpunit.xml
vendor
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,24 @@
"autoload": {
"psr-0": { "Payum\\LaravelPackage": "src/" }
},
"autoload-dev": {
"psr-4": {
"Payum\\LaravelPackage\\Tests\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"bin-dir": "bin"
},
"require-dev": {
"orchestra/testbench": "~3.8.6|^4.8|^5.2|^6.0",
"phpunit/phpunit": "^7.5|^8.0|^9.0"
},
"scripts": {
"test": "bin/phpunit"
}
}
7 changes: 3 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
verbose="true"
>
<testsuites>
<testsuite name="Payum LaravelBundle Tests">
Expand All @@ -22,4 +21,4 @@
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
6 changes: 3 additions & 3 deletions src/Payum/LaravelPackage/Controller/NotifyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

class NotifyController extends PayumController
{
public function doUnsafeAction(Request $request)
public function doUnsafeAction($gateway_name)
{
$gateway = $this->getPayum()->getGateway($request->get('gateway_name'));
$gateway = $this->getPayum()->getGateway($gateway_name);

$gateway->execute(new Notify(null));

Expand All @@ -34,4 +34,4 @@ public function doAction($payumToken)

return \Response::make(null, 204);
}
}
}
43 changes: 43 additions & 0 deletions tests/NotifyControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Payum\LaravelPackage\Tests;

use Payum\Core\Exception\InvalidArgumentException;

class NotifyControllerTest extends TestCase
{
/** @test */
public function test_notify_unsafe_response_has_500_http_code_without_registered_gateway()
{
$gateway_name = 'not-exists';

$response = $this
->call('GET', route('payum_notify_do_unsafe', ['gateway_name' => $gateway_name]))
->assertStatus(500)
;

$exception = $response->exception;
$expectedMessageException = sprintf('Gateway "%s" does not exist.', $gateway_name);
$this->assertEquals(get_class($exception), InvalidArgumentException::class);
$this->assertEquals($exception->getMessage(), $expectedMessageException);
}


/** @test */
public function test_notify_unsafe_payum_receive_right_gateway_name_parameter()
{
$gateway_name = 'not-exists';

$this
->mock('payum', function($mock) use ($gateway_name){
$mock
->shouldReceive('getGateway')
->with($gateway_name)
->once();
});

$response = $this
->call('GET', route('payum_notify_do_unsafe', ['gateway_name' => $gateway_name]))
;
}
}
43 changes: 43 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Payum\LaravelPackage\Tests;

use Orchestra\Testbench\TestCase as Orchestra;
use Payum\Core\PayumBuilder;
use Payum\LaravelPackage\PayumServiceProvider;

class TestCase extends Orchestra
{
public function setUp(): void
{
parent::setUp();

/** @var PayumBuilder $payumBuilder */
$payumBuilder = app('payum.builder');
$payumBuilder = $payumBuilder->addDefaultStorages();
$this->instance('payum.builder', $payumBuilder);
$this->swap('payum', $payumBuilder->getPayum());
}

protected function getPackageProviders($app)
{
return [
PayumServiceProvider::class,
];
}

public function getEnvironmentSetUp($app)
{
$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);

/*
include_once __DIR__.'/../database/migrations/create_skeleton_table.php.stub';
(new \CreatePackageTable())->up();
*/
}
}