Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AmonDeShir committed Nov 25, 2024
1 parent e62ec08 commit 7d0876b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
6 changes: 3 additions & 3 deletions tests/Feature/QuizTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function testAdminCanViewQuizzes(): void
->assertInertia(
fn(Assert $page) => $page
->component("Admin/Quizzes")
->has("quizzes", 2)
->has("quizzes.0.questions", 5)
->has("quizzes.1.questions", 5),
->has("quizzes.data", 2)
->has("quizzes.data.0.questions", 5)
->has("quizzes.data.1.questions", 5),
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/RegonRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Rules\Regon;
use Illuminate\Support\Facades\Lang;
use Tests\TestCase;
use PHPUnit\Framework\TestCase;

class RegonRuleTest extends TestCase
{
Expand Down
24 changes: 20 additions & 4 deletions tests/Unit/SortHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@
namespace Tests\Unit;

use App\Helpers\SortHelper;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Lang;
use Mockery;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response as Status;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Tests\TestCase;

class SortHelperTest extends TestCase
{
private Container $originalContainer;

/** @var MockInterface<Container> */
private MockInterface $container;

protected function setUp(): void
{
$this->originalContainer = Container::getInstance();
$this->container = Mockery::mock(Container::class);
Container::setInstance($this->container);
}

protected function tearDown(): void
{
Mockery::close();
restore_error_handler();
restore_exception_handler();
Container::setInstance($this->originalContainer);
}

public function testGetSortParametersReturnsDefaultValues(): void
Expand Down Expand Up @@ -83,8 +97,10 @@ public function testSortAppliesOrderBy(): void

public function testSortThrowsExceptionForUnsupportedField(): void
{
$this->container->shouldReceive("abort")
->with(Status::HTTP_BAD_REQUEST, "The field 'invalid_field' is not supported.", [])->andThrow(HttpException::class, Status::HTTP_BAD_REQUEST);

$this->expectException(HttpException::class);
$this->expectExceptionMessage("The field 'invalid_field' is not supported.");

Lang::shouldReceive("get")
->with("validation.sorting.unsupported_field", ["attribute" => "invalid_field"])
Expand Down

0 comments on commit 7d0876b

Please sign in to comment.