• 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

Add Metadata, headers (Expires, CacheControl) to a file uploaded to Amazon S3 using the Laravel 5.0 Storage facade

Handling expired token in Laravel

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

Laravel 5.2: Unable to locate factory with name [default]

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

Multiple order by in WooCommerce

Laravel unique validation on multiple columns

PHP and WebView - Cookie doesn't are the same

Add custom text under order details on WooCommerce My account view order pages

SMTP "Error: DATA not accepted from server!" Opencart 2.3 on InMotionHosting

Wordpress wpdb->delete issue

Printing more than one array using print_r or any other function in php

WooCommerce Additional Information - if empty, hide

Undefined Array Key error when uploading image on php

Json_Encode not returning html even i try to encode JSON_HEX_QUOT | JSON_HEX_TAG

About Contact Privacy policy Terms and conditions