Beispiel #1
0
 describe("->exists()", function () {
     it("returns the exists value", function () {
         $model = $this->model;
         $entity = $model::create(['id' => 123], ['exists' => true]);
         expect($entity->exists())->toBe(true);
     });
 });
 describe("->id()", function () {
     it("returns the entity's primary key value", function () {
         $model = $this->model;
         $entity = $model::create(['id' => 123, 'title' => 'Hello', 'body' => 'World']);
         expect($entity->id())->toBe(123);
     });
     it("throws an exception if the schema has no primary key defined", function () {
         $schema = new Schema(['key' => null]);
         $schema->locked(false);
         $model = $this->model;
         $model::definition($schema);
         $closure = function () {
             $model = $this->model;
             $entity = $model::create(['id' => 123, 'title' => 'Hello', 'body' => 'World']);
             $entity->id();
         };
         expect($closure)->toThrow(new ChaosException("No primary key has been defined for `{$model}`'s schema."));
         $model::reset();
     });
     it("throws an exception when trying to update an entity with no ID data", function () {
         $closure = function () {
             $model = $this->model;
             $entity = $model::create([], ['exists' => true]);
             $entity->id();
Beispiel #2
0
     $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);
     });
 });
 describe("->source()", function () {
     it("gets/sets the source", function () {