Closed RyanHavoc closed 11 years ago
Hi,
I have a model here:
<?php class PlanOption extends BaseModel { protected $guarded = array(); public static $rules = [ 'plan_id' => 'required|exists:plans,id', 'plan_price_id' => 'required|exists:plan_prices,id', 'item_limit' => 'required|integer' ]; }
Which when I use Factory::PlanOption to create a dummy object, run it through my validate method and split out to the browser like so (in routes.php):
use Way\Tests\Factory; Route::get('/', function(){ $planOption = Factory::PlanOption(['plan_id' => 44]); $planOption->validate(); var_dump($planOption); });
Give me what I'd expect, namely a couple of errors telling me that the plan_id and plan_option_id don't exist in the database:
/*...extract...*/ ["errors"]=> object(Illuminate\Support\MessageBag)#238 (2) { ["messages":protected]=> array(1) { ["plan_id"]=> array(1) { [0]=> string(32) "The selected plan id is invalid." } ["format":protected]=> string(8) ":message" }
However when I spit out the Factory::PlanOption within my test to ensure that validation is false if plan_id is invalid:
public function testIsInvalidWithoutAPlanId() { $planOption = Factory::PlanOption(['plan_id' => 44]); dd($planOption); $this->assertNotValid($planOption); }
I get:
["errors"]=>null
Same code, but different results? Does anyone have any idea why?
This was me being a tool. Move along, nothing to see here.
Hi,
I have a model here:
Which when I use Factory::PlanOption to create a dummy object, run it through my validate method and split out to the browser like so (in routes.php):
Give me what I'd expect, namely a couple of errors telling me that the plan_id and plan_option_id don't exist in the database:
However when I spit out the Factory::PlanOption within my test to ensure that validation is false if plan_id is invalid:
I get:
Same code, but different results? Does anyone have any idea why?