Category : testing

I have a problem with writing test for pdf generation. I have controller, service and repository, so service is injected in my controller and it’s calling method which is part of repository class. My test always returns error 500, probably because missing dependencies. Does anybody knows how to make test passing? This is the code: ..

I recently set up a new laravel 8 project and I want to run the tests in memory so I set the testing environment to the following: in phpunit.xml I set db <server name="DB_CONNECTION" value="sqlite"/> <server name="DB_DATABASE" value=":memory:"/> Database connection config/database.php ‘sqlite’ => [ ‘driver’ => ‘sqlite’, ‘url’ => env(‘DATABASE_URL’), ‘database’ => env(‘DB_DATABASE’, database_path(‘database.sqlite’)), ‘prefix’ ..

Il suffit de passer les paramètres en tableau. Exemple Policy: function attachModel($userRequest,$model1, $model2) {…} Test :$userRequest->can(‘attachModel’, [$model1,$model2]); Sourc..

I’m using Laravel 8 starting with cloned pingcrm and I’m tryng to write a test to update a contact, but seems it doesn’t work. Note that I made a change to the preset structure, now a contact is directly associated to the user that created it (not to the account) public function test_an_authorized_user_can_update_a_contact() { $this->user->contacts()->saveMany( .. Read more i’m new with the tests in Laravel (7.x), i create two feature tests, but the seconds don’t run with php artisan test my UserTest.php <?php namespace TestsFeature; use IlluminateFoundationTestingRefreshDatabase; use IlluminateFoundationTestingWithFaker; use TestsTestCase; class UserTest extends TestCase { /** * A basic feature test example. * @test * @return void */ public function an_authtenticated_user_can_get_own_details() { .. Read more I’m trying to write a Laravel test case where I need to make an HTTP Post Request to an external API. But my$this->postJson() keeps giving me an exception. Here’s an excerpt from my code: namespace TestsFeature; use TestsTestCase; class PurchaseTest extends TestCase { protected function setUp(): void { parent::setUp(); } public function testPurchasePolicy() { ..

After update to laravel 8 my passport tests fail because of factory and for all test I get message like this: BadMethodCallException: Call to undefined method LaravelPassportClient::factory() Sourc..

I’m using laravel eloquent to retrive data. When i run my test echo $company[‘name’]; like this it passes. Bun when i do this way echo$company->name; It gives me next error ErrorException: Trying to get property ‘name’ of non-object Sourc..

I have running project on localhost port 8000, and at first seek it opens home page (‘/’) perfecly but for some reasons <?php namespace TestsFeature; use IlluminateFoundationTestingRefreshDatabase; use TestsTestCase; class ExampleTest extends TestCase { /** * A basic test example. * * @return void */ public function testBasicTest() { $response =$this->get(‘/’); $response->assertStatus(200); } } .. Read more In my Laravel application I have a large number of MySql tables and a large number of phpunit tests to run. I run tests in memory using Sqlite and have a series of Seeder files to add data to the test database. For each test, Laravel creates a new database, runs the migrations and adds .. Read more api.php Route::middleware([‘trim.strings’, ‘other’])->group(function () { Route::put(‘a’, ‘[email protected]’); }) Kernel.php use AppHttpMiddlewareTrimStrings; protected$routeMiddleware = [ ‘trim.strings’ => TrimStrings::class, ‘other’ => Other::class ] Tests.php $this->withMiddleware() ->putJson(‘/a’, ‘{"a": [{"name" => "hi "}]’) ->assertStatus(200) ->assertJson([ ‘data’ => [ ‘a’ => [ [‘name’ => "hi"], ] ] ]); More Info: Laravel 7 Behavior: In the tests: Only middlewares other .. Read more I want to create with factory in the test case but i got a validation error it say The name has already been taken. But how? It always refresh database every time the test start run. The factory$factory->define(Companies::class, function (Faker $faker) { return [ ‘name’ =>$faker->unique()->company, ’email’ => $faker->email, ‘website’ =>$faker->url, ]; ..

I am creating a feature test for a Seminar. Everything is working great; I am trying to update my feature test to account for the seminar dates. Each Seminar can have one or many dates, so I am saving these values as a json field: // migration: … $table->json(‘dates’); … Here is what my Seminar .. Read more What I want to archive: I want to write a feature test using phpunit in Laravel. What does the controller I want to test do: It accepts uploads of test records to store it into a database. Each record consists of two files (xml, yml) with the same file name. Both files have to be .. Read more does not pass me the last test that compares the field just entered with the one sent because json I have the following fields: public function up() { Schema::create(‘polls’, function (Blueprint$table) { $table->id();$table->text(‘now’); $table->json(‘paramJson’);$table->enum(‘status’, [‘a’, ‘b’, ‘c’,’d’])->default(‘a’); }); } Poll model: protected $fillable=[ ‘now’, ‘paramJson’, ]; //to cast that column from JSON .. Read more I want to test that the Auth facade, when createUserProivder() method is called, returns my user provider. The problem is that with the following code, with the commented out part, the AuthManager is still the original, not the mock. With the uncommented part, I get an error: MockeryExceptionBadMethodCallException : Method Mockery_2_Illuminate_Auth_AuthManager::validate() does not exist on .. Read more I am trying to unit test the update function in a resource controller and I keep getting an error Call to undefined method assertStatus(). Here is my code:$this->withoutExceptionHandling(); $this->withoutExceptionHandling();$timesheet = factory(TimeSheets::class)->create(); $user = factory(UsersLoginModel::class)->create();$data = [ ‘subject’ => $this->faker->text, ‘subjectmatter’ =>$this->faker->text, ‘description’ => $this->faker->text, ]; ;$update = $this->actingAs($user)->json(‘PATCH’,’timesheets/update’.$timesheet->id,$data); $this->assertStatus(200); .. Read more I want mock laravel using PESTPHP Testing Framework on cache helper but when i try i got error like this Method Mockery_2_Illuminate_Cache_CacheManager::remember() does not exist on this mock object I want mock rememberForever method but why the remember method get mocked. I also try to change shouldReceive to another method but always remember method to .. Read more Lavarvel application running 7.10 I have a middleware that gets called on several routes. It check the user has the right relationships in place to get to the desired destination (that’s not important). I want a test that simply asserts that the user gets to the$next($request) in the middleware. I could of course just .. Read more I’m trying to add the code-coverage report feature for phpunit in Laravel 6 by following the tutorial https://coderwall.com/p/mxtqiw/add-code-coverage-report-to-laravel-project after adding the logging node on the phpunit.php file <?xml version=”1.0″ encoding=”UTF-8″?> <phpunit xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”./vendor/phpunit/phpunit/phpunit.xsd” backupGlobals=”false” backupStaticAttributes=”false” bootstrap=”vendor/autoload.php” colors=”true” convertErrorsToExceptions=”true” convertNoticesToExceptions=”true” convertWarningsToExceptions=”true” processIsolation=”false” stopOnFailure=”false”> … <logging> <log type=”coverage-html” target=”./report” lowUpperBound=”50″ highLowerBound=”80″ /> </logging> </phpunit> and running the .. Read more I user http tests to check the availability status of my pages. But I noticed that in tests one of my policy works differently. The controller method: public function show(Competition$competition) { $competition->load(‘registeredTeams.user’, ‘teams.user’); return view(‘competitions.show’, compact(‘competition’)); } The policy method applied to it: public function view(User$user, Competition $competition) { return$user->id === $competition->user_id; .. Read more Lets say I have this job: class ExampleJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; public$retryAfter = 300; public function handle() { // code } } I want to make sure that a job will be re-tried after x minutes when it fails. So, if I have the above job, how can I ..
I have a problem with routing and I’m near of freaking. In my API route file: Route::post(‘/role-user/attach/{user}’, ‘[email protected]’)->name(‘role.user.attach’); This is my Controller: public function attach(User $user) {$user->assignRole($this->roles); return response(”,200); } I making post request to the route by name in my test: (also tried path) public function roles_can_be_attached_to_a_user() {$user = factory(AppUser::class)->create(); $roles = .. Read more I have created a feature test to test the admin registration. When i run the testcases it gives me this error 1) TestsFeatureAdminRegisterTest::testValidRegistration The expected [AppEventsUserRegistered] event was not dispatched. Failed asserting that false is true. /var/www/html/gas-backend/tests/Feature/Admin/RegisterTest.php:85 Below i have stated the admin registration test file and user registered event file Admin/RegisterTest.php$response->assertStatus(201); $response->assertJson($expectedResponse); \$this->assertDatabaseHas(‘users’, ..