2016-03-28 11:15:08 -07:00
|
|
|
<?php
|
|
|
|
require_once('src/ReadOnlyTrait.php');
|
2017-03-27 13:14:50 -07:00
|
|
|
use MichaelAChrisco\ReadOnly\ReadOnlyException,
|
|
|
|
MichaelAChrisco\ReadOnly\ReadOnlyTrait,
|
|
|
|
Illuminate\Database\Eloquent\Model;
|
|
|
|
// use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
2016-03-28 11:15:08 -07:00
|
|
|
class User extends Illuminate\Database\Eloquent\Model {
|
2017-03-27 13:14:50 -07:00
|
|
|
use ReadOnlyTrait;
|
2016-03-28 11:15:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
describe("User", function() {
|
2016-10-06 13:22:17 -07:00
|
|
|
describe("::create()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->create([]);
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-10-06 13:22:17 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::forceCreate()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
$closure = function(){
|
2016-10-06 13:22:17 -07:00
|
|
|
$user = new User;
|
2017-03-27 13:14:50 -07:00
|
|
|
$user->forceCreate([]);
|
|
|
|
};
|
|
|
|
expect($closure)->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-10-06 13:22:17 -07:00
|
|
|
});
|
|
|
|
});
|
2016-03-28 11:15:08 -07:00
|
|
|
describe("::save()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->save([]);
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
2016-12-09 06:37:13 -08:00
|
|
|
});
|
2016-03-28 11:15:08 -07:00
|
|
|
describe("::update()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->update([]);
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::firstOrCreate()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->firstOrCreate([]);
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::firstOrNew()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->firstOrNew([]);
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::delete()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->delete();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::destroy()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->destroy(1);
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::restore()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->restore();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::forceDelete()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->forceDelete();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
|
|
|
});
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
2016-12-09 06:37:13 -08:00
|
|
|
describe("::performDeleteOnModel()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->performDeleteOnModel();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
|
|
|
});
|
2016-12-09 06:37:13 -08:00
|
|
|
});
|
|
|
|
describe("::push()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->push();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
|
|
|
});
|
2016-12-09 06:37:13 -08:00
|
|
|
});
|
|
|
|
describe("::finishSave()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->finishSave([]);
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
|
|
|
});
|
2016-12-09 06:37:13 -08:00
|
|
|
});
|
|
|
|
describe("::performUpdate()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
2016-12-09 06:37:13 -08:00
|
|
|
$user = new User;
|
2016-12-09 07:19:04 -08:00
|
|
|
//TODO: Mock up
|
2017-03-27 13:14:50 -07:00
|
|
|
// $user = new User;
|
|
|
|
// $user->performUpdate(new Builder, []);
|
2016-12-09 06:37:13 -08:00
|
|
|
unset($user);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::touch()", function(){
|
2017-03-27 13:14:50 -07:00
|
|
|
it("is expected to throw Error", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->touch();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
|
|
|
});
|
2016-12-09 06:37:13 -08:00
|
|
|
});
|
2017-03-29 10:15:48 -07:00
|
|
|
describe("::truncate()", function(){
|
|
|
|
it("is expected to throw Error", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->truncate();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::insert()", function(){
|
|
|
|
it("is expected to throw Error", function() {
|
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->insert();
|
|
|
|
})->toThrow(new ReadOnlyException("Not allowed to persist changes in read-only model User"));
|
|
|
|
});
|
|
|
|
});
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
?>
|