jeudi 30 juin 2016

How to test my Request macro from within a Laravel 5 package I'm creating?

I'm currently building a Laravel package that injects a new method in Illuminate\Http\Request. The method I'm injecting has been completed and is expected to work nicely, but I also want to test it before releasing it.

My test requires me to change the request's Content-Type header, in order for me to see if the test is passing or no. So I have done the following to simulate the request:

use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
    /**
     * Holds the request
     * @var Illuminate\Http\Request
     */
    protected $request;

    /**
     * Setup the test
     */
    public function setUp()
    {
        parent::setUp();

        $this->request = new Request;

        $this->request->headers->set('Content-Type', 'application/x-yaml');
    }
}

Then in my test I use the method I'm injecting into Request with $this->request->myMethod() and it's always returning false since the Content-Type header is not getting set to application/x-yaml.

How do I go on simulating the headers in a test in Laravel package development?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire