示例#1
0
     $this->schema->set('id', ['type' => 'serial']);
     $this->schema->set('gallery_id', ['type' => 'integer']);
     $this->schema->set('name', ['type' => 'string', 'default' => 'Enter The Name Here']);
     $this->schema->set('title', ['type' => 'string', 'default' => 'Enter The Title Here', 'length' => 50]);
     $this->schema->bind('gallery', ['relation' => 'belongsTo', 'to' => Gallery::class, 'keys' => ['gallery_id' => 'id']]);
     $this->schema->bind('images_tags', ['relation' => 'hasMany', 'to' => ImageTag::class, 'keys' => ['id' => 'image_id']]);
     $this->schema->bind('tags', ['relation' => 'hasManyThrough', 'to' => Tag::class, 'through' => 'images_tags', 'using' => 'tag']);
 });
 describe("->__construct()", function () {
     it("correctly sets config options", function () {
         $connection = Stub::create();
         $conventions = Stub::create();
         Stub::on($connection)->method('formatters')->andReturn([]);
         $schema = new Schema(['connection' => $connection, 'source' => 'image', 'model' => Image::class, 'primaryKey' => 'key', 'locked' => false, 'fields' => ['id' => 'serial', 'age' => 'integer'], 'meta' => ['some' => ['meta']], 'conventions' => $conventions]);
         expect($schema->connection())->toBe($connection);
         expect($schema->source())->toBe('image');
         expect($schema->model())->toBe(Image::class);
         expect($schema->primaryKey())->toBe('key');
         expect($schema->locked())->toBe(false);
         expect($schema->fields())->toBe(['id' => ['type' => 'serial', 'array' => false, 'null' => false], 'age' => ['type' => 'integer', 'array' => false, 'null' => true]]);
         expect($schema->meta())->toBe(['some' => ['meta']]);
         expect($schema->conventions())->toBe($conventions);
     });
 });
 describe("->connection()", function () {
     it("gets/sets the connection", function () {
         $connection = Stub::create();
         $schema = new Schema();
         expect($schema->connection($connection))->toBe($schema);
         expect($schema->connection())->toBe($connection);
     });