178 questions
0
votes
0
answers
45
views
How to make test for nova action class, which is called from user's view page?
On laravel 11 / nova 4 app I use action class, which is called from user's view page :
<?php
namespace App\Nova\Actions\User;
use App\Enums\UserBalanceActionTypeEnum;
use App\Library\Facades\...
0
votes
1
answer
84
views
Laravel HTTP Tests Routing Issue
I'm currently playing around with Laravel HTTP Feature Tests and I noticed when executing this code below:
Test.php
$this->actingUser($user)
->withHeaders([..])
->post(uri: '/api/foo/bar', ...
0
votes
0
answers
24
views
Why I got error making livewire test with bool field casted as enum?
In laravel 11 / livewire app I make test on a for with empty fields ?
#[Test]
public function on_new_article_got_validation_errors()
{
Livewire::test(ArticleEditor::class)
->set('...
1
vote
0
answers
36
views
How making tests to refer to middleware checks?
In laravel 11 / livewire app I make check if user has field status active
like having middleware CheckAuthPermissionsMiddleware.php in bootstrap/app.php file and condition in this
middleware :
if ...
0
votes
0
answers
218
views
Why Pest test on Laravel always fail (404) with valid URL?
I am adding a Pest test on Laravel 11 / Livewire 3 site
I created a new test file with command :
php artisan pest:test UsersTest
But adding any code to check existing page I got 404 error, like in ...
0
votes
0
answers
62
views
Unable to set HTTP status code for Policy response (Laravel)
I'm building an API with Laravel 10 and the JSON:API library. In this app, one of the main resources (Expense) has a to-one relationship with de User model. I decided to build this application ...
0
votes
1
answer
324
views
Laravel Collection macro not found in phpunit unit test?
I'm running a unit test in Laravel in phpunit and encountering this error where my Collection macro seemingly does not exist:
Method Illuminate\Support\Collection::getNext does not exist.
The code ...
2
votes
1
answer
303
views
Mockery Throws Error When Mocking Redis Connection: Mockery\Exception\BadMethodCallException
I have a command and some methods related to Redis connection are running in it. I want to test some of these methods and for this I want to mock the Redis connection. I approached it like this:
...
0
votes
1
answer
73
views
How to make custom exception in http unit test?
On laravel site in controller I catch custom KeyIsNotProvidedException Exception:
<?php
try {
$data = $this->method();
...
} catch (...
0
votes
1
answer
60
views
Laravel Package - Experiencing different data of model between in the test file and in the controller
I'm currently working on a laravel package that has route configuration below
Route::apiResource('companies', Controllers\CompanyController::class);
Route::apiResource('companies.addresses', ...
6
votes
1
answer
3k
views
Laravel phpunit tests Cannot find TestCase object on call stack
where running all test
php artisan test
everything work as expected and all tests runs
now , when i run signle test php artisan test --filter test_get_profile i get this wired error
An error occurred ...
1
vote
1
answer
777
views
Problem for run test on a Laravel package
I use a transformed Spatie/laravel-package-skeleton with my own ModuleServiceProvider and Module class for my system.
I didn't find suffisant ressource on the web for making my module system so maybe ...
1
vote
2
answers
1k
views
Counting the items in multiple sub-arrays in Laravel tests using assertJsonCount ()
For a Laravel Test of my Product API I am trying to check if the right number of prices are listed for all products. The API returns Json and the prices are items in the products.*.prices arrays.
I am ...
1
vote
1
answer
463
views
How can I make Laravel Dusk run seeders consistently?
I have been working on an issue with Laravel Dusk for a few hours and I cannot seem to find a solution.
To start, I have a few tests written for the home page of my application. These tests all ...
0
votes
1
answer
415
views
Encountered Method Illuminate\Auth\RequestGuard::attempt does not exist when running php artisan test
I have this code
public function it_can_change_password()
{
DB::beginTransaction();
$payloadForUser = [
"name" => "Name",
"...
0
votes
1
answer
796
views
Laravel PHPUnit testsuite class not found when used from vendor folder
I have added a Laravel package as local repository to my composer.json:
...
"repositories": [{
"type": "path",
"url": "../external-...
0
votes
1
answer
227
views
How do I repeat the same test on a feature test in laravel
This is my feature test
class CreateImageTest extends TestCase
{
private static function headers(){
....
}
/**
* @test
*
*/
public function no_api_key_404()
...
0
votes
1
answer
204
views
How to use Laravel AssertJson for testing a structured response
I have a signup API that returns a JSON response in this kind of format
{
"meta": {
//response metadata
},
"data": {
//user object
}
}
I want to ...
0
votes
1
answer
132
views
Why custom Exception was not catch by expectException method?
Making tests on laravel 9 site I try to catch custom Exception and looking at this
Undefind withoutExceptionHandling()
example I do in my tests
<?php
namespace Tests\Feature;
//use Illuminate\...
0
votes
0
answers
485
views
How to test Auth::once() in Laravel?
I'm using Auth:once() to authenticate users for a single request.
if (!Auth::once($this->only('email', 'password'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::...
0
votes
1
answer
213
views
How to test Laravel/Lumen API when retrieving the logged in user's ID in controller constructor?
I'm trying to test CRUD operations for my Lumen controllers. The constructor for each controller looks similar to this:
private $loggedInUserId;
public function __construct(Request $request) {
...
0
votes
0
answers
874
views
How to use MongoDB in Laravel Testing
I have laravel project, which I'm using two database: relational PostgresSQL and MongoDB.
I have to write feature tests to database but. I don't know how to create connection with mongo from laravel ...
0
votes
0
answers
54
views
Php unit cover files of composer package
i run tests in my laravel project but the test files are inside a composer package, here is my section of phpunit.xml
<testsuite name="Package Unit">
<directory suffix="Test....
0
votes
1
answer
769
views
How to assert If the signature is valid in the url - Laravel, TDD
I have a rating & review form which is used by the customers to submit their reviews. This form can be accessed using a url even if they are not signed-in to the platform.
I use signed routes to ...
0
votes
0
answers
147
views
How to mock laravel model relathipship?
I have a model that has a relationship with a View, that is complicate to popolate for make the feature test, but in the same time this is called from some component that are inside the controller ...
1
vote
1
answer
997
views
How with breeze to make feature test for forgot-password?
In laravel 9, breeze 1.11 app I want to make feature test for forgot-password functionality and in routes I found :
GET|HEAD
In laravel 9, breeze 1.11 app I want to make feature test for ...
4
votes
2
answers
2k
views
How to run tests in Laravel in parallel, while excluding some tests?
Both
php artisan test --parallel
and
php artisan test --exclude someGroup (this excludes tests which are annotated with someGroup)
work, but
php artisan test --parallel --exclude someGroup
doesn't
I ...
1
vote
1
answer
57
views
How to checks raised exceptions in phpunit tests?
In laravel 9.26.1 app I make tests with phpunit ^9.5.10 and I want to make checks on raised
exceptions on login with invalid credentials
In app/Http/Requests/Auth/LoginRequest.php I see :
public ...
2
votes
1
answer
743
views
Laravel Feature test: The user is not authenticated Failed asserting that false is true
I am trying to test the user registration, the test file came with laravel jetstream, I just added some additional fields, and I kept getting this error The user is not authenticated
Failed asserting ...
-1
votes
2
answers
1k
views
Why I got Unknown option "--env" error making tests?
Making tests ("phpunit/phpunit": "^9.5.10") for laravel ("laravel/framework": "^9.2") site I want to use .env.testing file
But I got error running command :
$ ...
0
votes
1
answer
1k
views
Failed asserting that a row in the table student.sections matches the attributes
Hello im new to PHPUnit with minimum knowledge in laravel.
Im trying to test this method that mass create student section
public function setStudentsSection(Request $request)
{
$...
2
votes
2
answers
607
views
Laravel remembers original response during http tests
Given the following pest test:
it('allows admins to create courses', function () {
$admin = User::factory()->admin()->create();
actingAs($admin);
$this->get('/courses')->...
1
vote
2
answers
2k
views
Laravel - Assert json array ids using wildcard
In my application I have a response like this:
{
"items": [
{
"id": 10,
"field": "foo"
},
{
"id": 20,
"...
-1
votes
1
answer
175
views
how to write mock test in laravel (IOC)
i dont know how to write mock test for my service
here is my compressContract Interface
interface compressContract
{
public function compress();
}
here is my ZipCompress class
<?php
namespace ...
1
vote
2
answers
688
views
laravel dusk:install file_get_contents(): SSL operation failed
Trying to install dusk on Laravel like this:
php7.4 artisan dusk:install
I get this error:
Dusk scaffolding installed successfully.
Downloading ChromeDriver binaries...
ErrorException
...
0
votes
1
answer
429
views
laravel 8 TDD $response->assertSessionHasNoErrors() is not working
The Illuminate\Testing\TestResponse::assertSessionHasNoErrors() isn't working as I would expect it to.
I have something like this in my code:
$response = $this->post('account/project/create', $...
0
votes
1
answer
501
views
How to assert array value but not strict?
How can we assert some of the array's property values which contain the expected object values?
My code below is working okay, but it checks all array property values. I want to ask if there's a way ...
1
vote
0
answers
130
views
laravel auth testing without Authenticatable User
I'm newbie on testing so I want to create a auth testing but in project I don't use laravel Models but I'm using own methods for auth because of started project too long ago. TestCase class has ...
3
votes
1
answer
9k
views
How do i get logged in user in another test case in laravel phpUnit testing?
When I check dd(\Auth()::check()); in testLoginTrue method in LoginTest case then it's returning true but when I use dd(\Auth()::check()); in testClientCreateFormDisplayed method in ClientTest then it'...
-1
votes
2
answers
935
views
Laravel test unable to find vendor class
I'm using laravel7 and codeception; and I have an Api test class called abcCest located inside test/api folder.
it looks like this:
<?php
use Tests\TestCase;
class abcCest extends TestCase
{}
...
1
vote
2
answers
1k
views
How to test array contains only objects with PHPUnit?
I'm looking for solution to test an array of objects with PHPUnit in my Laravel project.
This is my haystack array:
[
[
"id" => 10,
"name" => "Ten&...
0
votes
1
answer
568
views
Laravel request()->all() is empty in booted function when running tests
I created a trait sets up some Global Scopes based on the query parameters.
It does that by reading from the request() helper and reading the query parameters from the url. Below is the start of the ...
1
vote
1
answer
338
views
get data Factory Relationships for Laravel Testing
according laravel-database-testing
I have a factory relationship for testing data, my code like this
public function test_users_can_authenticate_using_the_login_screen()
{
$this->seed(...
1
vote
1
answer
295
views
Laravel 5.7 testing with RefreshDatabase trait throws ErrorException: Trying to access array offset on value of type int
so as I stated in the title, I am working on Laravel 5.7 project and am making first tests in this application (big system). We did not make any tests in here yet, so this problem is the first time ...
0
votes
1
answer
883
views
Testing insert methods by using factory make of Laravel with a PostgreSQL reserved id
Our Laravel app uses PostgreSQL and before we insert a register in a table we reserve the next valid id by calling PostgreSQL nextval function.
I want to test the insert method of UserRepository. As ...
0
votes
3
answers
3k
views
Login as multiple users during same test - Laravel and PestPHP
I'm trying to run a single test where multiple users are performing actions. There is either a bug in the actingAs() function, or I am completely missing something trivial. So here's the scenario. I ...
0
votes
2
answers
1k
views
How can I make fake records in a way that some of them have specific values in laravel?
I need to make some fake records in laravel testing in a way that some of them have specific values.
for example I need to create 20 fake records of countries name and want to name the two records &...
1
vote
0
answers
110
views
unitary test laravel and php
it´s my first time that I´m doing the unitary test in PHP and laravel and I have this problem:
Tests\Vocces\Company\Routes\CreateNewCompanyRouteTest > post create new company route
Expected ...
0
votes
1
answer
37
views
i made a testing class in laravel and using factory in it to make a user but it is giving error that "fname" doesn't have a default value
public function test_case1()
{
$user = factory(User::class)->create([
'fname' => "Testing",
'lname' => 'bot',
'email' => "testing_bot@apimio....
1
vote
1
answer
1k
views
Laravel testing url to resource in public directory
I'm using Laravel Dusk to test all links on a page, these links are PDF files that are that are copied from resources/docs to public/docs with laravel mix.
The problem is that trying to access the URL ...