jaapoost jaapoost
2
I'm doing a feature test on a function that uses the Cache facade. public static function getMainCategories() { $cacheKey = self::CATEGORY_CACHE_KEY . '_main'; $fromCache = Cache::get($cacheKey, false); if ($fromCache) { dd('Cach...
orest orest
1
I want to test whether some elements or text are present in the view when the view consists of Vue components. I can't use assertSee because all the thing that i want to test are within the Vue component What i've been doing in the controller is the...
tykus replied
Solved
Synchro Synchro
3
Say I have a test that fails like this: Expected status code 201 but received 422. Failed asserting that 201 is identical to 422. vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:186 tests/Unit/ProductTest.php:57 That tells me where...
cosmic_learning cosmic_learning
4
I have a service class VideosHandler in which constructor I get database records for further usage in this service class. Then, I have a VideosImporter command where I pass the service as a dependency in the constructor: public function __constru...
__gregory __gregory
3
Hello, I'm wondering what's the difference between $this->actingAs($user) and Auth::login($user) in tests. I want to test if Laravel shows a 404 page if a user is not allowed to see a resource. When I use Auth::login($user) it works: /**...
hrvali hrvali
4
Consider the following relationship: class Team extends Model { use HasFactory; protected $fillable = ['name']; public function members() { return $this->hasMany(User::class); } } When I write: $t = Team::factory()-&...
tykus replied
Solved
ShaneTurner ShaneTurner
19
I can't get tests to run from a testing environment, they always seem to run using the 'local' variables set in the .env file rather than the settings in phpunit.xml I've run. php artisan config:clear my phpunit.xml <?xml version="1.0"...
Spot-up Spot-up
3
Project use MySQL. Migration: { Schema::table('posts', function (Blueprint $table) { // $table->string('artist')->nullable()->change(); }); } Table 'posts': DROP TABLE IF EXISTS `posts`; CREAT...
bhosted bhosted
8
Hi, I'm trying to setup my first phpunit test in Laravel 8 and phpStorm. The first test already results in an error I can't fix: Illuminate\Contracts\Container\BindingResolutionException : Target class [translator] does not exist. The class being tes...
bhosted replied
Solved
agustavo87 agustavo87
6
I have a Source Model, and a User Model. They have a One to Many Relationship. The User hasMany Sources. I have implemented the sources() and user() method respectively. In testing i try to do the following: $user = User::find(1); Source::factory()...
kenprogrammer kenprogrammer
0
Consider a Laravel project with VueJS (Mono repo),which one would you prefer; browser testing with JS framework like Puppeteer or just Laravel's browser testing using dusk? NB: This can also be a SPA but VueJS installed manually WITHOUT scaffolding...
TobiasS TobiasS
2
Hi! I'm about to start writing front-end tests. I've watched the first episodes on laracasts regarding testing with cypress. What I do not know (since I haven't used the tools)... What is the big difference between Laravel Dusk and Cypress? Are there...
Sup guys, Why the migration in my test runs so slow?? abstract class TestCase extends BaseTestCase { use CreatesApplication, RefreshDatabase; protected function setUp(): void { RefreshDatabaseState::$migrated = false; pa...
trevorpan trevorpan
4
Hi, I decided to give larastan a shot to improve my code but there's a bunch of comments that I'd like to see what more experienced people have to say about it: 54 Method App\Http\Controllers\BidInvitationsController::store() should return Illumi...
automica automica
2
Hi All, I'm putting in some test coverage for a laravel 7 project and have a number of classes looking like below: <?php namespace App\Http; use App\Exceptions\AccountIsAlreadyActiveException; use App\Exceptions\CannotActivateUserException; use...
scwall scwall
2
Hello Here I am doing tasks in workers every 5 minutes, I would like to do some tests to see if it responds well. I try to mock guzzle but it doesn't work here's what I did: in test : $guzzleMock = Mockery::mock(Client::class); $guzzleMock -...
rudexpunx rudexpunx
5
I am sending notifications, both database and mail. For mail notifications I am using Mailables. Is it possible to Mail::assertSent(Mailable::class) while using notifications? I understand that when I fake Notification I can't get email, but even if...
KevDev KevDev
3
Hi I have a simple service that will fetch a data api and then loop it with generator. and i dont have any idea how will i do it. please see below some example of what class that i want to test. class Service { public function fetchData() { $res...
elbsurfer elbsurfer
7
Hello, I want to change the columns datatype from integer to decimal and have written a simple migration: Schema::table('products', function (Blueprint $table) { $table->decimal('tax_rate', 6, 2)->change(); }); The migration runs smoothly...
rstefanic rstefanic
8
In my .env file, I have a Postgres database setup. It looks like this: DB_CONNECTION=pgsql DB_HOST=postgres DB_PORT=5432 DB_DATABASE=my_database DB_USERNAME=user DB_PASSWORD=pw I have a phpunit.xml file which looks something like this: <server na...
aweishaar aweishaar
21
I'm trying to install Laravel Dusk following the documentation here: https://laravel.com/docs/5.4/dusk#installation When I run php artisan dusk, I get the following error: [email protected]:/var/www/html/testing$ php artisan dusk PHPUnit 5.7....
KevDev KevDev
2
Hi, do you guys do a unit test on your model class? like if you have a unit test on your service and repository class and you also have a feature test on your controller. do you still need test on your models?...
xtremer360 xtremer360
2
I'm trying to figure out what is the simplest test case to write to make the feature test pass and then write unit tests for the individual types of applicants. The test provided is one test that does pass however the applicant has additional statuse...
TobiasS TobiasS
3
Hi! I have added a column, and changed one columnname in a new migration. I'm running Postgres. For my test I use Sqlite. Schema::table('log_services', function (Blueprint $table) { $table->date('end')->nullable(); $tab...
gianmarx gianmarx
4
I'm at this lesson https://laracasts.com/series/build-a-laravel-app-with-tdd/episodes/16 minute 11:00 when i launch this test i get a different error than the course one public function test_a_user_can_update_a_project() { $this->signIn();...
lemmon replied
Solved
cosminc cosminc
8
Hello, I'm currently implementing an API (using Laravel 8.26.1) that has an endpoint which receives an array of e-mails and sends those e-mails asynchronously. Everything is working fine so far, but I'm willing to write a couple of unit tests for thi...
user2048 user2048
2
I'm developing tests for a Laravel 7.6 application. The application uses two databases, one at a time (two schemas on a single MySQL server). When a user logs in, they select one of the databases. They're authenticated against that database which is...
Jean_ali Jean_ali
8
I have this code to store a new post (it's work as testing manually) public function store(PostRequest $request, Post $post) { $data = $request->validated(); $request->image->store('post_images'); $data['image'] = $request-...
learningraph learningraph
5
Hi, I'm using Botman to provide a bot service in different languages and I end up testing all the conversations in the pattern below where I just copy paste the expected conversation and change the user language to simulate the different responses. W...
RichardJeffery RichardJeffery
5
I have a job that contacts a third party API and when it returns a 400 error, I want to retry the same job but send different data to the API. To do this I catch the 400 error and then dispatch the job with a second parameter: if($e->getCode() ===...
MikePage MikePage
1
I am new to testing. I am using Laravel Backpack I am trying to test a method in a controller that takes 3 inputs and adds them to the db but the test is being redirected to the logging page and I don't understand why. Here is the test public functi...
justaskkath justaskkath
3
Over the past 3 days, my website has been receiving a 500 error when loading. I have tried looking through error logs and testing but I can not seem to find the issue in the folder is it suggesting it can not find. Can someone help me? (My developer...
alexh alexh
3
To run my dusk tests I can use the command: php artisan dusk With this command dusks tests run with the correct test database and everything is working fine. But when I run the following command: php vendor/bin/phpunit to run all my tests - dusk uses...
wesleya wesleya
9
Is there a way to test that a job is dispatched with the correct parameters in Laravel phpunit? For example, I have a job that searches for images that should be deleted. For each image it finds, it will dispatch another job to delete the image (and...
cleverouge cleverouge
3
I am writing test but am unsure how I could get: $this->assertDatabaseHas('jobs', [ 'payload' => $email ]); to say payload contains $email? Hope someone can help?...
Create a New Discussion Button