Skip to content

Commit

Permalink
Merge pull request #1 from masitko/users
Browse files Browse the repository at this point in the history
Changes not related to users branch
  • Loading branch information
masitko authored Jun 1, 2024
2 parents a54503a + 3049ade commit 20814d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
22 changes: 22 additions & 0 deletions app/Http/Middleware/JsonResponseMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Http\Middleware;

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

class JsonResponseMiddleware
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
$request->headers->set('Accept', 'application/json');

return $next($request);
}
}
16 changes: 10 additions & 6 deletions tests/Unit/KayneWestDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
use App\Services\Quotes\KayneWestDriver;
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Facades\Cache;
use PHPUnit\Framework\MockObject\MockObject;

class KayneWestDriverTest extends TestCase
{
private KayneWestDriver | MockObject $driverMock;
public function setUp(): void {
$this->driverMock = $this->getMockBuilder(KayneWestDriver::class)->onlyMethods(['getRemoteQuotes'])->getMock();
}

public function test_get_quotes_should_try_to_get_quotes_from_cache_first(): void
{
$testQuotes = ['some_mocked_quotes'];
Expand All @@ -31,9 +37,8 @@ public function test_get_quotes_should_call_get_remote_quotes_if_cache_is_empty(
->with('quotes:kayne-west')
->andReturn(null);

$mock = $this->getMockBuilder(KayneWestDriver::class)->onlyMethods(['getRemoteQuotes'])->getMock();
$mock->expects($this->once())->method('getRemoteQuotes')->willReturn($testQuotes);
$result = $mock->getQuotes();
$this->driverMock->expects($this->once())->method('getRemoteQuotes')->willReturn($testQuotes);
$result = $this->driverMock->getQuotes();
$this->assertEquals($testQuotes, $result);
}

Expand All @@ -47,9 +52,8 @@ public function test_refresh_quotes_should_clear_quotes_from_cache_and_call_get_
->with('quotes:kayne-west')
->andReturn(true);

$mock = $this->getMockBuilder(KayneWestDriver::class)->onlyMethods(['getRemoteQuotes'])->getMock();
$mock->expects($this->once())->method('getRemoteQuotes')->willReturn($testQuotes);
$result = $mock->refreshQuotes();
$this->driverMock->expects($this->once())->method('getRemoteQuotes')->willReturn($testQuotes);
$result = $this->driverMock->refreshQuotes();
$this->assertEquals($testQuotes, $result);
}
}

0 comments on commit 20814d1

Please sign in to comment.