mardi 3 octobre 2017

Laravel: Testing Validation

I am trying to test a really simple validation in Laravel using phpunit but I am not able to get it working.

I have UserController.php as follow:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\User;


class UserController extends Controller
{

    public function store(Request $request)
    {   
        echo '#1: I'm in.';

        $request->validate([
            'email' => 'required'
         ]);

        echo '#2: The item validated';
    }

}

And a ExampleTest.php as follow:

<?php

use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function test()
    {

        $response = $this->call('POST', 'user', array('email' => 'test1@test.com'));

    }
}

It does echo the first echo #1, but I cannot seem to get it to echo the #2. What's wrong here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire