Skip to content

Commit

Permalink
Merge pull request #123 from trikoder/test-maintenance
Browse files Browse the repository at this point in the history
Various test related maintenance
  • Loading branch information
spideyfusion authored Nov 28, 2019
2 parents 60431d4 + 65afb7f commit 7e507e8
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 38 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
dist: bionic

sudo: required

language: bash

services:
- docker

addons:
apt:
packages:
- docker-ce

env:
# PHP 7.2
- PHP_VERSION=7.2 PSR_HTTP_PROVIDER=nyholm SYMFONY_VERSION=3.4.*
Expand Down
4 changes: 1 addition & 3 deletions DBAL/Type/ImplodedArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ private function assertValueCanBeImploded($value): void
return;
}

throw new InvalidArgumentException(
sprintf('The value of \'%s\' type cannot be imploded.', \gettype($value))
);
throw new InvalidArgumentException(sprintf('The value of \'%s\' type cannot be imploded.', \gettype($value)));
}

abstract protected function convertDatabaseValues(array $values): array;
Expand Down
7 changes: 1 addition & 6 deletions DependencyInjection/TrikoderOAuth2Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ private function assertRequiredBundlesAreEnabled(ContainerBuilder $container): v

foreach ($requiredBundles as $bundleAlias => $requiredBundle) {
if (!$container->hasExtension($bundleAlias)) {
throw new LogicException(
sprintf(
'Bundle \'%s\' needs to be enabled in your application kernel.',
$requiredBundle
)
);
throw new LogicException(sprintf('Bundle \'%s\' needs to be enabled in your application kernel.', $requiredBundle));
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions Model/Grant.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class Grant
public function __construct(string $grant)
{
if (!OAuth2Grants::has($grant)) {
throw new RuntimeException(
sprintf('The \'%s\' grant is not supported.', $grant)
);
throw new RuntimeException(sprintf('The \'%s\' grant is not supported.', $grant));
}

$this->grant = $grant;
Expand Down
4 changes: 1 addition & 3 deletions Model/RedirectUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class RedirectUri
public function __construct(string $redirectUri)
{
if (!filter_var($redirectUri, FILTER_VALIDATE_URL)) {
throw new RuntimeException(
sprintf('The \'%s\' string is not a valid URI.', $redirectUri)
);
throw new RuntimeException(sprintf('The \'%s\' string is not a valid URI.', $redirectUri));
}

$this->redirectUri = $redirectUri;
Expand Down
7 changes: 1 addition & 6 deletions Security/Authentication/Provider/OAuth2Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ public function __construct(UserProviderInterface $userProvider, ResourceServer
public function authenticate(TokenInterface $token)
{
if (!$this->supports($token)) {
throw new RuntimeException(
sprintf(
'This authentication provider can only handle tokes of type \'%s\'.',
OAuth2Token::class
)
);
throw new RuntimeException(sprintf('This authentication provider can only handle tokes of type \'%s\'.', OAuth2Token::class));
}

try {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/AbstractIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use League\OAuth2\Server\ResourceServer;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Trikoder\Bundle\OAuth2Bundle\Converter\ScopeConverter;
Expand Down
38 changes: 38 additions & 0 deletions Tests/Support/SqlitePlatform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Trikoder\Bundle\OAuth2Bundle\Tests\Support;

use Doctrine\DBAL\Platforms\SqlitePlatform as DoctrineSqlitePlatform;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;

/**
* @TODO Remove this once this issue is resolved: https://github.com/doctrine/orm/issues/7930
*/
final class SqlitePlatform extends DoctrineSqlitePlatform
{
/**
* {@inheritdoc}
*/
public function supportsForeignKeyConstraints()
{
return true;
}

/**
* {@inheritdoc}
*/
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
{
return 'SELECT 1';
}

/**
* {@inheritdoc}
*/
public function getDropForeignKeySQL($foreignKey, $table)
{
return 'SELECT 1';
}
}
20 changes: 14 additions & 6 deletions Tests/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Trikoder\Bundle\OAuth2Bundle\Manager\ScopeManagerInterface;
use Trikoder\Bundle\OAuth2Bundle\Tests\Fixtures\FixtureFactory;
use Trikoder\Bundle\OAuth2Bundle\Tests\Fixtures\SecurityTestController;
use Trikoder\Bundle\OAuth2Bundle\Tests\Support\SqlitePlatform;
use Zend\Diactoros as ZendFramework;

final class TestKernel extends Kernel implements CompilerPassInterface
Expand Down Expand Up @@ -131,6 +132,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa
'charset' => 'utf8mb4',
'utf8mb4_unicode_ci' => 'utf8mb4_unicode_ci',
],
'platform_service' => SqlitePlatform::class,
],
'orm' => null,
]);
Expand Down Expand Up @@ -187,6 +189,7 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa

$this->configureControllers($container);
$this->configurePsrHttpFactory($container);
$this->configureDatabaseServices($container);
}

private function exposeManagerServices(ContainerBuilder $container): void
Expand Down Expand Up @@ -253,9 +256,7 @@ private function configurePsrHttpFactory(ContainerBuilder $container): void
$responseFactory = Nyholm\Psr17Factory::class;
break;
default:
throw new LogicException(
sprintf('PSR HTTP factory provider \'%s\' is not supported.', $this->psrHttpProvider)
);
throw new LogicException(sprintf('PSR HTTP factory provider \'%s\' is not supported.', $this->psrHttpProvider));
}

$container->addDefinitions([
Expand All @@ -282,6 +283,15 @@ private function configureControllers(ContainerBuilder $container): void
;
}

private function configureDatabaseServices(ContainerBuilder $container): void
{
$container
->register(SqlitePlatform::class)
->setAutoconfigured(true)
->setAutowired(true)
;
}

private function determinePsrHttpFactory(): void
{
$psrHttpProvider = getenv('PSR_HTTP_PROVIDER');
Expand All @@ -294,9 +304,7 @@ private function determinePsrHttpFactory(): void
$this->psrHttpProvider = self::PSR_HTTP_PROVIDER_NYHOLM;
break;
default:
throw new LogicException(
sprintf('PSR HTTP factory provider \'%s\' is not supported.', $psrHttpProvider)
);
throw new LogicException(sprintf('PSR HTTP factory provider \'%s\' is not supported.', $psrHttpProvider));
}
}

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"require-dev": {
"ext-timecop": "*",
"ext-xdebug": "*",
"friendsofphp/php-cs-fixer": "^2.15",
"friendsofphp/php-cs-fixer": "2.16.0",
"nyholm/psr7": "^1.1",
"phpunit/phpunit": "~8.2.0",
"phpunit/phpunit": "^8.4",
"symfony/browser-kit": "^3.4|^4.2",
"symfony/phpunit-bridge": "^3.4|^4.3",
"symfony/phpunit-bridge": "^3.4|^4.4",
"zendframework/zend-diactoros": "^2.1"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions dev/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN apk add --update --no-cache --virtual .build-deps \
xml \
zip \
&& pecl install \
xdebug \
xdebug-2.7.2 \
timecop-beta \
&& docker-php-ext-enable \
xdebug \
Expand All @@ -41,7 +41,7 @@ RUN apk add --update --no-cache \
RUN curl --show-error https://getcomposer.org/installer | php -- \
--install-dir=/app/bin \
--filename=composer \
--version=1.8.6
--version=1.9.1

# Create the user that's going to run our application
RUN useradd -ms /bin/sh app
Expand Down

0 comments on commit 7e507e8

Please sign in to comment.