• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

How to test laravel controller method?

phplaraveltestingdesign-patterns


PHP Snippet 1:

$language = Language::create($request->only(['name', 'code', 'flag']));

PHP Snippet 2:

$response = $this->postJson('/language', ['name' => 'Swedish', 'code' => 'swe', 'flag => 'SE']);
 
$response
    ->assertStatus(200)
    ->assertJson([
        'success' => 'Language has been created successfully',
    ])
    ->assertJsonPath('data.name', 'Swedish')
    ->assertJsonPath('data.code', 'swe')
    ->assertJsonPath('data.flag', 'SE');

Related Snippets

Composer Script echo

Laravel insert dynamic input values with radio button

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

image source not readable

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

The "client_reference_id" argument is not passed

How to reset Laravel AuthManager/guards in between API calls in tests?

Chunk and transpose a flat array into rows with a specific number of columns

Where do I need to place a hook for phpunit?

Explode not working properly with dash

Required field only if another field has a value, must be empty otherwise

Unable to get password for the instance created from AMI

Make survey at laravel 5.4 and MySQL

Artisan, creating tables in database

Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work

About Contact Privacy policy Terms and conditions