philipbrown / magniloquent

DEPRECATED, USE https://github.com/dwightwatson/validating
MIT License
70 stars 8 forks source link

Issue with Mockery #4

Closed thepsion5 closed 10 years ago

thepsion5 commented 10 years ago

I'm not 100% sure if this is an issue with Magniloquent itself or Mockery, but attempting to mock a class that extends Magniloquent results in a fatal error.

My composer.json's requirements:

"require": {
    "laravel/framework": "4.0.*",
     "magniloquent/magniloquent": "dev-master"
  },
 "require-dev": {
    "mockery/mockery": "0.8.*",
    "way/generators": "dev-master",
    "way/laravel-test-helpers": "dev-master",
    "phpunit/phpunit": "3.7.*"
},

My model:

use Magniloquent\Magniloquent\Magniloquent;

class TestModel extends Magniloquent {

    public static $rules = array(
        'create'    => array(),
        'update'    => array(),
        'save'      => array()
    );
}

And my test:

class ExampleTest extends TestCase {

    /**
     * A basic functional test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $crawler = $this->client->request('GET', '/');

        $this->assertTrue($this->client->getResponse()->isOk());
    }

    public function __construct()
    {
        $mock = Mockery::mock('TestModel');
    }

}

Running $ vendor/bin/phpunit results in the following:

Cannot redeclare Mockery_2112532308::offsetUnset() in /home/tnsosnet/elections/laravel/vendor/mockery/mockery/library/Mockery/Generator.php(129) : eval()'d code on line 1031
philipbrown commented 10 years ago

Thanks. I'll take a look at it tonight.

philipbrown commented 10 years ago

Hey, I made this repo as a test case (https://github.com/philipbrown/test_project)

Can you take a look to see if it looks set up correctly? I can't seem to replicate your error.

w3irdrobot commented 10 years ago

In your ExampleTest class, you need to make sure that Mockery is cleaning itself up before creating another instance of itself. Include the following method in your class. It should fix the error.

public function tearDown()
{
    Mockery::close();
}
philipbrown commented 10 years ago

Thanks @searsaw :)