This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
beforeAll(function () { | |
// Executes first, before any of tests are run | |
// Eg. can be used to set up a testing database | |
}); | |
beforeEach(function () { | |
$this->bookRepository = new BookRepository(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
test('calculation', function () { | |
$result = 2 * 4; | |
expect($result) | |
->toBeInt() // Assert that the result is an integer | |
->toBe(8) // Assert that the result value is 8 | |
->not->toBeJson() // Using "not" modifier, asserting that the value isn't JSON | |
->not->toBe(5); // Another usage example of "not" modifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
test('user authorization', function () { | |
$auth = Mockery::mock(Auth::class); | |
$auth->shouldReceive('login'); | |
$auth->shouldReceive('authorize'); | |
$user = new UserRepository($auth); | |
expect($user->getAuthorized()) | |
->not->toBeEmpty(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
return new class extends Migration { | |
/** | |
* Run the migrations. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models; | |
use DateTimeInterface; | |
use Illuminate\Database\Eloquent\Factories\HasFactory; | |
use Illuminate\Database\Eloquent\Model; | |
/** | |
* App\Models\Book |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Database\Factories; | |
use App\Models\Book; | |
use Illuminate\Database\Eloquent\Factories\Factory; | |
/** | |
* @extends Factory<Book> | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Repositories; | |
use App\Models\Book; | |
use Illuminate\Database\Eloquent\Builder; | |
use Illuminate\Database\Eloquent\Collection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Repositories\BookRepository; | |
use Illuminate\Http\Request; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
class GetBooksController extends Controller | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Repositories\BookRepository; | |
use Illuminate\Http\Request; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
class GetBookByIsbnController extends Controller | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use App\Http\Controllers\GetBookByIsbnController; | |
use App\Http\Controllers\GetBooksController; | |
use Illuminate\Support\Facades\Route; | |
Route::get('/books', GetBooksController::class); | |
Route::get('/books/{isbn}', GetBookByIsbnController::class)->where('isbn', '[0-9]{10,13}'); |
OlderNewer