laravel-ardent / ardent

Self-validating, secure and smart models for Laravel's Eloquent ORM
BSD 3-Clause "New" or "Revised" License
1.39k stars 211 forks source link

Unable to unit test: #152

Open bkuhl opened 10 years ago

bkuhl commented 10 years ago

Is Ardent testable? It seems like I'm not doing anything special here and it's throwing a fatal error

My model:

class Account extends \LaravelBook\Ardent\Ardent
{

    protected $fillable = ['name', 'description', 'number'];

    /** @var [] Form validation rules */
    public static $rules = [
        'name'  => 'required|between:1,45',
        'description' => 'between:1,128',
        'number' => 'between:1,30'
    ];

}

My test:

<?php

use Codeception\Util\Stub;

class AccountModelTest extends \Codeception\TestCase\Test
{
   /**
    * @var \CodeGuy
    */
    protected $codeGuy;

    protected function _before()
    {
        $this->account = new Account();
    }

    protected function _after()
    {
    }

    /**
     * Test form validation
     */
    public function testAccountValidation()
    {
        //check name validation
        $this->assertFalse($this->account->validate());

        $this->account->name = \Faker\Provider\Lorem::text(46);
        $this->assertFalse($this->account->validate());

        $this->account->name = \Faker\Provider\Lorem::text(32);
        $this->assertTrue($this->account->validate());

        //check description validation
        $this->account->description = \Faker\Provider\Lorem::text(129);
        $this->assertFalse($this->account->validate());

        $this->account->description = \Faker\Provider\Lorem::text(64);
        $this->assertTrue($this->account->validate());

        //check number validation
        $this->account->number = \Faker\Provider\Lorem::text(31);
        $this->assertFalse($this->account->validate());

        $this->account->number = \Faker\Provider\Lorem::text(24);
        $this->assertTrue($this->account->validate());
    }

}```

The error:

Unit Tests (1) ------------------------------------------------------------------------ Trying to test account validation (AccountModelTest::testAccountValidation) PHP Fatal error: Call to a member function make() on a non-object in /Users/.../vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 214```

rogue780 commented 10 years ago

I am also experiencing this issue.

bkuhl commented 10 years ago

I've stopped using Ardent and gone a different direction with our architecture.

rogue780 commented 10 years ago

Yeah, we've abandoned Ardent as well and implemented the features we wanted in our own model.