/** * @covers ::getProducts */ public function testProducts() { $store = new Store(); $items = $store->getProducts(); $this->assertInstanceOf('Harp\\Harp\\Repo\\LinkMany', $items); $this->assertEquals(Product::getRepo(), $items->getRel()->getRepo()); }
/** * @covers ::initialize */ public function testInitialize() { $product = Product::getRepo(); $store = $product->getRelOrError('store'); $this->assertEquals('CL\\Purchases\\Store', $store->getRepo()->getModelClass()); $items = $product->getRelOrError('productItems'); $this->assertEquals('CL\\Purchases\\ProductItem', $items->getRepo()->getModelClass()); $model = new Product(); $this->assertFalse($model->validate()); $errors = $model->getErrors()->humanize(); $expected = 'name must be present'; $this->assertEquals($expected, $errors); }
public static function initialize(Config $config) { parent::initialize($config); $config->addRels([new Rel\BelongsTo('product', $config, Product::getRepo(), ['key' => 'sourceId'])]); }
public static function initialize(Config $config) { SoftDeleteTrait::initialize($config); $config->addRels([new Rel\HasMany('products', $config, Product::getRepo(), ['inverseOf' => 'store']), new Rel\HasMany('storePurchases', $config, StorePurchase::getRepo(), ['inverseOf' => 'store'])])->addAsserts([new Assert\Present('name'), new Assert\LengthLessThan('name', 150)]); }