1
votes

Can you please help me solve this issue on my local homestead/vagrant machine?

When I run the command: PHPUnit

I getting this result

PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

E
Time: 1.97 seconds, Memory: 6.00MB

                                                                                                               There was 1 error:                                                    

                                                                                                               1) ExampleTest::testBasicExample                                      

Cannot modify header information - headers already sent by (output started at /home/vagrant/Code/Project/vendor/php unit/phpunit/src/Util/Printer.php:134)

                                                                                                               /home/vagrant/Code/Project/bootstrap/app.php:4                         

/home/vagrant/Code/Poptin/tests/TestCase.php:20
/home/vagrant/Code/Project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:85 /home/vagrant/Code/Project/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:64

Please help! I've tried everything!!!

TestCase File

<?php

class TestCase extends Illuminate\Foundation\Testing\TestCase
{
    /**
     * The base URL to use while testing the application.
     *
     * @var string
     */
    //protected $baseUrl = 'http://localhost';
    protected $baseUrl = 'http://192.168.10.10';

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

        return $app;
    }
}

ExampleTest File:

<?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 testBasicExample()
    {

        $this->visit('/login')
            ->see('password');
    }
}
3
Please paste code from /home/vagrant/Code/Poptin/tests/TestCase.phpDaniel
paste code snippet from your testAkbar
@SomeDev Added!Dani Banai
have you checked the following out? stackoverflow.com/questions/8028957/…Akbar
Is there a reason you're changing $baseUrl? Remove this and run your tests in homestead.Jack

3 Answers

5
votes

I have found the answer. In one of my file, I added Header functions. So when I removed them. everything worked fine :)

3
votes

I've also had this issue.

I have solved this by just using preventive headers_sent function, so there was no need to delete the header() functions from my code:

if(!headers_sent()) {

    header("Access-Control-Allow-Origin: *");
    header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With, GoogleDataStudio');
    header('Access-Control-Allow-Credentials: true');
}

For a small bulk of tests you can also use this:alternative solution

In this answer there is a full explanation about this situation

0
votes
add stderr=true for phpunit.
<phpunit backupGlobals="false"
     backupStaticAttributes="false"
     bootstrap="vendor/autoload.php"
     colors="true"
     stderr="true"
     ...
 </phpunit>

or use annotations

/**
 * @runInSeparateProcess
 */

resolved for me. i hope will help you.