Skip to content

Commit

Permalink
Merge pull request #45 from olssonm/dev
Browse files Browse the repository at this point in the history
Improve phpunit tests, minor refactoring
  • Loading branch information
olssonm authored Jun 16, 2020
2 parents ec40af3 + 5c86e26 commit f93d4fe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ composer.lock
src/config.php
.DS_Store
.phpunit.result.cache
phpunit-output
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: php

sudo: false
dist: xenial

os: linux

before_script:
- travis_retry composer self-update
Expand All @@ -9,7 +11,7 @@ before_script:
script:
- composer test

matrix:
jobs:
include:
- php: 7.1
env:
Expand Down
8 changes: 8 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@
<file>./tests/VeryBasicAuthTests.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory suffix=".blade.php">src</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
15 changes: 8 additions & 7 deletions src/Http/Middleware/VeryBasicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Olssonm\VeryBasicAuth\Http\Middleware;

use \Illuminate\Http\Request;
use \Symfony\Component\HttpFoundation\Response;

use Closure;

Expand All @@ -11,13 +12,13 @@ class VeryBasicAuth
/**
* Handle an incoming request
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param mixed $username
* @param mixed $password
* @return \Illuminate\Http\Response
* @param Request $request
* @param Closure $next
* @param mixed $username
* @param mixed $password
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle(Request $request, Closure $next, $username = null, $password = null)
public function handle(Request $request, Closure $next, $username = null, $password = null): Response
{
$active = (count(array_intersect([
'*',
Expand All @@ -42,7 +43,7 @@ public function handle(Request $request, Closure $next, $username = null, $passw
/**
* Return a error response
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
private function deniedResponse(Request $request)
Expand Down
12 changes: 12 additions & 0 deletions tests/VeryBasicAuthTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public function test_config_file_is_installed()
$this->assertTrue(file_exists(__DIR__ . '/../src/config.php'));
}

/** @test */
public function test_view_exists()
{
$view = file_get_contents(__DIR__ . '/../src/resources/views/default.blade.php');

if (method_exists($this, 'assertStringContainsStringIgnoringCase')) {
$this->assertStringContainsStringIgnoringCase('This is the default view for the olssonm/l5-very-basic-auth-package', $view);
} else {
$this->assertContains('This is the default view for the olssonm/l5-very-basic-auth-package', $view);
}
}

/** @test */
public function test_very_basic_auth_authenticate_no_credentials()
{
Expand Down

0 comments on commit f93d4fe

Please sign in to comment.