0

I have installed Pear and used Pear to install PHPUnit and Mockery. I have PHPUnit running successfully in elipse (the pear directory is configured as an include path in the project).

I would like to use Mockery but eclipse keeps giving me this error:

PHP Fatal error: Class 'deepend\Mockery' not found

I followed the advice here: http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit but am not sure how to load the library. Here's my code:

<?php
use \Mockery as m;

define('BASEPATH', (dirname(__FILE__) . '/../../../../sys'));

require_once (dirname(__FILE__) . '/../models/products_model_composed.php');

class ProductsModelTest extends PHPUnit_Framework_TestCase { 
    private $products;
    private $mock_ci_model;


public function setUp(){
    $this->products = new products_model_composed();
    $this->define_ci_mock();
    $this->products->__set('ci_model', $this->mock_ci_model);
}

private function define_ci_mock(){
    $ci = m::mock('CI_Model');
    $ci->shouldReceive('ee')->once()->andReturn($this);
}

See first line in function define_ci_mock. This is where Mockery is called but not found. Can you point me in the right direction? I've installed Mockery 0.8.0

dorothy Dorothy
  • 309
  • 2
  • 7

1 Answers1

0

Aha! Just when I had given up for the day I found the answer!

A bootstrap file needs to be run first with these parameters:

require_once 'Mockery/Loader.php';
require_once 'Hamcrest/Hamcrest.php';
$loader = new \Mockery\Loader;
$loader->register();

See https://github.com/padraic/mockery/blob/master/README.markdown

Mockery ships with an autoloader so you don't need to litter your tests with require_once() calls. To use it, ensure Mockery is on your include_path and add the following to your test suite's Bootstrap.php or TestHelper.php file:

dorothy Dorothy
  • 309
  • 2
  • 7