Asked  7 Months ago    Answers:  5   Viewed   60 times

I have started the process of making use on Continuous Integration and I have decided on circleci.

Please let me know if I can supply any other information as I am lost at this point.

When circleci tries to run the phpunit command it returns the following error:

I have failed miserably at solving this issue.

vendor/bin/phpunit
 PHPUnit 3.7.37 by Sebastian Bergmann.

Configuration read from /home/ubuntu/simple/phpunit.xml

PHP Fatal error:  Class 'IlluminateViewEnvironment' not found in /home/ubuntu/simple/vendor/laravel/framework/src/Illuminate/View/ViewServiceProvider.php on line 124

 Fatal error: Class 'IlluminateViewEnvironment' not found in /home/ubuntu/simple/vendor/laravel/framework/src/Illuminate/View/ViewServiceProvider.php on line 124
vendor/bin/phpunit returned exit code 255

The composer.json file:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "laravel/framework": "4.1.29",
        "cartalyst/sentry": "2.1.*",
        "vespakoen/menu": "dev-master",
        "venturecraft/revisionable": "1.8.*",
        "dompdf/dompdf" : "0.6.*",
        "baum/baum": "~1.0",
        "thujohn/pdf": "dev-master",
        "yohang/finite": "1.1.x-dev",
        "pimple/pimple": "2.1.*@dev",
        "symfony/security": "2.4.x-dev",
        "maatwebsite/excel": "1.*",
        "codesleeve/asset-pipeline": "dev-master"
    },
    "repositories": [
    {
        "type": "composer",
        "url": "http://packages.cartalyst.com"
    }
    ],
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/lib"
        ],
        "psr-0": {
            "Authority": "app/",
            "Acme": "app/"
        }
    },
    "config": {
        "preferred-install": "dist",
        "frozennode/administrator": "dev-master"
    },
    "require-dev": {
        "barryvdh/laravel-debugbar": "1.*",
        "way/generators": "2.*",
        "codeception/codeception":"@stable",
        "zizaco/factory-muff": "dev-master",
        "zizaco/testcases-laravel": "dev-master",
        "mockery/mockery": "dev-master",
        "phpspec/phpspec": "~2.0",
        "behat/behat": "~2.5.1",
        "behat/mink": "~1.5.0",
        "behat/mink-extension": "~1.2.0",
        "behat/mink-goutte-driver": "~1.0.9",
        "behat/mink-selenium2-driver": "~1.1.1",
        "phpunit/phpunit": "3.7.37",
        "onigoetz/profiler":"dev-master",
        "benconstable/phpspec-laravel": "~1.0"
    },
    "minimum-stability": "beta"
}

The circle.yml file

machine:
  timezone:
    Africa/Johannesburg
  php:
    version: 5.4.21
  hosts:
    app.test: 127.0.0.1

test:
  override:
    - vendor/bin/phpunit

 Answers

82

Did you try to run composer before? Try to put this in your circleci.yml:

dependencies:
  override:
    - composer install --prefer-source --no-interaction --no-dev
Saturday, May 29, 2021
 
Wilk
answered 7 Months ago
63

The problem seems to be that Laravel 5.4 does not support the namespace for PHPUnit introduced with version 6.

If you compare the branches it is easy to see:

https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php#L8

vs.

https://github.com/laravel/framework/blob/master/src/Illuminate/Foundation/Testing/Constraints/HasInDatabase.php#L6-L8

I think the best solution is to either run the tests with PHPUnit 5.x or possibly update laravel/framework to use master. Since the master might contain breaking changes the first seems to be the safer approach for now.

Wednesday, March 31, 2021
 
jakubos
answered 9 Months ago
63

I found a solution but I don't think this is the right place to write it. I added a simple line of code on the ConnectorLaravel5 class.

public function __construct($module)
{
    $this->module = $module;
    $this->initialize();

    $components = parse_url($this->app['config']->get('app.url', 'http://localhost'));
    $host = isset($components['host']) ? $components['host'] : 'localhost';

    parent::__construct($this->app, ['HTTP_HOST' => $host]);

    // Parent constructor defaults to not following redirects
    $this->followRedirects(true);

    // Added to solve the problem of overriding the request method
    Request::enableHttpMethodParameterOverride();
}

This solves my problem.

Saturday, May 29, 2021
 
dkcwd
answered 7 Months ago
28

You are doing something wrong here. view::share() is used for sharing a piece of data across all views not controller.

namespace AppHttpControllers;

use AppHttpRequests;
use AppHttpControllersController;
use Sentry;
use IlluminateHttpRequest;
use View;

//If you wish to get these variables in your other controllers you do this:

class BaseController extends Controller {

    public $obavijesti="Other data";
    public $izbornici="Some data";

    public function __construct() {
       View::share ( 'izbornici', $this->izbornici );
       View::share ( 'obavjesti', $this->obavjesti );
    }  

}

class AdminController extends BaseController {

    //if you have a constructor in other controllers you need call constructor of parent controller (i.e. BaseController) like so:

    public function __construct(){
       parent::__construct();
    }

    public function Index(){
      echo $this->obavijesti;
    }

}

You can also use a composer to share variables to views

//1. Create a composer file at appComposersAdminComposer.php
//NB: create "appComposers" if does not exists

//2. Inside AdminComposer.php add this.


<?php namespace AppComposers;

class AdminComposer
{
    public function __construct()
    {

    }

    public function compose($view)
    {
        //Add your variables
        $view->with('izbornici',      'Other data')
            ->with('obavjesti',       'Some other data');
    }
}

//3. In you controller do this:

<?php namespace AppHttpControllers;
//NB: I removed your BaseController because I believe the issue is coming from //there

use AppHttpRequests;
use AppHttpControllersController;
use Sentry;
use IlluminateHttpRequest;
use View;

class AdminController extends Controller{


    public function __construct(){
        //Lets use AdminComposer to share variables to adminpage.blade.php view

        View::composers([
            'AppComposersAdminComposer'  => array('adminpage')
        ]);

    }

    public function Index(){
        return view('adminpage');
    }

}
Saturday, May 29, 2021
 
Gerardo
answered 7 Months ago
21

When the validation on the FormRequest fails, it checks to see if the request was ajax or if it accepts a json response. If so, it will return a json response with the 422 status code. If not, it will return a redirect to a specified url (previous, by default). So, in order to get the response on failure you're looking for (422), you need to make a json request or an ajax request.

JSON

To make a json request, you should use the json() method:

//post exam
$this->json('POST', 'modul/foo/exam', [
        'date' => '2016-01-01'
    ])
    ->assertResponseStatus(200);

//post exam again
$this->json('POST', 'modul/foo/exam', [
        'date' => 'some invalid date'
    ])
    ->assertResponseStatus(422);

There are also getJson(), postJson(), putJson(), patchJson(), and deleteJson() shortcut methods if you think that looks cleaner than passing the method as a parameter.

//post exam
$this->postJson('modul/foo/exam', [
        'date' => '2016-01-01'
    ])
    ->assertResponseStatus(200);

AJAX

To make an ajax request, you need to add in the ajax headers. For this, you can continue to use the post() method:

//post exam
$this->post('modul/foo/exam', [
        'date' => '2016-01-01'
    ], ['HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'])
    ->assertResponseStatus(200);

//post exam again
$this->post('modul/foo/exam', [
        'date' => 'some invalid date'
    ], ['HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'])
    ->assertResponseStatus(422);
Wednesday, August 11, 2021
 
Elxx
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share