Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
phpunit homebrew
  • I installed phpunit via homebrew on mac, but now my "php oil test" command doesn't work...
    If i run phpunit from commandline phpunit works...?

    which phpunit >>> /usr/local/bin/phpunit


    Uncaught exception Oil\Exception: PHPUnit does not appear to be installed.
    --
    Please visit http://phpunit.de and install.

    Callstack: 
    #0 /oil(73): Oil\Command::init(Array)
    #1 {main}
    --

    this is the content of /usr/local/bin/phpunit:

    #!/usr/bin/env bash
    /usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/phpunit/4.2.0/libexec/phpunit-4.2.0.phar $*

  • This is what the code does. So you can create an 'oil.php' config file, and tweak that to make sure it loads what you want.

    $phpunit_command = \Config::get('oil.phpunit.binary_path', 'phpunit');

    // Check if we might be using the phar library
    $is_phar = false;
    foreach(explode(':', getenv('PATH')) as $path)
    {
        if (is_file($path.DS.$phpunit_command))
        {
            $handle = fopen($path.DS.$phpunit_command, 'r');
            $is_phar = fread($handle, 18) == '#!/usr/bin/env php';
            fclose($handle);
            if ($is_phar)
            {
                break;
            }
        }
    }

    // Suppressing this because if the file does not exist... well thats a bad thing and we can't really check
    // I know that supressing errors is bad, but if you're going to complain: shut up. - Phil
    $phpunit_autoload_path = \Config::get('oil.phpunit.autoload_path', 'PHPUnit/Autoload.php' );
    @include_once($phpunit_autoload_path);

    // Attempt to load PHUnit.  If it fails, we are done.
    if ( ! $is_phar and ! class_exists('PHPUnit_Framework_TestCase'))
    {
        throw new Exception('PHPUnit does not appear to be installed.'.PHP_EOL.PHP_EOL."\tPlease visit http://phpunit.de and install.");
    }

  • Yeah ok but when I add the path to oil.php config file it still doesnt work because it is looking for this line " $is_phar = fread($handle, 18) == '#!/usr/bin/env php';"

    And the homebrew phpunit link is different
  • that doesn't matter, that is just a check whether you use phpunit.phar or not.

    If you don't, it will try to load 'PHPUnit_Framework_TestCase' for which the path must be correct.

    what it calls (the binary, and in your case the script), is defined here:

    $phpunit_command = \Config::get('oil.phpunit.binary_path', 'phpunit');

    so you need to set the 'phpunit.binary_path' in the oil.php config file to

    '/usr/local/bin/phpunit'

    unless that is in your path.

    But given the fact you get the exception, you don't even get this far. Problem is that PHPUnit's autoload.php file can't be found, which loads the phpunit framework.  So if there is no 'PHPUnit/Autoload.php' in your environment search paths, you need to define the full path (as in FQFN) to it 'phpunit.autoload_path' in your oil config file.
  • I am not sure, if I just download and install phpunit via phpunit.de instructions, testing works...
  • HarroHarro
    Accepted Answer
    So homebrew installs in a non-standard installation, so you need to create the oil.php config file, and add the two paths, one a FQFN to the Autoload.php, one a FQFN to the binary (or in your case the script).
  • I'll just use the phar version... haha

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion