Skip to content

Commit

Permalink
Merge branch 'unit_tests' into 'main'
Browse files Browse the repository at this point in the history
tests: init

See merge request ecphp/laravel-ecas!2
  • Loading branch information
drupol committed Apr 22, 2024
2 parents 14ccf1b + c5ef157 commit 29df155
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/vendor
composer.lock
.php_cs.cache
.phpunit.result.cache
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2019-2023, European Union.
Copyright (c) 2019-2024, European Union.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
26 changes: 20 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
],
"homepage": "https://github.com/ecphp/",
"require": {
"php": ">= 8.0.2",
"php": ">= 8.1",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"ecphp/ecas": "^3.0",
"ecphp/laravel-cas": "0.0.1",
Expand All @@ -24,19 +22,35 @@
"require-dev": {
"ecphp/php-conventions": "^1.0",
"guzzlehttp/guzzle": "^7.5",
"phpstan/phpstan-strict-rules": "^1.4"
"nyholm/psr7": "^1.5",
"orchestra/testbench": "^8.22",
"phpstan/phpstan-strict-rules": "^1.4",
"symfony/cache": "^6.2",
"symfony/psr-http-message-bridge": "^2.1"
},
"suggest": {},
"autoload": {
"psr-4": {
"EcPhp\\LaravelEcas\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"EcPhp\\LaravelEcas\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"ergebnis/composer-normalize": true,
"phpro/grumphp": true,
"ergebnis/composer-normalize": true
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
"providers": [
"EcPhp\\LaravelEcas\\Providers\\LaravelEcasProvider"
]
}
}
}
33 changes: 33 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
>
<testsuites>

<testsuite name="LaravelCas">
<directory suffix="Test.php">./tests</directory>
</testsuite>

</testsuites>
<coverage/>
<php>
<server name="APP_ENV" value="testing"/>
<server name="APP_KEY" value="O2lsv1gg9Guol7e4BlrxbCmM3aY5jzJt"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>

7 changes: 2 additions & 5 deletions src/Auth/EcasUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ final class EcasUserProvider implements UserProvider
{
public function __construct(
private CasUserProvider $casUserProvider
) {
}
) {}

public function retrieveByCredentials(array $credentials): ?Authenticatable

Check failure on line 25 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 8.3)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::retrieveByCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 25 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 8.1)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::retrieveByCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 25 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 8.2)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::retrieveByCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 25 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (macOS-latest, 8.3)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::retrieveByCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 25 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (macOS-latest, 8.2)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::retrieveByCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 25 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (macOS-latest, 8.1)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::retrieveByCredentials() has parameter $credentials with no value type specified in iterable type array.
{
Expand Down Expand Up @@ -49,9 +48,7 @@ public function retrieveCasUser(): ?Authenticatable
return $this->casUserProvider->retrieveCasUser();
}

public function updateRememberToken(Authenticatable $user, $token)
{
}
public function updateRememberToken(Authenticatable $user, $token) {}

public function validateCredentials(Authenticatable $user, array $credentials)

Check failure on line 53 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 8.3)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::validateCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 53 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 8.1)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::validateCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 53 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (ubuntu-latest, 8.2)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::validateCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 53 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (macOS-latest, 8.3)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::validateCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 53 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (macOS-latest, 8.2)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::validateCredentials() has parameter $credentials with no value type specified in iterable type array.

Check failure on line 53 in src/Auth/EcasUserProvider.php

View workflow job for this annotation

GitHub Actions / Unit Tests (macOS-latest, 8.1)

Method EcPhp\LaravelEcas\Auth\EcasUserProvider::validateCredentials() has parameter $credentials with no value type specified in iterable type array.
{
Expand Down
8 changes: 2 additions & 6 deletions src/Auth/User/EcasUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

final class EcasUser implements Authenticatable
{
public function __construct(private CasUser $user)
{
}
public function __construct(private CasUser $user) {}

public function __toString(): string
{
Expand Down Expand Up @@ -173,7 +171,5 @@ public function getUserManager(): ?string
return $this->user->getAttribute('userManager');
}

public function setRememberToken($value): void
{
}
public function setRememberToken($value): void {}
}
47 changes: 47 additions & 0 deletions tests/Providers/LaravelCasProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

namespace EcPhp\LaravelEcas\Tests\Providers;

use GuzzleHttp\Client;
// use Illuminate\Support\ServiceProvider;
use loophp\psr17\Psr17;
use loophp\psr17\Psr17Interface;
use Nyholm\Psr7\Factory\Psr17Factory;
use Orchestra\Workbench\WorkbenchServiceProvider as ServiceProvider;
use Psr\Http\Client\ClientInterface;

class LaravelCasProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void {}

/**
* Register any application services.
*/
public function register(): void
{
$this->app->bind(ClientInterface::class, static function ($app, $params = []) {
if (!empty($params) && isset($params['handler'])) {
return new Client(['handler' => $params['handler']]);
}

return new Client();
});
$this->app->bind(Psr17Interface::class, static function ($app) {
$requestFactory = $responseFactory = $streamFactory = $uploadedFileFactory = $uriFactory = $serverRequestFactory = new Psr17Factory();

return new Psr17($requestFactory, $responseFactory, $streamFactory, $uploadedFileFactory, $uriFactory, $serverRequestFactory);
});
}
}
44 changes: 44 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

namespace EcPhp\LaravelEcas\Tests;

use EcPhp\LaravelCas\Providers\AppServiceProvider;
use EcPhp\LaravelEcas\Providers\LaravelEcasProvider;
use EcPhp\LaravelEcas\Tests\Providers\LaravelCasProvider;
use Orchestra\Testbench\TestCase as OrchestraTestCase;

use function dirname;

/**
* @internal
*/
abstract class TestCase extends OrchestraTestCase
{
/**
* Get application package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app)
{
$config = include dirname(__DIR__) . '/vendor/ecphp/laravel-cas/src/publishers/config/laravel-cas.php';
config(['laravel-cas' => $config]);

return [
AppServiceProvider::class,
LaravelCasProvider::class,
LaravelEcasProvider::class,
];
}
}
32 changes: 32 additions & 0 deletions tests/Unit/CasInterfaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

namespace Tests\Unit;

use EcPhp\CasLib\Contract\CasInterface;
use EcPhp\Ecas\Ecas;
use EcPhp\LaravelEcas\Tests\TestCase;

/**
* @internal
*
* @coversNothing
*/
final class CasInterfaceTest extends TestCase
{
private $response;

public function testIfEcas()
{
$casInterface = app()->make(CasInterface::class);
self::assertInstanceOf(Ecas::class, $casInterface);
}
}
41 changes: 41 additions & 0 deletions tests/Unit/ProxyCallBackControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

namespace Tests\Unit;

use EcPhp\LaravelEcas\Tests\TestCase;

/**
* @internal
*
* @coversNothing
*/
final class ProxyCallBackControllerTest extends TestCase
{
private $response;

protected function setUp(): void
{
parent::setUp();
$this->response = $this->get(route('laravel-cas-proxy-callback'));
}

public function testIfNotFalse()
{
self::assertNotFalse($this->response);
}

public function testIfXml()
{
$xml = '<?xml version="1.0" encoding="utf-8"?><proxySuccess xmlns="http://www.yale.edu/tp/casClient" />';
self::assertEquals($xml, $this->response->getContent());
}
}
43 changes: 43 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/ecphp
*/

declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

require __DIR__ . '/../vendor/autoload.php';
// require __DIR__ . '/helpers.php';
// require __DIR__ . '/../src/Helpers/helpers.php';

use Carbon\Carbon;

/*
|--------------------------------------------------------------------------
| Set The Default Timezone
|--------------------------------------------------------------------------
|
| Here we will set the default timezone for PHP. PHP is notoriously mean
| if the timezone is not explicitly set. This will be used by each of
| the PHP date and date-time functions throughout the application.
|
*/

date_default_timezone_set('UTC');

Carbon::setTestNow(Carbon::now());

0 comments on commit 29df155

Please sign in to comment.