2016-03-28 11:15:08 -07:00
|
|
|
<?php
|
|
|
|
require_once('src/ReadOnlyTrait.php');
|
2017-12-11 14:10:25 -08:00
|
|
|
|
|
|
|
use MichaelAChrisco\ReadOnly\ReadOnlyException;
|
|
|
|
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
|
2017-03-27 13:14:50 -07:00
|
|
|
|
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([]);
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('create', '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([]);
|
|
|
|
};
|
2017-12-11 14:10:25 -08:00
|
|
|
expect($closure)->toThrow(new ReadOnlyException('forceCreate', '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([]);
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('save', '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([]);
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('update', '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([]);
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('firstOrCreate', '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([]);
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('firstOrNew', '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();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('delete', '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);
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('destroy', '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();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('restore', '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();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('forceDelete', 'User'));
|
2017-03-27 13:14:50 -07:00
|
|
|
});
|
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();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('performDeleteOnModel', 'User'));
|
2017-03-27 13:14:50 -07:00
|
|
|
});
|
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();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('push', 'User'));
|
2017-03-27 13:14:50 -07:00
|
|
|
});
|
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([]);
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('finishSave', 'User'));
|
2017-03-27 13:14:50 -07:00
|
|
|
});
|
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(){
|
2018-03-20 10:32:09 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
2017-03-27 13:14:50 -07:00
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->touch();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('touch', 'User'));
|
2017-03-27 13:14:50 -07:00
|
|
|
});
|
2016-12-09 06:37:13 -08:00
|
|
|
});
|
2017-03-29 10:15:48 -07:00
|
|
|
describe("::truncate()", function(){
|
2018-03-20 10:32:09 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
2017-03-29 10:15:48 -07:00
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->truncate();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('truncate', 'User'));
|
2017-03-29 10:15:48 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe("::insert()", function(){
|
2018-03-20 10:32:09 -07:00
|
|
|
it("is expected to throw ReadOnlyException", function() {
|
2017-03-29 10:15:48 -07:00
|
|
|
expect(
|
|
|
|
function(){
|
|
|
|
$user = new User;
|
|
|
|
$user->insert();
|
2017-12-11 14:10:25 -08:00
|
|
|
})->toThrow(new ReadOnlyException('insert', 'User'));
|
2017-03-29 10:15:48 -07:00
|
|
|
});
|
|
|
|
});
|
2016-03-28 11:15:08 -07:00
|
|
|
});
|
2022-09-07 09:14:13 -07:00
|
|
|
|
|
|
|
class MockModel
|
|
|
|
{
|
|
|
|
public static function create(array $attributes = [])
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class UserReadOnlyNotActive extends MockModel
|
|
|
|
{
|
|
|
|
use ReadOnlyTrait;
|
|
|
|
|
|
|
|
protected static function isActive(): bool
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe("UserReadOnlyNotActive", function () {
|
|
|
|
describe("::create()", function () {
|
|
|
|
it("expects `create()` to be toBeTruthy", function() {
|
|
|
|
$user = new UserReadOnlyNotActive;
|
|
|
|
expect($user->create([]))->toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|