Skip to content
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
21 changes: 9 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ jobs:
max-parallel: 15
fail-fast: false
matrix:
coverage: [ 'none' ]
php-versions: [ '8.2', '8.3', '8.4', '8.5' ]
exclude:
- php-versions: '8.5'
include:
- php-versions: '8.5'
coverage: 'xdebug'

name: PHP ${{ matrix.php-versions }}
steps:
Expand All @@ -30,18 +24,21 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json, mbstring, xdebug
coverage: ${{ matrix.coverage }}
extensions: json, mbstring
coverage: pcov

- name: Install dependencies
run: composer update --no-interaction --prefer-dist --no-suggest --prefer-stable

- name: Lint composer.json
run: composer validate --strict

- name: Run Tests
run: vendor/bin/phpunit -v
- name: Run Tests with Coverage
run: vendor/bin/phpunit -v --coverage-text --coverage-clover=build/logs/clover.xml

- name: Upload coverage results
if: matrix.coverage != 'none'
- name: Upload coverage to Codecov
if: matrix.php-versions == '8.5'
uses: codecov/codecov-action@v5
with:
files: build/logs/clover.xml
fail_ci_if_error: false
68 changes: 68 additions & 0 deletions tests/ConfigRelativeUriTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace SocialiteProviders\Manager\Test;

use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\URL;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use SocialiteProviders\Manager\Config;

class ConfigRelativeUriTest extends TestCase
{
use \Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;

protected function setUp(): void
{
parent::setUp();

$urlGenerator = m::mock(\Illuminate\Contracts\Routing\UrlGenerator::class);
$this->urlGenerator = $urlGenerator;

// Set up a minimal Facade application container
$app = new \ArrayObject();
$app['url'] = $urlGenerator;

Facade::setFacadeApplication($app);
}

protected function tearDown(): void
{
Facade::clearResolvedInstances();
Facade::setFacadeApplication(null);
parent::tearDown();
}

/** @var \Mockery\MockInterface */
protected $urlGenerator;

/**
* @test
*/
public function it_resolves_relative_uri_using_url_to(): void
{
$this->urlGenerator
->shouldReceive('to')
->with('/callback/oauth')
->once()
->andReturn('http://localhost/callback/oauth');

$config = new Config('key', 'secret', '/callback/oauth');
$result = $config->get();

$this->assertSame('http://localhost/callback/oauth', $result['redirect']);
}

/**
* @test
*/
public function it_does_not_resolve_absolute_uri(): void
{
$this->urlGenerator->shouldNotReceive('to');

$config = new Config('key', 'secret', 'https://example.com/callback');
$result = $config->get();

$this->assertSame('https://example.com/callback', $result['redirect']);
}
}
122 changes: 121 additions & 1 deletion tests/ConfigRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,124 @@ public function it_retrieves_a_config_from_the_services_with_guzzle(): void
$this->assertSame($additionalConfigItem, $result['additional']);
$this->assertSame(['verify' => false], $result['guzzle']);
}

/**
* @test
*/
public function it_spoofs_config_when_running_in_console_and_config_is_empty(): void
{
\SocialiteProviders\Manager\Helpers\applicationStub::$runningInConsole = true;

$providerName = 'test';
self::$functions
->shouldReceive('config')
->with("services.{$providerName}")
->once()
->andReturn(null);
$configRetriever = new ConfigRetriever;

$result = $configRetriever->fromServices($providerName)->get();

$this->assertStringContainsString('_KEY', $result['client_id']);
$this->assertStringContainsString('_SECRET', $result['client_secret']);
$this->assertStringContainsString('_REDIRECT_URI', $result['redirect']);

\SocialiteProviders\Manager\Helpers\applicationStub::$runningInConsole = false;
}

/**
* @test
*/
public function it_returns_empty_array_for_missing_guzzle_config(): void
{
$providerName = 'test';
$config = [
'client_id' => 'key',
'client_secret' => 'secret',
'redirect' => 'uri',
];
self::$functions
->shouldReceive('config')
->with("services.{$providerName}")
->once()
->andReturn($config);
$configRetriever = new ConfigRetriever;

$result = $configRetriever->fromServices($providerName)->get();

$this->assertSame([], $result['guzzle']);
}

/**
* @test
*/
public function it_returns_null_for_missing_additional_config_key(): void
{
$providerName = 'test';
$config = [
'client_id' => 'key',
'client_secret' => 'secret',
'redirect' => 'uri',
];
self::$functions
->shouldReceive('config')
->with("services.{$providerName}")
->once()
->andReturn($config);
$configRetriever = new ConfigRetriever;

$result = $configRetriever->fromServices($providerName, ['tenant_id'])->get();

$this->assertNull($result['tenant_id']);
}

/**
* @test
*/
public function it_throws_for_missing_required_key(): void
{
$this->expectExceptionObject(new MissingConfigException('Missing services entry for test.client_secret'));

$providerName = 'test';
$config = [
'client_id' => 'key',
// client_secret is missing
'redirect' => 'uri',
];
self::$functions
->shouldReceive('config')
->with("services.{$providerName}")
->once()
->andReturn($config);
$configRetriever = new ConfigRetriever;

$configRetriever->fromServices($providerName)->get();
}

/**
* @test
*/
public function it_deduplicates_guzzle_in_additional_config_keys(): void
{
$providerName = 'test';
$config = [
'client_id' => 'key',
'client_secret' => 'secret',
'redirect' => 'uri',
'guzzle' => ['timeout' => 10],
];
self::$functions
->shouldReceive('config')
->with("services.{$providerName}")
->once()
->andReturn($config);
$configRetriever = new ConfigRetriever;

// Pass 'guzzle' explicitly — it should be deduplicated, not appear twice
$result = $configRetriever->fromServices($providerName, ['guzzle'])->get();

$this->assertSame(['timeout' => 10], $result['guzzle']);
}
}

namespace SocialiteProviders\Manager\Helpers;
Expand All @@ -132,8 +250,10 @@ function app()

class applicationStub
{
public static bool $runningInConsole = false;

public function runningInConsole(): bool
{
return false;
return self::$runningInConsole;
}
}
Loading