Example #1
0
 public function testSetter()
 {
     $model = new Product();
     $model->name = 'example';
     $this->assertEquals('example', $model->name);
     $this->assertEquals('SIMPLE', $model->type);
     $model->type = '123';
     $this->assertEquals('123', $model->type);
     $category = new Category();
     $category->name = 'Toys';
     $category->save();
     $product = new Product();
     $product->name = 'Bear';
     $product->price = 100;
     $product->description = 'Funny white bear';
     $this->assertNull($product->category);
     $this->assertNull($product->category_id);
     $this->assertEquals(1, $category->pk);
     // Also working
     // $product->category = $category;
     $product->category_id = $category->pk;
     $this->assertEquals(['id', 'name'], $category->attributes());
     $this->assertEquals(['id', 'name', 'price', 'description', 'category_id'], $product->attributes());
     $this->assertEquals(1, $product->category_id);
     $this->assertEquals(1, $product->getAttribute('category_id'));
     $product->save();
     $this->assertInstanceOf('\\Tests\\Models\\Category', $product->category);
     $this->assertTrue(is_numeric($product->category_id));
 }