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

feat: application tests #177

Merged
merged 1 commit into from
Feb 26, 2025
Merged
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
19 changes: 19 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ jobs:
with:
files: ./coverage.xml

application:
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:10.5
env:
MARIADB_ROOT_PASSWORD: swagbraintree
MYSQL_DATABASE: swagbraintree_test
ports: ['3306:3306']
env:
DATABASE_URL: mysql://root:[email protected]:3306/swagbraintree
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-php
- name: Setup database
run: composer setup:test
- name: Run PHPUnit
run: composer phpunit:application -- --coverage-clover=coverage.xml

infection:
runs-on: ubuntu-latest
services:
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"braintree/braintree_php": "^6.19",
"braintree/braintree_php": "^6.21",
"doctrine/doctrine-bundle": "^2.10",
"doctrine/doctrine-migrations-bundle": "^3.2",
"doctrine/orm": "^3.2",
Expand Down Expand Up @@ -47,7 +47,8 @@
"autoload-dev": {
"psr-4": {
"Swag\\Braintree\\Tests\\Unit\\": "tests/unit/",
"Swag\\Braintree\\Tests\\Integration\\": "tests/integration/"
"Swag\\Braintree\\Tests\\Integration\\": "tests/integration/",
"Swag\\Braintree\\Tests\\Application\\": "tests/application/"
}
},
"replace": {
Expand Down Expand Up @@ -93,7 +94,8 @@
"bin/console doctrine:migrations:migrate --env=test -n"
],
"phpunit:unit": "@phpunit --testsuite=SwagBraintreeUnitTest",
"phpunit:integration": "@phpunit --testsuite=SwagBraintreeIntegrationTest"
"phpunit:integration": "@phpunit --testsuite=SwagBraintreeIntegrationTest",
"phpunit:application": "@phpunit --testsuite=SwagBraintreeApplicationTest"
},
"conflict": {
"symfony/symfony": "*"
Expand All @@ -113,6 +115,7 @@
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^11",
"symfony/browser-kit": "7.1.*",
"symfony/debug-bundle": "^7.1",
"symfony/stopwatch": "^7.1",
"symfony/web-profiler-bundle": "^7.1",
Expand Down
206 changes: 204 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions infection.json5
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"tmpDir": "var/cache",
"testFramework":"phpunit",
"testFrameworkOptions": "--testsuite=SwagBraintreeUnitTest",
"mutators": {
"@default": true,
"LessThan": {
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ parameters:
-
message: '#Multiple class/interface/trait is not allowed in single file#'
path: tests/unit
# PHPStan does not know of symfony browser component
-
message: '#Service "test\.client" is not registered in the container\.#'
path: tests

rules:
# rules from https://github.com/symplify/phpstan-rules
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<testsuite name="SwagBraintreeIntegrationTest">
<directory>tests/integration</directory>
</testsuite>

<testsuite name="SwagBraintreeApplicationTest">
<directory>tests/application</directory>
</testsuite>
</testsuites>

<extensions>
Expand Down
33 changes: 33 additions & 0 deletions src/Tests/Contract/ApplicationHelperTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace Swag\Braintree\Tests\Contract;

use Shopware\App\SDK\Shop\ShopInterface;
use Swag\Braintree\Framework\Request\ShopResolver;
use Symfony\Bundle\FrameworkBundle\Test\BrowserKitAssertionsTrait;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Cookie;

trait ApplicationHelperTrait
{
use BrowserKitAssertionsTrait;
use IntegrationHelperTrait;

protected static function createClientForShop(?ShopInterface $shop = null): AbstractBrowser
{
$client = static::getContainer()->get('test.client');

if (!$shop) {
$shop = static::createShop(persist: false);
}

$session = $client->getContainer()->get('session.factory')->createSession();
$session->set(ShopResolver::SHOP_ID, $shop->getShopId());
$session->save();
$session->start();

$client->getCookieJar()->set(new Cookie($session->getName(), $session->getId()));

return static::getClient($client);
}
}
Loading
Loading