Category : phpunit

I’m still new to laravel testing. I want to do testing on my store function. But I keep getting the error Call to The given data was invalid. the error. my store function is : public function store(Request $request) { $request->validate([ ‘companyLogo’ => ‘required’, ‘companyName’ => ‘required’, ‘companyDescription’ => ‘required’, ]); $path = $request->file(‘companyLogo’)->store(‘logo’, ‘s3’); ..

Read more

I’m still new to laravel and I have a simple app and aSo I have a route that will store data based on the request in my controller. public funtion store(Request $request, $id){ if ($request->has(‘work_experiences’)) { WorkExperience::create([ ‘user_id’ => $user->id, ‘position’ => $request->work_experiences[‘position’], ‘company’ => $request->work_experiences[‘company’], ‘start_date’ => $request->work_experiences[‘start_date’], ‘end_date’ => $request->work_experiences[‘end_date’], ]); } if ..

Read more

I’m learning tests with PHP, i need to test a function that returns a view and i still can’t find a way to do this. For example the function bellow: public function getEmails(){ if (Defender::hasPermission("users")) { $index = $this->diretorioPrincipal; $route = $this->nameView; return view("{$this->index}.{$this->nameView}.emails", compact(‘index’, ‘route’)); } else { return redirect("/{$this->index}"); } } Can somebody ..

Read more

In my controller I am using a class like so: public function book($id, CalRequest $request) { $event = $this->repo->find($id); (new CalAuthorisation()) ->setEvent($event) ->canBook(); $this->booking->book($event, $request); } I’m mocking a class like below: $auth = Mockery::mock(CalAuthorisation::class)->makePartial(); $this->app->bind(CalAuthorisation::class, function() use ($auth) { return $auth; }); $auth->shouldReceive(‘canBook’)->once()->andReturn(true); However, if I dd within the canBook() function I still get ..

Read more

Consider the following config file, appconfigsomeFeature.php <?php /* SomeFeature toggles */ return [ ‘product_listing’ => [ ‘full_listing_enabled’ => env(‘FEATURE_PRODUCT_LISTING’, false), ‘test_mode’ => env(‘FEATURE_PRODUCT_LISTING_TEST_MODE’, false), ] ]; In the code, (a queued job), variable is called as follows: if (config(‘features.product_listing.full_listing_enabled’)) { // do something .. } For some reason values are not picked up when set ..

Read more

I Have Test class that extends TestCase, and i want to setup $base_route, $base_model early, this is my Test class looks like,.. <?php namespace TestsFeature; use IlluminateFoundationTestingRefreshDatabase; use TestsTestCase; class OperatorTest extends TestCase { $this->setBaseRoute(‘master.operator’); $this->setBaseModel(‘AppModelsOperator’); } This is TestCase.php <?php namespace Tests; use IlluminateFoundationTestingRefreshDatabase; use IlluminateFoundationTestingTestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { ..

Read more

I write a code using laravel 8 and i want to create CRUD Testing for all model so i can called it in every test case, for example I Have Operator Test that extends TestCase (crud testing master) ref : crud test, this is my Operator Test looks like,.. <?php namespace TestsFeature; use IlluminateFoundationTestingRefreshDatabase; use ..

Read more

Using php 8.0.2 and Laravel 8.37.0, I am running tests where for every test the database data should be refreshed, since there is conflicting data per test (due to unique constraints). using the in-memory database with SQLite, this works, but when I switch to MySQL (v8.0.23) I get the next error: 1) TestsFeatureControllersAuthControllerTest::testSuccessLogin PDOException: There ..

Read more

I have a Laravel 8 with livewire installed I have a blade file under resources/concerts/show.blade.php and my routes Route::get(‘concerts/{concert}’, ‘whatever’); Concerts show test $concert = Concert::create([ ‘title’ => ‘The Red Chord’, ‘subtitle’ => ‘yeah’, ‘date’ => Carbon::parse(‘December 13, 2016, 8:00pm’), ‘ticket_price’ => 3250, ‘venue’ => ‘The Mosh Pit’, ‘venue_address’ => ‘123 Example Lane’, ‘city’ => ..

Read more

This might be a long shot, in the dark, but I’m currently trying to run a set of tests on Bitbucket. It is a feature-test for logging into the application and it fails miserably. I get this as part response-content: #content: """ <!DOCTYPE html>n <html>n <head>n <meta charset="UTF-8" />n <meta http-equiv="refresh" content="0;url=’https://subdomain.http://localhost/admin/login’" />n n <title>Redirecting ..

Read more

I have my Laravel application in a subdirectory as such: https://www.example.com/subdirectory/api This means that requests to the API are done as such: // GET https://www.example.com/subdirectory/api/user/1 // Meanwhile in api.php Route::get(‘/user/{id}’, ‘[email protected]’); And return as expected. However when trying to set up feature tests of these endpoints using the $this->get() methods on the testcase my routes ..

Read more

I have the following Json array: [{"ticket_id":131,"ticket_subject":"quasi","ticket_content":"However, everything is queer to-day.’ Just then she walked up towards it rather timidly, saying to.","ticket_name":"Prof. Ellen Yost Jr.","ticket_email":"[email protected]","ticket_status":0,"created_at":"2021-04-19 16:53:33","updated_at":"2021-04-19 16:53:33"}] I am trying to write a feature test to check that it has the key of ‘ticket_status’ and the corresponding value of 0. So far in my tests ..

Read more

I have a problem with PhpUnit. I try to learning about this but i receibed this message always try to execute a united test: C:wampwwwcovermanagertest>phpunit tests/Feature/Http/Controllers/Auth/LoginControllerTest.php Fatal error: Uncaught TypeError: Argument 2 passed to PHPUnitRunnerBaseTestRunner::getTest() must be of the type string, array given, called in C:UsersJoseAppDataRoamingComposervendorphpunitphpunitsrcTextUICommand.php on line 120 and defined in C:wampwwwcovermanagertestvendorphpunitphpunitsrcRunnerBaseTestRunner.php:86 Stack trace: ..

Read more

I’m trying to write a test but I can’t authenticate with a fake test user, I’m using mongodb, jenssegers/laravel-mongodb and jwt-auth this is the factory I’ve created <?php /** @var IlluminateDatabaseEloquentFactory $factory */ use FakerGenerator as Faker; use IlluminateSupportStr; $factory->define(AppUser::class, function (Faker $faker) { return [ ‘username’ => $faker->name(), ‘password’ => $faker->password() ]; }); phpunit.xml ..

Read more

I’m testing an api that uses jwt and this is a test that works: public function test_get_customer() { $url = env(‘APP_URL’).’:8000/customer/’.env(‘TEST_USER_TO_GET’).’?token=’.env(‘TEST_TOKEN’); $response = $this->json(‘GET’, $url); $response ->assertStatus(200) ->assertJson([ ‘meta’=>[ ‘success’=>true ] ]); } I this test I have to get a token, then edit .env.testing and update the TEST_TOKEN variable and the ‘TEST_USER_TO_GET’ variable, in ..

Read more

Running Laravel 7 with the job queue using the ‘database’ driver. There is a call from the frontend to an API that dispatches a job and immediately returns a response with the status (queued). This works fine when called from the frontend Javascript. Trying to test this same endpoint with PHPUnit, with a test that ..

Read more

I’m trying to unit testing a service that handles the registration of a user in Laravel. This is the service: public function completeRegistration(Collection $data) { $code = $data->get(‘code’); $registerToken = $this->fetchRegisterToken($code); DB::beginTransaction(); $registerToken->update([‘used_at’ => Carbon::now()]); $user = $this->userRepository->update($data, $registerToken->user); $token = $user->createToken(self::DEFAULT_TOKEN_NAME); DB::commit(); return [ ‘user’ => $user, ‘token’ => $token->plainTextToken, ]; } Where the ..

Read more