}); describe("->lastInsertId()", function () { it("gets the encoding last insert ID", function () { $schema = new Schema(['connection' => $this->adapter]); $schema->source('gallery'); $schema->column('id', ['type' => 'serial']); $schema->column('name', ['type' => 'string']); $schema->create(); $schema->insert(['name' => 'new gallery']); expect($schema->lastInsertId())->toBe("1"); $schema->drop(); }); it("gets the encoding last insert ID even with an empty record", function () { $schema = new Schema(['connection' => $this->adapter]); $schema->source('gallery'); $schema->column('id', ['type' => 'serial']); $schema->column('name', ['type' => 'string']); $schema->create(); $schema->insert([]); expect($schema->lastInsertId())->toBe("1"); $schema->drop(); }); }); describe("->query()", function () { it("throws an exception when an error occured", function () { $closure = function () { $this->adapter->query('SELECT'); }; expect($closure)->toThrow(); }); });
$this->fixtures->populate('tag', ['create']); $this->gallery = $this->fixtures->get('gallery')->model(); $this->galleryDetail = $this->fixtures->get('gallery_detail')->model(); $this->image = $this->fixtures->get('image')->model(); $this->image_tag = $this->fixtures->get('image_tag')->model(); $this->tag = $this->fixtures->get('tag')->model(); }); afterEach(function () { $this->fixtures->drop(); $this->fixtures->reset(); }); describe("->create()/->drop()", function () { it("creates/drop a table", function () { $this->fixtures->drop(); $schema = new Schema(['connection' => $this->connection, 'source' => 'test_table']); $schema->column('id', ['type' => 'serial']); $schema->create(); expect($this->connection->sources())->toBe(['test_table' => 'test_table']); $schema->drop(); expect($this->connection->sources())->toBe([]); }); it("throw an exception when source is not set", function () { $closure = function () { $schema = new Schema(['connection' => $this->connection]); $schema->create(); }; expect($closure)->toThrow(new DatabaseException("Missing table name for this schema.")); }); it("throw an exception when source is not set", function () { $closure = function () { $schema = new Schema(['connection' => $this->connection]);